Blog

23 Dec
2016

Laravel Icon Logo

Update Laravel 5.2 to 5.3 and update PHP 7.1 on Mac OS X


I had to recently update my version of Laravel 5.2 to Laravel 5.3 along with my php version to 7.1. It was a little bit tricky due to some missing help documentation, but I managed to figure it out. So if you are having the same problems then this should help.

WARNING: Don't ignore this since it's important! Now before doing anything I noticed a memory issue when installing and after searching around - it turned out to be the pragmarx -> tracker in the vendors folder. If you have installed this I would suggest you temporarily disable it while doing the update by changing the following file config/tracker.php and make this change 'enabled' => false.

 Step 1:

Install PHP 7.1

This first part isn't really important since if you are running Laravel 5.2 then you should already be running the minimum version of PHP 5.6. But for me I decided to install PHP 7.1

So start by using terminal and enter the following.

curl -s https://php-osx.liip.ch/install.sh | bash -s 7.1

It will also ask for your password before installing.

This could take a while but once done enter the next line to restart apache. And again it will ask for your password.

sudo /usr/sbin/apachectl restart

This restart should be instantaneous, so enter the following line to see which version of php is being used.

php -v

It should output the following...

PHP 7.1.0 (cli) (built: Dec  2 2016 09:19:56) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.1.0-dev, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.1.0, Copyright (c) 1999-2016, by Zend Technologies

 Step 2:

Files to change for installation to work

Now lets open the composer.json which is in the root folder and make the following changes.

"laravel/framework": "5.2.*",

to

"laravel/framework": "5.3.*",

and more importantly (without this change it wouldn't update for me) since I had installed the Laravel Forms and HTML components

"laravelcollective/html": "5.2.*",

to

"laravelcollective/html": "5.3.*",

and

"symfony/css-selector": "2.8.*|3.0.*",
"symfony/dom-crawler": "2.8.*|3.0.*"

to

"symfony/css-selector": "2.8.*|3.1.*",
"symfony/dom-crawler": "2.8.*|3.1.*"

Next edit the following lines of code in the app/Providers/RouteServiceProvider.php file.

/**
 * Define your route model bindings, pattern filters, etc.
 *
 * @param  \Illuminate\Routing\Router  $router
 * @return void
 */

public function boot(Router $router)
{
    //

    parent::boot($router);
}

to

 /**
 * Define your route model bindings, pattern filters, etc.
 *
 * @return void
 */

public function boot()
{
    //

    parent::boot();
}

Next edit the following lines of code in the app/Providers/EventServiceProvider.php file.

/**
 * Register any other events for your application.
 *
 * @param  \Illuminate\Contracts\Events\Dispatcher  $events
 * @return void
 */

public function boot(DispatcherContract $events)
{
    parent::boot($events);

    //
}

to

 /**
 * Register any events for your application.
 *
 * @return void
 */

public function boot()
{
    parent::boot();

    //
}

So what's the reason for editing to the 2 files in the Providers folder?

The answer being that if you were to run the update without doing this - the terminal will show the following error messages at the end of the installation.

> Illuminate\Foundation\ComposerScripts::postUpdate
> php artisan optimize

[ErrorException]        
Declaration of App\Providers\EventServiceProvider::boot(Illuminate\Contracts\Events\Dispatcher $events) should be compatible with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot()

Script php artisan optimize handling the post-update-cmd event returned with error code 1

 Step 4:

Update Laravel 5.2 to Laravel 5.3

Now we are going to do the update. So in the terminal use cd and enter the directory for this example something in MAMP folder.

cd /Applications/MAMP/htdocs/our-laravel-app

Then input this to start the Laravel 5.3 update.

php /Applications/MAMP/htdocs/composer.phar update

You should see the list of updates in the terminal.

laravel 5.2 to laravel 5.3 terminal

So now lets check it has worked and in the terminal input

php artisan --version

It should now output

Laravel Framework version 5.3.28

So in theory everything should work fine? Read on...

 Step 4:

/Applications/MAMP/htdocs/our-laravel-app/routes/web.php... (Fix)

After installing I tried the following code in the terminal to add the login author default controllers etc.

php artisan make:auth

But I would keep getting the following errors, or similar.

[ErrorException]

file_put_contents(/Applications/MAMP/htdocs/our-laravel-app/routes/web.php): failed to open stream: No such file or directory 

Well it turns out there is a change in Laravel 5.3 with regard to the app/Http/routes.php file. It now uses a different folder and file structure. They are now in the same directory that contains the app folder for example routes/web.php

So the only workaround was to install a separate version of Laravel 5.3 using something like the following.

php composer.phar create-project laravel/laravel temp-laravel "5.3.*" --prefer-dist

Now copy the following into your updated version of Laravel 5.3.

routes/api.php
routes/console.php
routes/web.php

So now when inputting 'php artisan make:auth' it will work fine.

php artisan make:auth
Authentication scaffolding generated successfully.

I hope this has helped you with the update process from Laravel 5.2 to Laravel 5.3 and PHP 7.1.

Posted in: < Laravel >
me@grafxflow avatar

me@grafxflow


I am a Full-stack Developer who also started delving into the world of UX/UI Design a few years back. I blog and tweet to hopefully share a little bit of knowledge that can help others around the web. Thanks for stopping by!

Related Posts

4 Thoughts

  1. 23 Apr
    2017

    avatar

    Farghana Hussain

    I keep getting this error:
    laravel/framework v5.3.0 requires paragonie/random_compat ~1.4|~2.0 -> no matching package found.

    Can you help please?
  2. 23 Apr
    2017

    avatar

    me@grafxflow

    Unsure what could be causing it.

    Try:

    php composer.phar require paragonie/random_compat

    Or maybe try changing your php version if possible.

    Also do you have any more information - is this a standalone install or an update.
  3. 25 Apr
    2017

    avatar

    Farghana Hussain

    I was trying to upgrade 5.2 to 5.3. However, I have installed a fresh version of Laravel 5.3 and all seems fine. I think there was some cache issue and I had to manually delete the cache files.

    Anyways, thanks a lot for your response.
  4. 25 Apr
    2017

    avatar

    me@grafxflow

    Glad to hear you got it working.

    Just need to try 5.4 now :)

Add comment

Add comment