Rants and Raves

Welcome to Rants and Raves! I kept hearing that I needed to write, so here is the blog that I ended up starting. It is mostly an accounting of my progression through creating a web site, nuances with code, and tips about what I did to make things work. In there you will find sprinkled about some gems of life, and letting loose fun. Enjoy!

Laravel Migrations To Tweak Database
2022-12-16
In order to make a change to an existing database/table without loosing data takes a little bit of work. First is to make sure you have the doctrine/dbal package installed for Laravel via Composer. If you don't have Composer installed, get it here: https://getcomposer.org/download/ Just need to point it to the PHP version you want to use, which might already be in your environment path, or I think it can add it to your path. I did need to also update the php.ini file in my PHP directory by uncommenting the: extension=fileinfo line. Open a fresh command window, CD into your project, and use: composer require doctrine/dbal:* to have it added to the composer.json file and installed in your project. https://laravel.com/docs/9.x/migrations#modifying-columns With that in play you can now create a new migration using: php artisan make:migration migration_name --table=table and inside the up function of that migration Schema::table make your change, such as: $table->string('body', 15000)->change(); https://dev.to/mahmudulhsn/update-existing-table-with-migration-without-losing-in-data-in-laravel-fb1 After that you can run: PHP artisan migrate in Homestead to get the changes taken care of without losing data. When you do a deploy in Forge it will now be able to make the adjustments necessary. I chose 15000 since it was close the limit that the varchar in MySQL would allow, seems it varies on some factors though. https://dev.mysql.com/doc/refman/8.0/en/column-count-limit.html#row-size-limits
DO Database Backups
2022-12-15
I want to change the database limitation for the number of characters a post can have. Before we do that I need to make sure I can backup, and get access to that backup from Forge/DO. First SSH into the site: SSH forge@IP CD into your backup location Then run the MySQL backup: mysqldump -c -p database table > "file.sql" I do NOT recommend spaces, makes everything a pain. Run: scp -T forge@IP:"'path/file.sql'" dest/file.sql The -T and "''" are for if there are spaces in the path https://linux.die.net/man/1/scp https://stackoverflow.com/questions/19858176/how-do-i-escape-spaces-in-path-for-scp-copy-in-linux
Switches And Custom Controller Method
2022-12-14
In an effort to clean up and start getting ready for admin level troubleshooting info I tossed in a simple switch case around some code so that it only shows in Homestead. Don't forget the @break, that tells the switch that it's done and to end. If you leave those out then the code after that section will still run. @switch ( config('app.env') ) @case ("homestead") Content Homestead sees @break @default Content if there's no match @endswitch https://laravel.com/docs/8.x/blade#switch-statements Further "admin" level prep was to be able to view all of the created posts, even if the post date hasn't happened. In the blogs controller I added a new method to do this. The only difference from the index method was removing: where('post_at', '<=', Carbon::now())-> from the Eloquent search. Laravel doesn't default route to every method in a controller, just their defaulted ones, so we need a way to access it. The way to do this is to add a route specifically to the web.php: Route::get('/blog/viewAll', [BlogsController::class, 'viewAll']); This needs to be before the: Route::resource() otherwise it might stop looking through the routes at that point.
Azure Redirect
2022-12-13
With Bitbucket/Forge/DigitalOcean working I wanted to redirect the Azure traffic to the new site. What I ended up settling on was an if conditional on the app environment in the web.php: if (config('app.env')=="azure"){ Route::permanentRedirect('{whatever}', 'http://162.243.171.147/')->where('whatever', '.+'); } else { other routes } https://www.folkstalk.com/2022/09/use-app-name-in-laravel-blade-with-code-examples.html https://stackoverflow.com/questions/29222216/if-condition-in-laravel-routes-file https://joshanthony.info/2017/12/28/wildcards-in-laravel-routes/
Database Access
2022-12-12
Forge uses Laravel's migrations to build your database structure, so you will want to make sure those are up to snuff. I had to add the post date field to my blog migration, and the: ->nullable() option to the user column as well. Once your server is up and running you can SSH into it to run artisan commands or access the MySQL database. You will need to add the public SSH key for your local machine into the SSH Keys section in your Forge server. https://blog.laravel.com/forge-connect-to-your-server-using-ssh-or-sftp If you need to generate an SSH key: https://www.howtogeek.com/762863/how-to-generate-ssh-keys-in-windows-10-and-windows-11/#:~:text=To%20generate%20an%20SSH%20key,C%3AUsers%20folder%20by%20default. Once you SSH in you can access the DB by typing: mysql -p and entering your Forge/DigitalOcean DB password. This can be found in: Forge > your site > Environment > and find the DB_PASSWORD A Nice little table of MySQL command examples can be found here: http://g2pc1.bu.edu/~qzpeng/manual/MySQL%20Commands.htm I have tried to connect HeidiSQL to the Forge/DO database, but have been unsuccessful. I believe I have the SSH portion correct, however the MySQL login seems to be unhappy. I will have to try with TablePlus as recommended by Forge.
DigitalOcean And Forge
2022-12-11
DigitalOcean was pretty simple to open up, which did require a card on file since it is a paid for service. You will have to link DO to Forge, and it was outlined well enough that I do not have any extra pointers for that process. I believe the initial Forge setup was okay enough. They do require a card on file as this is a paid for service, although they did give me a small trial period. Connecting Forge to Bitbucket wasn't too bad I don't think. When you add a new site in Forge it'll inquire about where to install the application from, you'll select Git Repository. Bitbucket should be a button to select. Enter in the user/repository.git to your project, you can be sure to find them by taking the end info from the clone button in your repo in Bitbucket. Before you can select a branch you do need to copy the SSH key that Forge is providing into the Access Keys section of the Repository Settings in your Bitbucket project. It might take a moment for Bitbucket to propagate the change before Forge can access the project, there also might be other levels that entering this key in will work but at this point it worked for me. https://stackoverflow.com/questions/60527052/issue-when-using-laravel-forge-with-bitbucket https://laracasts.com/discuss/channels/forge/bitbucket-to-forge
GIT Repo - Bitbucket Prep
2022-12-10
I was definitely planning on getting to setting up a GIT repo and testing its abilities, but this definitely sped up that timeline. Bitbucket was pretty straight forward with their guidance. My biggest initial problem was figuring out how to push my existing project into Bitbucket. Found this little gem that helped though: https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-git-push-an-existing-project-to-Bitbucket When trying to push my project to Bitbucket I think I had some password issues. The issue was that it didn't want the password I used to log in to the site, it wanted one that I hadn't setup yet. This will help you setup your password for the repo access: https://www.theserverside.com/blog/Coffee-Talk-Java-News-Stories-and-Opinions/How-to-generate-a-Bitbucket-App-Password-example
Using The Default Forge Site
2022-12-09
One thing to note is that I did end up using the "default" site provided by forge. This is because it can be accessed via the server IP. If you want to utilize a site name/domain or multiple sites then you will have to purchase and setup the domain name. I haven't done this at this time. The default site is the only site name that is accessible by IP, and I don't think any other site can be accessed while it's in play.
Moving To Another Hosting Service
2022-12-08
Discovering that Azure was discontinuing support for PHP on Windows App Servers lead through a chain of events. App server running Linux meant no MySQL In App. External database needed, Flexible only option now. Flexible requires Vnet and DNS... $$$. On top of that Azure's automated system wouldn't make the resources. And getting their shit to work nicely together through Power Shell without an example seemed like it was going to be a bitch. Moved on to looking into self hosting a windows web server... that also came with a lot of issues on the configuration front with a Laravel project. Also at that point I would need to be reliant on someone else to actually house the machine and worry about remotely connecting to it. Sat on it for a few days. Did a little research on paid hosting for Laravel since I would have to pay for Azure at this point anyway, and ran across Forge... Laravel's solution for launching their projects on a hosting service. It's basically a manager that creates a VM on a hosting service, installs a web server, configures all the nuancey BS, and gets your project on there. It's a lot like their Homestead setup. Using Forge means using two other services as well, a hosting provider and a GIT repository. I chose DigitalOcean and Bitbucket this time. Unfortunately I kind of blasted through this process to prevent interruption of the site, so unfortunately the info in here is mostly going to be pointing out some of the issues I ran into and some sources that I used to resolve them. https://forge.laravel.com/ https://www.digitalocean.com/ https://bitbucket.org/
Azure PHP Depreciation
2022-12-07
Looks like Azure does not want to mess around with supporting PHP on Windows web app instances. Which means I need to work on transitioning to a Linux App. What a pain in the ass.
Id Title Body Post At