Welcome to the comprehensive guide on setting up your Ubuntu server to host multiple PHP versions. This guide is designed for beginners and will walk you through each step of the process in a user-friendly manner. Whether you're managing a headless server via SSH or just getting started with server administration, you're in the right place.
Before diving into the technicalities, it's crucial to understand the significance of adding an APT repository for PHP versions on your Ubuntu server. This setup allows you to install and run multiple versions of PHP side by side, which can be incredibly useful for running different applications that require specific PHP versions. By following this guide, you'll be able to set up PHP 5.6, PHP 7.x, and PHP 8.x along with the most requested extensions.
Before we begin, ensure that your server runs one of the Supported Ubuntu Releases. It's also important to have SSH access to your server as this guide is intended for a headless server setup. Basic knowledge of terminal commands will be beneficial.
First, we need to prepare your Ubuntu server for the repository addition. Open your terminal and connect to your server via SSH. Once logged in, update your package lists to ensure you have the latest versions of the software:
sudo apt update && sudo apt upgrade
Now, install the software-properties-common
package. This package provides an easier way to add new repositories:
sudo apt install software-properties-common
With your system updated and ready, it's time to add the PHP repository to your Ubuntu server. This repository is maintained by Ondřej Surý and supports Debian and Ubuntu systems. Execute the following command to add the repository:
LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
This command also circumvents a known issue with add-apt-repository
and non-UTF-8 locales, as documented here.
Once the repository is added, you can now install the desired PHP versions. For example, to install PHP 8.0, use the following command:
sudo apt install php8.0
Repeat this step for any other PHP versions you wish to install, such as PHP 7.4 or PHP 5.6, by replacing php8.0
with the desired version number in the command above.
If you're using specific web servers or packages, consider adding their respective PPAs for optimal compatibility and performance:
ppa:ondrej/apache2
ppa:ondrej/nginx
or ppa:ondrej/nginx-mainline
ppa:ondrej/pkg-gearman
Join LinuxPatch today and take control of your server's patch management with ease.
Sign Up NowBy following the steps outlined in this guide, you've successfully set up your Ubuntu server to support multiple PHP versions through the APT repository. This setup not only allows for greater flexibility in managing different applications but also ensures that you're using supported versions of PHP. Remember to check the official PHP website for information on supported versions and the repository website for updates and additional information.