Categories
Mac Samuel

Running List Of Shortcuts In Mac Big Sur 11.2.3

Change Host File:

  • Open up terminal and type: sudo nano /etc/hosts
  • Make the needed change in the file to change the host of a website. This is simply writing the IP address of the server, space, the domain name. So in effect it looks like 000.000.00 domain.com
  • Hit control x to close the file. Press Y plus ENTER to save the changes
  • Type: sudo killall -HUP mDNSResponder followed by Return to flush the DNS cache.
  • navigate to the website you want to see

Change Version of PHP in Use With Laravel Valet:

  • Open terminal and navigate to the project you are working on
  • Type: Valet use php@7.2 (or whatever version of PHP you want to activate)

Serving Local Websites From Nested Folder with Laravel Valet:

  • Open iTerminal and navigate to the subfolder where the site lives
  • run valet link folder-name. This will create a symlink to this site so that you can then open up the web browser and type foler-name.test and the site will serve

Opening files in the finder window:

  • option + space to open the alfred search finder
  • ~ + file name, so for example ~ repos gets me to code repo folder
  • once the folder that you want is visible hit command + enter to open it up in the finder winder

Open MySQL from command line & create a new database:

  • from the terminal window type: mysql (this will login to mysql)
  • then type: create database db-name; (replace db-name with the real name of the database you want to create and then press return to create the DB)
  • Once the database has been created open up sequel pro and input the DB name + root and click connect
  • If you need to import a database from staging or live down to local you can do that by clicking file -> import

Ignore a file in any repo – especially useful it the file has been added to gitignore and it is still tracking changes

git update-index --assume-unchanged -- wp-config.php

or you can run:

git update-index --skip-worktree -- wp-config.php

or for a directory you can run:

git update-index --assume-unchanged -- wp-content/plugins/
git update-index --skip-worktree -- wp-content/plugins/

*If you have a really stubborn file you can use:
git update-index --force-remove wp-config.php

Open up Alias file (or any file) with sublim text from the command line:

  • This is pulled from this video: https://laracasts.com/series/setup-a-mac-dev-machine-from-scratch/episodes/7
  • Once you follow the steps in that video you can then run the following command to open the alias file in sublime: subl . ~/.aliases
  • This command can be used to open any file as well just replyce the ~/.aliases with “filename”
  • ***If ever having trouble opening files up with subl . then just open up transmit and the .aliases file will be right there in the local root and just right click and open it up with sublime***

Open up Alias file with Vim

  • vim ~/.aliases
  • press shift i to start inserting new lines
  • when done and ready to save press esc then shift :
  • to quit without saving type q then hit enter
  • to quit and save press wq and then hit enter

Take a screenshot and copy to the clipboard

control + command + shift + 4

Categories
Laravel Samuel

Upgrading Laravel From 5.6 -> 5.7 -> 5.8 -> 6.0

This post is going to go through upgrading a site currently running Laravel 5.6. We will be taking the site up from 5.6 to 5.7 with the goal of eventually going all the way to 6.0 (the latest LTS at the time of this writing).

Start by creating a new upgrade branch from the dev branch:

git checkout -b feature/upgrading-laravel dev

*please note we are pulling from the dev branch here because the dev branch is currently more up to date than the master branch. We are writing these Laravel upgrades during a single day upgrade process, taking a Laravel site from 5.5 all the way up to 6.0. So if you are following along this series updating your own site make sure to branch off of whatever your current branch is (which will most likely be master)

The next thing we are going to do is open up sourcetree and push our newly created feature branch up to the remote repo server. To do this we will hit the push button and then check the box for the new branch and hit push.

Now that we have our new feature branch to the remote repo, were going to login to Laravel shift and purchase the shift we need, in this case we will be purchasing a shift from 5.6 -> 5.7. When we purchase the shift we will input our new feature branch as the branch shift should use to update from. In the Shift Screen there will be 2 boxes and we will need to fill them in this:

username/repo-name branch-name

With our shift purchased and executed, its time to merge the new branch shift creates into our updating branch and check how the site is doing locally:

Git fetch origin
Git checkout shift-42238
Git checkout feature/upgrading-laravel
Git merge shift-42238

Before we view the site locally we will also want to run:

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

Issues with cache:clear:
*If the artisan cache:clear line fails due to permissions issue, then do the following to fix that error:

Check to see if the data folder is present at: 
storage/framework/cache/data

Create the data directory manually if its not there: (storage/framework/cache/data)

run php artisan route:clear again and it should work :)

--update --
If creating the data folder still does not fix the issue, then try running:

php artisan config:cache 

If there are any bugs we will fix those, in this case we did not have any issues so we will go ahead and merge our branch into the dev branch and test it on the staging server.

git checkout dev
git merge --no-ff feature/upgrading-laravel -m "merge laravel 5.7 into dev"

*we can either then git push dev from the command line, or we can use sourcetree to push the dev branch up to the remote server, and deploy to the staging site from there.

Once logged into our staging server we will run our deployment script, and then navigate to the project root folder and run the following commands:

