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
Categories
Laravel Samuel

Laravel Deployment Commands

This is just a helpful reminder list of commands to run when deploying code for a Laravel project:

composer update
npm install
php artisan cache:clear
php artisan route:clear
php artisan view:clear
php artisan config:clear

when running php artisan cache:clear if you see the error:

Failed to clear cache. Make sure you have the appropriate permissions.

The data directory most likely doesn’t exist under (storage/framework/cache/data),

This data directory doesn’t exist by default on a fresh/new installation.

Creating the data directory manually at (storage/framework/cache) should fix this issue.

Categories
Laravel Mac Samuel

Fixing NPM Install Error

Ran into this error today when running NPM install on a project:

No receipt for 'com.apple.pkg.CLTools_Executables' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLILeo' found at '/'.

No receipt for 'com.apple.pkg.DeveloperToolsCLI' found at '/'.

gyp: No Xcode or CLT version detected!
gyp ERR! configure error
gyp ERR! stack Error: `gyp` failed with exit code: 1

To Fix this we ran:

xcode-select --print-path
# in my case /Library/Developer/CommandLineTools

# next line deletes the path returned by the command above
sudo rm -rf $(xcode-select --print-path)

# install the tools(again) with
xcode-select --install

Source: https://stackoverflow.com/questions/60573595/npm-install-fails-on-node-gyp-rebuild-with-gyp-no-xcode-or-clt-version-detec 

Once you complete the commands above now run npm install again and live is good 🙂

Categories
Fixing Stuff Laravel Samuel

Setting Up an Old Laravel Project

Steps to setting up an old Laravel project:

First error screen:

Warning: require(/path/public/../vendor/autoload.php): failed to open stream: No such file or directory in /path/public/index.php on line 24

Fatal error: require(): Failed opening required '/path/public/../vendor/autoload.php' (include_path='.:/usr/local/Cellar/php@7.4/7.4.19/share/php@7.4/pear') in /path/public/index.php on line 24

Fix:

run: composer install

Second Error Screen:

Fix:

Download the .env file from the staging site and change it to work with the local DB

Third Error:

ErrorException (E_ERROR)
The Mix manifest does not exist. (View: /path/resources/views/layouts/app.blade.php)
(View: /path/resources/views/layouts/app.blade.php)

Fix:

To fix this we will want to run “npm install followed by npm run dev” however when we run “npm install” we get the error message incorrect or missing password. To fix this we must first do:

download the .npmrc file from staging

rm -rf node_modules
rm package-lock.json
rm yarn.lock
npm cache clear --force
npm install
composer install
npm run dev
now we can run
npm insall 
npm install --save-dev webpack
npm run dev
   type yes to install CLI for webpack