Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

shankarnewton's avatar

Use sail without PHP on the machine

My idea is to use sail (for docker) on Mac M2 (year 2023) which comes with PHP8.X. My old projects are in version 7.x while new client projects are in Laravel 9 (which used php 8.x). From reading the blogs around, the best recommendation is to use docker. So I started looking for Sail/Docker settings for Laravel 7 and finally found this -https://github.com/ajuCubettech/sail-7.x but the issue is to run composer require ajuchacko/sail-7.x --dev I need php7.x which my local has only php 8.x and so am back to square 1.

I assume the best option would be to write the docker configuration for this so all my dependencies are pulled and installed within the docker, but since writing docker config is tough for me at this moment (am just starting with docker, pretty fresh) I'm planning to go with the above link.

How do you guys handle the environment dependencies? I use the following services-

  1. Laravel
  2. MySQL
  3. phpmyadmin
0 likes
4 replies
lbecket's avatar

One option would be to install php 7 and switch between 7 and 8 as needed. There may be a more elegant approach, but this is certainly viable and pretty easy for accommodating local development in different Laravel versions. This is what I do and it's pretty seamless.

shankarnewton's avatar

@lbecket thanks for the suggestion. I just did brew install [email protected] and did composer install. Although on back of my mind I was still not happy about downgrading the global php and then handling others from the docker, this thing saved lot of time.

lbecket's avatar

@shankarnewton Yes, but keep in mind that you can just as easily switch back to version 8.X as needed. You can run sudo update-alternatives --config php to set the default version. You may also have to enable/disable versions with, say, sudo a2enmod php7.4 or sudo a2dismod php8.1. Also remember to restart the services after making changes: sudo service apache2 restart

But the point is that you can have multiple versions installed and switch between them, you don't need to rely on Docker. That said, I have made a move to Sail in the past year where I can, and I do prefer to let the Docker container handle everything.

martinbean's avatar

@shankarnewton I’ve just got a new M2 MacBook Pro and it doesn’t have any version of PHP installed.

You can get started by running Composer in a Docker container: https://laravel.com/docs/9.x/sail#installing-composer-dependencies-for-existing-projects

Just be sure to change the image name if you need to use a version of PHP other than 8.2 for the project.

Once you’ve installed your project’s dependencies, you can run sail up -d to boot up the Sail environment, and then run any PHP commands via the Docker container: https://laravel.com/docs/9.x/sail#executing-sail-commands

I’ve had my MacBook for just over a week or so now and have gotten by without installing PHP on the Mac itself so far.

Please or to participate in this conversation.