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

Categories
Fixing Stuff Mac Samuel

Getting Local ENV Setup To Run Old Site

First issue:

Library not loaded: /usr/local/opt/openldap/lib/libldap-2.5.0.dylib
  Referenced from: /usr/local/Cellar/php@7.3/7.3.33/bin/php

To fix this we ran:

Just do this:

brew tap shivammathur/php
brew link --overwrite --force php

done....
brew unlink php@8.1
brew link php@7.4 
brew services restart --all
composer global update
valet use php@7.4
    *this should confirm that valet is set to use php 7.4

***If we want to go farther back and use PHP7.3 or older, we have to do the following:

brew tap shivammathur/php
brew install shivammathur/php/php@7.3
brew unlink php@7.4
brew link php@7.3  
brew services restart --all
composer global update
valet use php@7.3  
     *this should confirm that valet is set to use php 7.3

***If you pull up a PHP info page in the browser and its still showing as using PHP 8.1, you can use this command to force the change***

valet use php@7.3 --force
Categories
Fixing Stuff Laravel Mac Samuel

Fixing Dev Environment After Monterey Update

Ok so had a very strange issue come up after upgrading my Macbook to macOS Monterey. To start with I was getting this error anytime I typed php -v on the command line:

zsh: command not found: php

Which obviously that is strange because php is 100% installed on my system. To Fix this we ran:

brew upgrade php

composer global update valet use php@8.1

Everything ran correctly and I now had php 8.1 installed. When I typed php -v it returned my version of php on the command line as it should, but then we ran into a new issue. I pulled up the site I had been working on before this Monterey debacle and got this error message:

Fatal error: Composer detected issues in your platform: Your Composer dependencies require a PHP version ">= 8.0.0". You are running 7.4.26. in /Users/sam/repos/local-eats-laravel/vendor/composer/platform_check.php on line 24

Ummmm…. what the fuck, over? I’ve got 8.1 installed, it returns from the command line… but my web browser is still stuck using this old outdated php 7.4 (that’s strange) up until this point Valet had always properly taken care of syncing both versions of php. So now we went on the hunt to fix this issue, turns out – easy fix. Just run:

rm ~/.config/valet/valet.sock
valet restart 

This removed a configuration file for Laravel Valet – that I guess was stuck using the old php 7.4 for some reason….. once valet restarted it picked up on the php 8.1 change and were good to go

Categories
Fixing Stuff Laravel Samuel

Fixing NPM Run Watch Error

Today we are getting this error on a Laravel site:

To fix this issue we are going to do the following:

  • delete the node_modules folder
  • delete package-lock.json file
  • run: npm install
  • open the .env file and make sure our environments line up with the script we are trying to run- IE make sure “npm watch” is set to work with the environment we are currently on. In this case “npm dev” was set to local and “npm watch” was set to staging.
  • Run: npm run dev locally to confirm it works.
  • Run: npm run watch on the staging site to confirm it works

Now we need to add a migration to get a portion of the site working with a new DB column, for this we will run:

  • php artisan make:migration create_payment_status_column
  • inside of the migration file we will add:
class CreatePaymentStatusColumn extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::table('companies', function (Blueprint $table) {
            $table->enum('payment_status',['trail', 'active', 'inactive'])->default('trail');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        $table->dropColumn('payment_status');
    }
}
Categories
Laravel Samuel

Deploying An Old Laravel Site

When deploying an old site today we ran npm install which triggers this issue:

npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it! 

npm WARN img-loader@3.0.1 requires a peer of imagemin@^5.0.0 || ^6.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN laravel-mix-transpile-node-modules@2.0.1 requires a peer of laravel-mix@^4.0.0||^5.0.0||^6.0.0 but none is installed. You must install peer dependencies yourself.

npm WARN v-calendar@2.3.0 requires a peer of @popperjs/core@^2.4.0 but none is installed. You must install peer dependencies yourself.

The staging server in this case had an older version of NPM installed than what our two developers were using in their local environments, so to fix this we got staging in sync with the NPM version that the developers were now using by running:

npm audit fix
npm install -g npm