Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lucenarenato/4a31206e9d65fe0981e35a1f0b04f6d1 to your computer and use it in GitHub Desktop.
Save lucenarenato/4a31206e9d65fe0981e35a1f0b04f6d1 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.

@lucenarenato
Copy link
Author

Outras que usei.

lsb_release -cd ; getconf LONG_BIT ; lsb_release -a

pacman -Ss php-

pacman -S make
pacman -S go
pacman -S gcc
pacman -S pkgconf
pacman -S fakeroot
pacman -S patch
pacman -S binutils

mkdir -p $HOME/bin
mkdir ~/src
cd ~/src
git clone https://aur.archlinux.org/php72.git
cd php72
makepkg -si

pacman -Qi php
php72 -v

@lucenarenato
Copy link
Author

Alteração nova no script

[[ -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}"
  /usr/bin/php72 -v
  php72 -v
  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

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

@ruscher
Copy link

ruscher commented Jul 11, 2023

No BigLinux tem um pacote prontinho em Docker que faz tudo isso num clique.

Só instalar o pacote: biglinux-docker-lamp

LAMP: Linux, Apache, MySQL, PHP stack for dynamic web development

Grato
Rafael Ruscher

@lucenarenato
Copy link
Author

@ruscher não uso apache. Como trabalho com laravel, eu uso sail do laravel, e as vezes uso php local da maquina para baixar bibliotecas com composer. Valeu!

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