Categories
Fixing Stuff Laravel Php Storm Samuel

Fixing Laravel Valet Error

Sooooo we needed to jump our local environment from PHP 7.4 to PHP 8.1 in order to work on a different project.

We started by running the command:

Valet use php@8.1

That provided the following error:

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.1.0". You are running 7.4.27. in /Users/sam/.composer/vendor/composer/platform_check.php on line 25

To fix this issue we ran:

brew link php

This command resulted in:

brew link php
Unlinking /usr/local/Cellar/php@7.4/7.4.27.reinstall... 25 symlinks removed.
Linking /usr/local/Cellar/php/8.1.2.reinstall... 24 symlinks created.

From there we could run “valet use php 8.2” and our new project was happy. This post was also super helpful, it provides solutions for a few other versions oh PHP so if anyone else out there is stuck you can try the link below:

https://dev.to/arielmejiadev/switch-to-older-php-versions-with-laravel-valet-33ph

Categories
Laravel Samuel

Setting up Forge & Envoyer

These are shorthand notes for setting up Forge & Envoyer

Forge:

The first thing we need to do is create the account on Forge. Since we are using Envoyer we need to update the root path, we should also select use Isolation and then type in our domain name. The screen should look like this

Just add our actual domain and then hit add

From there, its time to activate SSL. The domain must be pointed to forge for this to work, so make sure the A record of the domain name is pointing to the forge machine. Click “let’s Encrypt” then type click install.

Now its time to jump over to Envoyer to finish deploying the site:

Envoyer:

  • Hit the Add new project button.
  • Type Live – Site Name
  • Copy username and repo name
  • Copy branch name
  • Click Save project -> then click into the project
  • Click the Server tab, then click Add server
  • Type the Name
  • Copy public IP address from Forge & Enter
  • Connect with port 22
  • connect as the isolated username
  • Select the PHP version we used on Forge
  • Copy the project root path from Forge commands page
  • Leave Blank the check box for reload FPM after deployments
  • Save server, then copy SSH key from Envoyer and add to forge for the isolated user -> test connection
  • Click Manage Environment, copy the .ENV contents into screen and hit save

Setup Deployment Hooks for NPM Install & Run Prod, as well as Clear & Update Cache. The code in these files should look like:

cd {{release}}

npm ci
npm run prod


cd {{release}}

php artisan cache:clear
php artisan view:clear
php artisan config:clear

php artisan config:cache
php artisan route:cache
php artisan view:cache

Finally drag/drop the deployment hooks so that they run before the new release is activated, it will look like this

Categories
Laravel Samuel

Migrate Refresh & Seed With Envoyer

We have been test driving Envoyer and ran into a bit of a stumbling block this week. We have a staging site that we setup to auto deploy with Envoyer. As part of our auto deploy we wanted to run

php artisan migrate:fresh --force --seed

To start we added that code to the Envoyer deployment hook section but it kept spitting out this error when it executed

Could not open input file: artisan

So we realized ok we must be in the wrong location on the server when Envoyer executes this command. It took a little bit of trial and error but we got it working with this:

cd ~/home-directory/current

php artisan migrate:fresh --force --seed

**Replace home-directory above with your real path, so for us we got this by SSHing into the server, and then navigating to the public web directory. If you are using forge this will be super easy as it will be one folder typically named with the URL of your site

Categories
Fixing Stuff Laravel Samuel

Fixing Stuck Forge Deployment

We had a forge deployment get stuck today, took a little searching around but the fix actually ended up being super easy. From the forge dashboard select the self-help drop down -> reset deployment state:

Thats pretty much it, your deployment should stop, and you can look into what was causing the issue. In our case it ended up being incorrect DB credentials in our .env file

Categories
Fixing Stuff Laravel Samuel

Fixing Laravel Error

We had this error display today when trying to deploy a staging site:

Symfony\Component\Debug\Exception\FatalThrowableError  : Class 'Doctrine\DBAL\Driver\PDOMySql\Driver' not found

to fix this issue we connected to the machine via SSH and ran:

composer require doctrine/dbal --with-all-dependencies

This allowed it to install correctly but we were still getting the same error message, solution TBD…

Categories
Laravel Samuel

Setting Up Laravel Forge Staging & Live Machines With Auto Deploy

We are going to break this into three separate sections. Section #1 will be setting up a stand alone Database machine. Section #2 will be setting up a staging and live environment for Laravel sites. Section #3 will be setting up a staging and live environment for WordPress sites.

Section: 1

  • We will be installing a MySQL database server. The documentation on that can be found here: https://docs.digitalocean.com/products/databases/mysql/
  • When creating the database we are going to select the following options from the Forge Screen
    • Type: Database
    • Region: Default
    • Server Size: 4GB Ram, 2 CPU Core, 80 GB SSD
      • This option cost $24/month
    • VPC: we will add it to our company VPC network, all of the other machines will also be added to this network
    • Enable weekly backups: yes

Once the server has been spun up we will save all of the login information that gets emailed to us in our password manager, make a connection to the machine using TablePlus, then delete the email with the passwords.

Making A Connection to the machine using TablePlus:

  • The first thing we will do is go to the SSH screen in forge for the database machine and add our public SSH key. To copy our SSH key from the command line use:
pbcopy < ~/.ssh/id_rsa.pub
  • Once our SSH key has been added to the machine, we can open up TablePlus and create our connection. To do this we will copy the Database Connection URL from the database tab on forge -> open TablePlus and select “create new connection” then select “import from URL”. Note, there is a great video on setup and connecting here: https://www.youtube.com/watch?v=jY5FhyiEdig

Allowing App servers to connect to the DB:

This step can actually only be completed once the other app machines have been created in steps 2 and 3 below, but once you have those created you need to come back to this machine and click into the server -> click network -> then select the option to allow the app machines to connect to the stand alone DB machine.

Section #2:

Laravel staging and live environments. We will create a two separate servers for staging and live. Both of these servers will be “web servers” from the server type drop down menu. We will check the option at the bottom of the page to add servers SSH key to source control providers. Both servers will be added to our company VPC.

Staging: 2GB Ram, 2CPU Core, 60GB SSD – cost $18/month

Live: 4GB Ram, 2 CPU, 80GB SSD – cost 24/month

*Once Both of these Machines are created we need to:

  • Install all our needed versions of PHP
  • Add our SSH key and test our SFTP connections
  • Create a new site with isolated user
    • Note: you must add an ssh key for each isolated user
  • Connect our project repo.
    • Note: we will need to add the servers SSH key and deploy key to the repo.
  • Once the repo is connected we will need to edit the .env file to point to our database machine + set the app_name, app_env, app_debug & app_url
  • we then need to activate our SSL from the SSL tab select lets encrypt
    • Note: we must point the site to the server before obtaining the SSL