r/PHPhelp • • Oct 05 '22

PHP version manager?

Hey all,

Wondered if anyone can recommend some kind of php version manager - I've been using phpbrew but to be honest I've found it pretty fragile and it hasn't been working that well for me.

Are there any useful tools or scripts to help install and change php versions?

Thanks!

14 Upvotes

19 comments sorted by

13

u/CyberJack77 Oct 05 '22

Just just docker. You can easily switch PHP versions, but also manage other project requirements (and versions).

5

u/AVeryLazyProgrammer Oct 05 '22

I agree. The drawback is that Docker has a steep learning curve.

3

u/CyberJack77 Oct 05 '22

Docker itself isn't hard, it just needs to be installed.

Managing a project can be more difficult, because you need to start everything manually, or use docker compose. In both cases you need to figure out which images you want to use and maybe create some configuration. When using docker compose you can start the entire project with one command, but it needs its own configuration file (which can be committed of course), so yeah, I agree that it has a learning curve.

Luckily there are some tools that can help you setup a per project development environment using docker. Tools like ddev, lando or docksal will get your projects running in no time.

2

u/bomphcheese Oct 06 '22

Adding devilbox to that list. Low learning curve and free.

2

u/CyberJack77 Oct 07 '22

Thanks for the addition.

I looked at devilbox, and first of all, it's very surprising to see a site not using SSL in 2022 (especially since browsers are starting to implement HTTPS-only).

Devilbox works a bit different than the other tools I mentioned. It basically spins up a bunch of containers that ALL of your projects will use. That means you cannot specify a PHP version per project, and ALL your projects use the same version. Of course, you can change the PHP version, but this still means ALL your project will use this version.

The other tools I mentioned will spin up separate containers per project. So 1 project can use PHP 8.2 while an older project can still use PHP 7.4 and they can run simultaneously.

The same goes for database, redis, and other services. In Devilbox you cannot have one project that uses MySQL 8 and another using MySQL 5.7 at the same time.

So personally I wouldn't recommend it, but if it fits your needs then please keep using it. I wasn't familiar with it yet, but I will stick to one of the other tools.

2

u/bomphcheese Oct 07 '22

Thanks for the helpful comparison. I guess since I manage my servers to all be the exact same settings, I hadn't really considered the need to have separate settings per project. But that flexibility is a great selling point.

I'll definitely try out the services you named. Which is your favorite? I'll start there.

3

u/CyberJack77 Oct 07 '22

At work, we use Docksal because that was the only one that supported NFS out of the box. Docker had a lot of issues with the filesystem on MacOS, and using NFS gave us a serious performance boost. Now we have M1 MacBooks and the problem isn't noticeable anymore, but because we commit project configuration, we still use Dockal.

All of the tools I mentioned have support for custom commands (or add-ons). Since we use different database systems, I wrote an addon to use DBeaver with my projects.

Nowadays tools like mutagen can really speed things up, and ddev is the only one supporting this out-of-the-box.

All 3 tools have been written in different languages, so this is something to think about when you want to create commands or add-ons yourself.

  • Docksal: Bash

  • Lando: Node

  • DDev: Go

For me, the fact that ddev is written in go is a big plus because you have a single binary that handles everything. No need for Node or any other application that needs to be installed on your system.

In the end, I think all 3 are fine to use. Just try them and let us know which you like best... and why 😃

2

u/bomphcheese Oct 07 '22

Damn you really took the time to thoroughly answer that question. I appreciate it. Sounds like I’ll give DDev a go first.

1

u/CyberJack77 Oct 07 '22

Let me know what you think. 👍

Just to be clear, we have like 100+ projects for all kinds of customers, and each project has its own requirements. It was impossible for us to keep everything on the same PHP version. Some projects require PostgreSQL, some Redis and some Elasticsearch, so not all projects are the same.

On top of that, not all developers are technical and know how to install and configure all the required server software themself. For example, we have a lot of front-enders who are great in what they do but don't ask them to configure Apache or Nginx. So we needed something that was easy for everybody and that didn't require any technical knowledge.

One other requirement was that we could commit the project configuration and installation scripts. For Docksal we simply create project-specific commands that can do the project setup after the containers start. These scripts are also committed. So everything you need to get started is inside the repository.

The project setup and the creation of the installation commands is something a technical person (tech lead or architect) does when the project is first created. After that, every developer that needs to work on the project just clones the repository and starts the project.

Updating a PHP version is also very easy. The technical person updates PHP in their configuration and tests the application (unit test, integration test and manual tests). Afterwards, the changes to the configuration are committed. After a developer pulls the new changes, they automatically get a new PHP version (after a project restart).

Now we have a very structured way on how we work with projects, so onboarding new developers is a breeze because every developer knows which commands to use or where to look.

One additional tip. Add something about the setup in the README. It really helps developers to get started quickly.

1

u/gordonv Oct 10 '22

Not really. This UDemy is 4.5 hours.

And Docker itself is free and runs on everything.

6

u/BlueScreenJunky Oct 05 '22

I just install all the versions I need with Ondřej Surý's PPAs : https://launchpad.net/~ondrej/+archive/ubuntu/php

Then I serve my various projects with Apache2 (it probably works the same with nginx, I'm just less familiar with it) and point to the right PHP version for the project with this snippet in the VirtualHost (replace 8.1 with whatever version):

<FilesMatch ".+\.php$">
    SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost"
</FilesMatch>

Then I use some functions in my .bash_aliases file that I stole from homestead to change the version used in the CLI:

function php74() {
    sudo update-alternatives --set php /usr/bin/php7.4
    sudo update-alternatives --set php-config /usr/bin/php-config7.4
    sudo update-alternatives --set phpize /usr/bin/phpize7.4
}

function php80() {
    sudo update-alternatives --set php /usr/bin/php8.0
    sudo update-alternatives --set php-config /usr/bin/php-config8.0
    sudo update-alternatives --set phpize /usr/bin/phpize8.0
}

function php81() {
    sudo update-alternatives --set php /usr/bin/php8.1
    sudo update-alternatives --set php-config /usr/bin/php-config8.1
    sudo update-alternatives --set phpize /usr/bin/phpize8.1
}

2

u/dabenu Oct 05 '22

I have:

change-php () {
  `export PATH=echo "${PATH}" | sed -E "s/php[0-9]*/php${1}/"` 
}

3

u/itemluminouswadison Oct 05 '22

docker for sure. on mac using homebrew you can also just link different versions using brew link

2

u/crazedizzled Oct 05 '22

Use docker or vagrant. It's generally better to keep separate projects isolated.

1

u/ddz1507 Oct 05 '22

I just use MAMP Pro

1

u/andoril Oct 05 '22

Instead of docker you can also use the nix package manager. Works well with a config per project and imo doesn't have as much overhead as docker in daily usage, with the draeback of having a steeoer learning curve

1

u/rish_p Oct 06 '22

on local macbook, valet works best for me. very easy to setup and switch.https://laravel.com/docs/9.x/valet

edit: after reading the comments, I have tried them but nothing beats valet as far as I know so give it a try.

1

u/dev-data Apr 22 '26

I use the fast version manager written in Rust, jdx/mise, for both Node.js and PHP. For PHP, I use the cross-platform verzly/mise-php plugin, which also supports Composer, PECL, and PIE.

-1

u/ddruganov Oct 05 '22

Docker lol