Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Diegiwg/4065cc6c7c8e763d1d91504f71332e7d to your computer and use it in GitHub Desktop.
Save Diegiwg/4065cc6c7c8e763d1d91504f71332e7d to your computer and use it in GitHub Desktop.
Install multiple PHP versions on Arch / Manjaro Linux / BigLinux

Install Any PHP on Arch / Manjaro / Biglinux

Through the AUR it is possible to install older and newer PHP versions, simultaneously on the same system. I often had trouble installing using pacman and pamac so here's what I did:

mkdir -p $HOME/bin
mkdir ~/src
cd ~/src
git clone https://aur.archlinux.org/php72.git
cd php72
makepkg -si
# Wait a very long time (it literally compiles and installs php AND ALL MODULES
# enter sudo password after the compile step is done

In that example, php 7.2 is now available at /usr/bin/php72 along with /usr/bin/phpize72 . 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:

Update: Better version of this script is in a comment below.

#!/bin/sh 


[[ -n $DEBUG ]] && set -x

red='\033[0;31m'
green='\033[0;32m'
reset='\033[0m'

echo "7 - php7.2"
echo "8 - php8.2"
# $1 is version: 7 for latest 7, 8 for latest 8
read opcao;
if [ "$opcao" == "7" ]; then
  echo -e "${green}Activating php 7.2 at location /usr/bin/php72 ...${reset}"
  rm -f $HOME/bin/php $HOME/bin/phpize
  ln -sf php72 php
  ln -s /usr/bin/php72 $HOME/bin/php
  ln -s /usr/bin/phpize72 $HOME/bin/phpize
  alias php=/usr/bin/php72 
  php -v
fi

if [ "$opcao" == "8" ]; then
  echo -e "${green}Activating php 8.2 at location /usr/bin/php82 ...${reset}"
  rm -f $HOME/bin/php $HOME/bin/phpize
  ln -s /usr/bin/php82 $HOME/bin/php
  ln -s /usr/bin/phpize82 $HOME/bin/phpize
  sleep 0.5
  php -v
fi

echo -e "Viva o \033[01;32mLinux\033[01;37m!" 

php -v
lsb_release -cd ; getconf LONG_BIT ; lsb_release -a,
pacman -Qi php

Then I can run it any time with phpenv 7 to activate 7.4, and phpenv 8 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment