How to Install Multiple PHP Versions on a Debian Server with ISPConfig
Are you looking to expand your PHP capabilities on your Debian server using ISPConfig? This comprehensive guide not only shows you how to install a range of PHP versions—from 5.6 to 8.4—but also ensures your server remains optimal and secure. By following these precise steps, you can easily manage multiple PHP versions tailored for specific websites, enhancing flexibility and performance. Let’s dive in!
1. Preliminary Notes
In this guide, you’ll be adding the SURY repository to install various PHP packages using apt
. Ensure not to remove this repository later, as it provides essential updates, including those for OpenSSL. Remember, PHP-FPM works seamlessly with both Apache and Nginx, while FastCGI is exclusive to Apache servers.
2. Adding the SURY Repository
Before installing additional PHP versions, first, you need to set up the SURY repository:
apt-get install -y apt-transport-https lsb-release ca-certificates
Next, execute the following commands:
wget -O /etc/apt/trusted.gpg.d/php.gpg >/dev/null 2>&1
echo "deb $(lsb_release -c -s) main" > /etc/apt/sources.list.d/php.list
Update the package list:
apt-get update
To upgrade any previously installed packages under the new repository, run:
apt-get upgrade
3. Installing Additional PHP Versions
Install only the PHP versions necessary for your projects. Here’s how to install them:
3.1 Install PHP 5.6
apt-get install php5.6 php5.6-cli php5.6-cgi php5.6-fpm php5.6-gd php5.6-mysql php5.6-imap php5.6-curl php5.6-intl php5.6-pspell php5.6-recode php5.6-sqlite3 php5.6-tidy php5.6-xmlrpc php5.6-xsl php5.6-zip php5.6-mbstring php5.6-soap php5.6-opcache libicu65 php5.6-common php5.6-json php5.6-readline php5.6-xml
3.2 Install PHP 7.0
apt-get install php7.0 php7.0-cli php7.0-cgi php7.0-fpm php7.0-gd php7.0-mysql php7.0-imap php7.0-curl php7.0-intl php7.0-pspell php7.0-recode php7.0-sqlite3 php7.0-tidy php7.0-xmlrpc php7.0-xsl php7.0-zip php7.0-mbstring php7.0-soap php7.0-opcache php7.0-common php7.0-json php7.0-readline php7.0-xml
3.3 Install PHP 7.1 through 8.4
Follow similar commands for each version, replacing the version numbers accordingly:
apt-get install php7.1…php7.4…php8.0…php8.1…php8.2…php8.3…php8.4
4. Set Default PHP Versions
After all installations, ensure the OS default PHP version remains intact. Adjust your settings as follows:
update-alternatives --config php
Pick the correct version based on your distribution:
- Debian 12: PHP 8.2
- Debian 11: PHP 7.4
- Debian 10: PHP 7.3
5. Add PHP Versions in ISPConfig
To add the new PHP versions in ISPConfig, navigate to System > Additional PHP Versions > Add new PHP version. Insert the relevant configuration for each PHP version, as shown in the example below:
# For PHP 5.6
Fast-CGI settings:
Path to PHP FastCGI binary: /usr/bin/php-cgi5.6
Make sure to repeat this step for every version you have installed, replacing the version numbers accordingly.
FAQ
Question 1: Can I install PHP versions other than those listed?
Answer 1: Yes, you can add even older or newer versions, but ensure they’re compatible with your applications.
Question 2: Is it safe to remove the SURY repository later?
Answer 2: No, removing the SURY repository can lead to issues with future updates for critical packages like OpenSSL.
Question 3: How do I verify which PHP versions are installed?
Answer 3: Use the command php -v
to check the active version. You can also manage different versions by adjusting the options in ISPConfig.
Conclusion
Congratulations! You have successfully set up multiple PHP versions on your Debian server using ISPConfig. By being able to choose the specific PHP version for each website, you enhance the flexibility and performance of your server. If you have further questions or need support, don’t hesitate to reach out to the community or consult official documentation.