Install Any PHP on Arch / Manjaro
While develop I found myself in the situation of having multiple versions of php I found a solution, docker, but now I won't talk about docker.
browsing I found this github repository, where speak about install multiple version of php on arch linux o majaro.
michaelbutler is the creator of this solution, it does not apply to other distributions like debian(ubuntu) derivations.
Through the AUR it is possible to install older and newer PHP versions, simultaneously on the same system.
michaelbutler did the following
mkdir ~/src
cd ~/src
git clone https://aur.archlinux.org/php81.git
cd php81
makepkg -si
# Wait a very long time (it literally compiles and installs php AND ALL MODULES
# enter sudo password after the compile step is doneif you want install another version, this is list of aur repository
JavaScript
mkdir ~/src
git clone https://aur.archlinux.org/php81.git
git clonehttps://aur.archlinux.org/php71.gitt
git clonehttps://aur.archlinux.org/php71.gitt
git clonehttps://aur.archlinux.org/php71.gitt
git clone https://aur.archlinux.org/php71.gitIn that example, php 8.1 is now available at /usr/bin/php81 along with /usr/bin/phpize81 . These steps can be repeated by just changing php81 to another version, such as php74 or php80 to get more versions installed. Then, to help with activating a specific PHP version at any given time (mainly for CLI commands) I use this simple script, placed in my $PATH:
JavaScript
#!/usr/bin/env bash
[[ -n $DEBUG ]] && set -x
red='\033[0;31m'
green='\033[0;32m'
reset='\033[0m'
VERSION=$1
if [[ -z $1 ]]; then
echo -e "${red}Error: no version specified!${reset}"
echo -e "Usage: \`phpenv [VERSION]\`"
echo -e "Example: \`phpenv 81\`"
fi
PHP_BIN="/usr/bin/php$VERSION"
PHPIZE_BIN="/usr/bin/phpize$VERSION"
PHP_FPM_BIN="/usr/bin/php-fpm$VERSION"
PHP_DBG_BIN="/usr/bin/phpdbg$VERSION"
PHP_CGI_BIN="/usr/bin/php-cgi$VERSION"
PHP_PEAR_BIN="/usr/bin/pear$VERSION"
PHP_PECL_BIN="/usr/bin/pecl$VERSION"
if [[ -f "$PHP_BIN" ]]; then
echo -e "${green}Activating PHP $VERSION..."
rm -f $HOME/bin/php $HOME/bin/phpize $HOME/bin/php-fpm $HOME/bin/phpdbg $HOME/bin/php-cgi $HOME/bin/pear $HOME/bin/pecl
ln -s $PHP_BIN $HOME/bin/php
ln -s $PHPIZE_BIN $HOME/bin/phpize
ln -s $PHP_FPM_BIN $HOME/bin/php-fpm
ln -s $PHP_DBG_BIN $HOME/bin/phpdbg
ln -s $PHP_CGI_BIN $HOME/bin/php-cgi
ln -s $PHP_PEAR_BIN $HOME/bin/pear
ln -s $PHP_PECL_BIN $HOME/bin/pecl
php -v
else
echo -e "${red}Error: $PHP_BIN could not be found!${reset}"
fiThen I can run it any time with phpenv 74 to activate 7.4, and phpenv 81 to activate 8.1. You can customize and add more versions as needed, just update the paths. As a reminder, php --ini will print out the location of the .ini files that are loaded.
for mi the better solitions is docker, cause nothing install ot modified our system
2.4k
Related Articles
Discussion
3 commentsShare your thoughts...