composer update
php artisan cache:clear
php artisan route:clear
php artisan view:clear

*one special note, if the server has any issue running composer update, we can always delete the vendor directory and then run composer install which will install a fresh version of all dependencies. The fastest way to delete the vendor folder is via command line with:

rm -rf vendor

Fixing Issues:

#1: A Note From Shift: Laravel 5.8 changed several of the core contracts with new implementations and methods. You should review the Upgrade Guide for more detail on these respective changes:

Shift found references to these contracts within:

  • app/Excel/Exports/InquiryExport.php

Error Message On Staging Server Command Line:

In CustomFormBuilderServiceProvider.php line 9:

Interface 'Illuminate\Contracts\Support\DeferrableProvider' not found

In CustomFormBuilderServiceProvider.php line 9:

Interface 'Illuminate\Contracts\Support\DeferrableProvider' not found

To fix this issue we just updated the packages in composer.json to work with the latest version of Laravel. This was tricky as composer was not able to resolve the packages into an installable set, so what we did is removed all of the packages and then added them back into the file in small chunks and ran composer each time, until we arrived at the full set of needed packages.

Error #2:

The file TrustProxies.php was causing an error message to display in the command line, to fix this we changed the code in this file to:

protected $headers = Request::HEADER_X_FORWARDED_ALL;

Error #3:

Now we were at the point where we could actually pull the website up, but we received the following error screen on any page of the site:

To Fix this issue we went to the file referenced in the error message (configure_vehicle.blade.php) and we updated the code to:

OLD: 
-    var base_url = "{{ route('configurator.configure_vehicle', ['manufacturer' => $manufacturer->slug, 'vehicle' => $vehicle->slug]) }}";

New:   var base_url = "{{ route('configurator.configure_vehicle', ['manufacturer_slug' => $manufacturer->slug, 'vehicle_slug' => $vehicle->slug]) }}";

The latest version of Laravel needs these values to be explicitly defined.

Error #4

Once we try to login to the site we are getting the error:

To fix this we will update our call in AuthAdminiter.php to be:

$this->authenticate($request, $guards);

Error #5

Once we got the login permission issue fixed, we were then presented with this error screen:

If we look at the error we can pull out a few clues:

Missing required parameters for [Route: packages.create_for_vehicle] 
[URI: manage/packages/create/vehicle={vehicle_id}]. 
(View:C:\wamp64\www\SFPS\resources\views\vehicles\partials\table.blade.php)

The route mentioned in the error wants you to pass vehicle_id, but the code as-is is only passing in id so Laravel can’t figure that out. To fix this we can either rename it, or remove the special key. ([$vehicle->id]  or [‘vehicle_id’=>$vehicle->id]). So in our case we made the following update to fix the bug:

Old: 
<td>{{ Helper::number(count($vehicle->packages)) }} {!! link_to_route('packages.create_for_vehicle', 'Add', ['id' => $vehicle->id], ['class' => 'btn btn-primary']) !!}</td>

New:         
<td>{{ Helper::number(count($vehicle->packages)) }} {!! link_to_route('packages.create_for_vehicle', 'Add', ['vehicle_id' => $vehicle->id], ['class' => 'btn btn-primary']) !!}</td>

Error #6

It looks like Laravel dropped support for SparkPost around 5.8 – so we are now getting these errors on all of our form submissions:

To fix this we need to install this package:
https://github.com/vemcogroup/laravel-sparkpost-driver

This package was giving us some issues when installing, in order to successfully install it we had to remove the 4.0 version that installed automatically with the package and instead install version 2.0 using the code below::

composer remove vemcogroup/laravel-sparkpost-driver


composer_memory_limit=-1 composer require vemcogroup/laravel-sparkpost-driver:^2.0

When we did this we ran into an issue that Guzzle 7.0 was not compatible with V2.0 of the SparkPost Package and could not install correctly as well, so to fix that we ran:

composer_memory_limit=-1 composer require guzzlehttp/guzzle:6.5.5

Once that package is installed its important to note that we also need to then run:

php artisan config:clear
php artisan cache:clear

The above gets the site working on our local machine, however when we deploy to the staging site we are still running into a different error screen which we will fix under Error #8 below, but first a general note.

General Error – Error #7

If you are getting the php memory limit error when running composer install or update, which looks like this:

To work around this issue run the code below, which tells PHP to keep trying instead of stopping after reaching the initial memory limit set on the server

composer_memory_limit=-1 composer install

Error #8:

On the staging server we are getting the error that allow_url_fopen must be enabled in php.ini. We login to cpanel and set this to enabled, but we still receive this message. So we will manually run the command below instead, which allows url_fopen for this 1 single command:

which composer

//for us this spits out /opt/cpanel/composer/bin/composer so we will then run

php -d allow_url_fopen=on /opt/cpanel/composer/bin/composer install

Error 9:

With the SparkPost API now working, we are getting the error below:

