r/PHPhelp • u/[deleted] • 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!
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
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
13
u/CyberJack77 Oct 05 '22
Just just docker. You can easily switch PHP versions, but also manage other project requirements (and versions).