As a developer you may sometime need to test an app on different PHP versions. Today I am going to show you how to switch PHP versions in Arch and Manjaro OS.
I have PHP 7 and 8(8.1) installed on Manjaro. I even have
php56 package from AUR repository only for testing an old project for a client.
Install PHP 7 and 8 with Apache if not installed yet.
sudo pacman -Sy php7 php7-apache php php-apache apache
You can check any other packages you want to install from the article below.
After the installation is done, open the Apache config file.
sudo vim /etc/httpd/conf/httpd.conf
Loadmodule section, add the following lines for PHP 7.
LoadModule php7_module modules/libphp7.so AddHandler php7-script php Include conf/extra/php7_module.conf
The following will default to the current latest version of PHP.
LoadModule php_module modules/libphp.so AddHandler php-script php Include conf/extra/php_module.conf
php56, if you have installed it from AUR repository. Otherwise I will advise to not install it.
LoadModule php5_module modules/libphp56.so AddHandler php5-script php Include conf/extra/php56_module.conf
If you have all these snippets added to the config file, make sure to comment out the rest which are not in use, for example the default one(8.1).
#LoadModule php_module modules/libphp.so #AddHandler php-script php #Include conf/extra/php_module.conf
Save the file, and restart Apache.
sudo systemctl restart httpd