Client error: `POST https://api.sparkpost.com/api/v1/transmissions` resulted in a `400 Bad Request` response:
{\"errors\":[{\"message\":\"Unconfigured Sending Domain <example.com>

To fix this error we will open up config/mail.php and change the backup email address from hello@example.com to the actual address we want to use:

'address' => env('MAIL_FROM_ADDRESS', 'ActualEmailAddress'),
Categories
Laravel Samuel

Upgrading Laravel from 5.5 -> 5.6

Notes on Upgrading Laravel from 5.5 -> 5.6

Start by creating a new upgrade branch from the master branch:

git checkout โ€“b laravel-5.5-upgrade โ€“master

Next Purchase a Laravel shift using this new upgrade branch name

Merge the branch that is created by Laravel shift into this new upgrade branch

Git fetch origin
Git checkout shift-42238
Git checkout laravel-5.5-upgrade
Git merge shift-42238

Now its time to check how the site is doing on our local machine, but first we will want to update composer & clear config, route & view caches:

composer update
php artisan cache:clear
php artisan route: clear
php artisan view:clear

Now it’s time to fix any errors that cop up, our first error is:

array_keys() expects parameter 1 to be array, integer given

Solution: in app -> Http -> Middleware -> TrustProxies.php set the following:

protected $headers = [
    Request::HEADER_FORWARDED => 'FORWARDED',
    Request::HEADER_X_FORWARDED_FOR => 'X_FORWARDED_FOR',
    Request::HEADER_X_FORWARDED_HOST => 'X_FORWARDED_HOST',
    Request::HEADER_X_FORWARDED_PORT => 'X_FORWARDED_PORT',
    Request::HEADER_X_FORWARDED_PROTO => 'X_FORWARDED_PROTO',
];

our second error is: Class user not found. To fix this we update config -> auth.php to the following:

'model' => App\Models\User::class,
Categories
Laravel Samuel Uncategorized

Setting Composer To Use PHP 7.3 From Command Line

So we ran into a little bit of an issue today when upgrading Laravel from 5.6 -> 6.0. We updated the version of PHP using the MultiPHP Manager section in Cpanel, however when we then SSH’d into the server to pull in the updated Laravel code and run composer install we ran into the issue of composer using the system version of PHP. The full process we went through is below:

Update the version of PHP on MultiPHP manager page:

We then SSH’d into the server to pull in the new Laravel code. When we did this, we got the following error message:
To get around this issue we created a shim script, so now instead of running:
composer install

We instead ran:

~/bin/composer install

Composer now uses the version of PHP defined in the shim script, which in our case is PHP 7.3 and we are back to all green happy lines ๐Ÿ™‚

Categories
Fixing Stuff Laravel Samuel

Laravel Comapact PHP 7.3 Temporary Fix

With PHP 7.3 being automatically pushed out to a lot of servers recently we noticed a bug that came up on severeal older Laravel sites. The bug is:

compact(): Undefined variable: operator 

public function addWhereExistsQuery(self $query, $boolean = 'and', $not = false)
    {
        $type = $not ? 'NotExists' : 'Exists';
 
        $this->wheres[] = compact('type', 'operator', 'query', 'boolean');
 
        $this->addBinding($query->getBindings(), 'where');
 
        return $this;
    }

A Fix for this bug can be found on this stack overflow article: https://stackoverflow.com/questions/56726263/compact-undefined-variable-operator

The specific fix is:

$this->wheres[] = compact('type', 'operator', 'query', 'boolean');

you just remove the 'operator' parameter

Please note this is just a temporary fix to remove the error page. The long term fix for this is that the version of Laravel will need to be updated, and then composer update needs to be run to pull in the latest packages that will work with the new version of Laravel, and they will handle the new behavior of the compact method. The old version allowed for empty variables to be passed to the compact method, but in PHP 7.3 if an empty variable is passed to the compact method it presents you with that nice error message ๐Ÿ™‚

Categories
Fixing Stuff Laravel Samuel

Fixing Laravel Localhost Email Issue

While updating a clients site today we ran into an error message when trying to do a test on a submission for a new contact form that was created, the error message read:

cURL error 60: SSL certificate problem: unable to get local issuer certificate (see http://curl.haxx.se/libcurl/c/libcurl-errors.html

To Fix This Issue we Completed the Following Steps:

I am using PHP 7.1.9 for my WampServer, so change 7.1.9 in the example below to the version number you are currently using.

;curl.cainfo

  • Change it to:

curl.cainfo = "C:\wamp64\bin\php\php7.1.9\cacert.pem"

  • Make sure you remove the semicolon at the beginning of the line.
  • Save changes to php.ini, restart WampServer, and you’re good to go!

That fixes our issue with the curl error if we are using localhost to server our site, but if we are using php artisan server to dispaly the webpage then we also need to complete the steps below:

If your laravel project is located in c:\wamp\laravel\ then you should be able to call http://localhost/laravel/public and see the default laravel welcome page or your own.

  1. Open your /app/config/app.php file and check that the value of url directs to your project. 'url'=>'http://localhost/laravel/
  2. Then open your .htaccess file and add the RewriteBase rule under the RewriteEngine On Line RewriteBase /laravel/public/

Credit for these answers goes to: