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

vincent15000's avatar

How to run php artisan serve with a specific php version ?

Hello,

I'd like to install PHP 8.x on my Ubuntu distribution but I want to continue using PHP 7.4 with some Laravel projects.

How is it possible to do that ? Is it for example possible to generate a virtual environment like with Python ? Or having PHP entirely inside the Laravel project instead of installed on the OS ?

Thanks for your help ;).

Vincent

0 likes
19 replies
vincent15000's avatar

@Sinnbeck I have to study the benefit for me to use Docker (no matter with Sail or Lando). I've read that Docker can be useful to do continuous integration. I have never done continuous integration, is it really interesting ?

Sinnbeck's avatar

@vincent15000 I mostly use it locally to have multiple completely different development environments. But github actions uses it as well, and using it in production is great as well (docker, not sail/lando)

1 like
vincent15000's avatar

@Sinnbeck If I have only PHP 7.4 installed on my OS and if I want to install Laravel 9.x, it's not possible. So I need to install first Laravel 8.x, then install Sail, and the upgrade Laravel to the 9.x version ?

Sure I've not understood how to use Docker yet.

Is it possible to prepare a complete development environment with Docker and then work in it to install a fresh Laravel app ? (I should not compare with ... but I'm comparing with a virtual machine like with VirtualBox)

vincent15000's avatar

@Sinnbeck yes ... effectively with composer it's possible ;) I generally use laravel new and with this command it's not possible.

webrobert's avatar

@vincent15000 I have been weary of containers. But I have to say I’m a convert. Over are the days of being weary of upgrading my system or php blah blah blah.

I just started with a fresh computer. No php. No MySQL. Just lando and docker and git.

At the moment I feel like The benefit of spinning up a container and being able to run any of my projects based on their individual requirements far out weighs the trade offs.

1 like
Sinnbeck's avatar

@vincent15000 the sail command uses laravel new. Mine uses composer directly. The end result is more or less the same (except mine requires lando)

1 like
vincent15000's avatar

@webrobert Sorry I don't understand --- spinning up a container => set a container ??? --- so you feel the benefit to set a container or not to set one ? Sorry problem of english for me ;) you feel the benefit of running any of your projects without any container ?

Sinnbeck's avatar

@vincent15000 ok a bit of quick information to better understand this.

Docker has images (like the installation for an OS like Ubuntu). Many of these are ready to just download and use, but you can also customize them

Then we have containers. These are the installed OS. Normally you save the container to disk so you an easily start it again.

But here is the awesome thing. Docker let's you download an image, and run it as a container, run a single command and then remove it again. That is what that command does. It downloads a tiny OS that only have php and composer installed. Nothing else. It the runs a single command, and deletes the container. But it maps its install directory to your local directory (volumes) so the files are added to your local system

And all of my projects except my blog is run using docker/lando locally

1 like
Sinnbeck's avatar

@vincent15000 oh and the images are tiny. Ubuntu is only 188 mb in total. Debian 125 mb. And alpine is 5 mb

1 like
Sinnbeck's avatar

Btw. If you just want to install laravel 9

SITENAME=my-app; docker run --rm --interactive --tty \
  --volume $PWD:/app \
  --user $(id -u):$(id -g) \
  composer create-project laravel/laravel $SITENAME ^9.0 \
  && cd $SITENAME
1 like
vincent15000's avatar

@Sinnbeck That's my choice because it's much easier to do. I use update-alternatives --config php and all works well ;). I'll perhaps have a look at Docker which seems very difficult for me.

vincent15000's avatar

Docker and Sail / Lando seem to be excellent.

I explore all other possibilities too and I've seen Homestead.

Sinnbeck's avatar

@vincent15000 personally I prefer docker as I have each service seperately. It made it possible for me to make a seperate container for php 8 in the same project and run all my tests while the primary php container still ran php 7.4

And adding new services like meili search is easy

Please or to participate in this conversation.