To install PHP 8.1 alongside PHP 7.4 on Zorin OS without uninstalling the existing version, you can follow these steps:
-
Add Repository:
sudo add-apt-repository ppa:ondrej/php
This command adds the PHP repository maintained by Ondřej Surý, who provides up-to-date PHP packages for Ubuntu-based systems.
-
Update Package List:
sudo apt update
-
Install PHP 8.1:
sudo apt install php8.1
During the installation, you might be prompted to choose between Apache and Nginx. Select the web server you are using or 'None' if you're not using a web server at the moment.
-
Install PHP Extensions: You might need to install additional PHP extensions that you had for PHP 7.4. You can do this using
apt
and thephp8.1
prefix.sudo apt install php8.1-{extension-name}
-
Switch PHP Version: Use the
update-alternatives
command to switch between PHP versions. For example, to switch to PHP 8.1:update-alternatives --config php
OR
sudo update-alternatives --set php /usr/bin/php8.1
To switch back to PHP 7.4, you can use:
sudo update-alternatives --set php /usr/bin/php7.4
-
Verify PHP Version: Check the PHP version to ensure the switch was successful:
php -v
Now, you should have both PHP 7.4 and PHP 8.1 installed on your Zorin OS, and you can switch between them using the update-alternatives
command.
Remember to update your web server configuration to use the appropriate PHP version based on your project requirements.
lit