DEV Community

Devtonight
Devtonight

Posted on • Updated on • Originally published at devtonight.com

How To Update Laravel Sail To PHP v8.1

PHP 8.1 support added to Laravel Sail starting from v1.12.0. Meanwhile, they have replaced the mysql:8.0 Docker image with mysql/mysql-server:8.0 image in this pull request. Keeping all these things in mind, let's update the Laravel Sail to the latest version to use PHP 8.1.

First of all, update the Laravel Sail Composer package.

composer update laravel/sail
Enter fullscreen mode Exit fullscreen mode

Update The docker-compose.yml File

Since Laravel Sail changed its MySQL Docker image, you can decide whether use it or continue with the mysql:8.0 image that you already have. If you decided not to continue with the updated image, follow Method 1 or otherwise, follow Method 2 as described below.

Method 1: PHP 8.1 Update Only

If you have valuable data in your development database and willing to continue using the mysql:8.0 Docker image without taking any risk or just want to use PHP 8.1, open the docker-compose.yml file and replace the 8.0 in the context: ./vendor/laravel/sail/runtimes/8.0 line to 8.1. Also, replace the 8.0 in the image: sail-8.0/app line to 8.1. So the final docker-compose.yml file should be similar to this.

version: '3'
services:
    laravel.test:
        build:
            context: ./vendor/laravel/sail/runtimes/8.1
            dockerfile: Dockerfile
            args:
                WWWGROUP: '${WWWGROUP}'
        image: sail-8.1/app
Enter fullscreen mode Exit fullscreen mode

Method 2: PHP 8.1 + mysql/mysql-server:8.0 Image Update

If you do not have any valuable data in the development database or they can be easily regenerated using backups or seeds, run the following command to re-create the entire docker-compose.yml file with the services. Following services are available to use at this moment.

  • mysql
  • pgsql
  • mariadb
  • redis
  • memcached
  • meilisearch
  • minio
  • mailhog
  • selenium

However, only mention the services that you need using the --with.

php artisan sail:install --with mysql,mailhog,redis
Enter fullscreen mode Exit fullscreen mode

Build The sail-8.1 Docker Image

Once you prepared the docker-compose.yml file, remove existing containers with the following command.

./vendor/bin/sail down
Enter fullscreen mode Exit fullscreen mode

Build the sail-8.1 image.

./vendor/bin/sail build --no-cache
Enter fullscreen mode Exit fullscreen mode

Start the application in detached mode.

./vendor/bin/sail up -d
Enter fullscreen mode Exit fullscreen mode

If you followed Method 2, you might not be able to start the MySQL container as it tries to use the old MySQL volume created with the mysql:8.0 image. Under that situation, remove the existing containers along with all the volumes.

./vendor/bin/sail down -v
Enter fullscreen mode Exit fullscreen mode

Now start the application as usual.

./vendor/bin/sail up -d
Enter fullscreen mode Exit fullscreen mode

Run the following commands to see whether the update is successful.

Print the PHP version.

./vendor/bin/sail php -v

PHP 8.1.0 (cli) (built: Nov 25 2021 20:22:22) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.1.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.1.0, Copyright (c), by Zend Technologies
    with Xdebug v3.1.1, Copyright (c) 2002-2021, by Derick Rethans
Enter fullscreen mode Exit fullscreen mode

Print the Composer version.

./vendor/bin/sail composer --version

Composer version 2.1.14 2021-11-30 10:51:43
Enter fullscreen mode Exit fullscreen mode

Print the NodeJS version.

./vendor/bin/sail node -v

v16.13.1
Enter fullscreen mode Exit fullscreen mode

Print the NPM version.

./vendor/bin/sail npm -v

8.1.4
Enter fullscreen mode Exit fullscreen mode

Feel free to visit devtonight.com for more related content.

Oldest comments (0)