Install PHP 5.6 on Ubuntu 22.04 with PHP-FPM
PHP (Hypertext Preprocessor) is an open-source, server-side scripting language widely used in web development. Although PHP 5.6 has reached end of life, some teams still install PHP 5.6 on Ubuntu to power dynamic sites, handle forms, manage sessions, and connect to MySQL or PostgreSQL. Many organizations retain this release due to legacy apps or compatibility requirements. PHP also offers a rich set of extensions, keeping it adaptable for modern scenarios.
This guide shows how to install PHP 5.6 on Ubuntu 22.04. You will add the required repositories, install PHP modules, configure PHP-FPM, and integrate it into your applications via PHP-FPM.
Prerequisites
Have access to an Ubuntu 22.04 instance as a non-root sudo user.
Install the PHP PPA Repository
PHP 5.6 is deprecated and not available in Ubuntu’s default repositories. You must add a Personal Package Archive (PPA) that maintains older PHP builds. The Ondřej Surý PPA is commonly used for installing legacy PHP versions. Follow these steps to add the PHP PPA.
Update the APT package index
console
Copy
$ sudo apt update
Add the ondrej/php PPA
console
Copy
$ sudo add-apt-repository ppa:ondrej/php
Press Enter to proceed with adding the repository to your system.
…
WARNING: add-apt-repository is broken with non-UTF-8 locales, see
https://github.com/oerdnj/deb.sury.org/issues/56 for workaround:
# LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
More info: https://launchpad.net/~ondrej/+archive/ubuntu/php
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.
If you hit non-UTF-8 locale errors
Run the following to add the repository with a UTF-8 locale.
console
Copy
$ sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
Refresh APT indexes
console
Copy
$ sudo apt update
Install PHP 5.6 on Ubuntu
Use the following steps to install PHP 5.6 and essential modules commonly required by web applications.
Install PHP 5.6
console
Copy
$ sudo apt install -y php5.6
Install common PHP 5.6 modules
console
Copy
$ sudo apt install -y php5.6-mysql php5.6-xml php5.6-curl php5.6-cli
When asked to restart services, use Tab to select <Ok> and press Enter.
Verify the installed PHP version
console
Copy
$ php -v
Your output should resemble the following.
PHP 5.6.40-81+ubuntu22.04.1+deb.sury.org+1 (cli) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies
Install PHP 5.6 FPM
PHP-FPM (FastCGI Process Manager) is a FastCGI implementation that handles PHP requests efficiently. It offers better resource usage and performance than traditional methods. PHP-FPM runs PHP processes independently, improving memory management, concurrency handling, and integration capabilities. Follow these steps to install PHP 5.6 FPM.
Install the PHP 5.6 FPM package
console
Copy
$ sudo apt install php5.6-fpm
When prompted to restart services, use Tab to select <Ok> and press Enter.
Start PHP 5.6 FPM
console
Copy
$ sudo systemctl start php5.6-fpm
Enable PHP 5.6 FPM at boot
console
Copy
$ sudo systemctl enable php5.6-fpm
Confirm PHP 5.6 FPM status
console
Copy
$ sudo systemctl status php5.6-fpm
Your output should be similar to this.
● php5.6-fpm.service - The PHP 5.6 FastCGI Process Manager Loaded: loaded (/lib/systemd/system/php5.6-fpm.service; enabled; vendor preset: enabled) Active: active (running) since Thu 2025-03-20 22:54:20 UTC; 3min 27s ago Docs: man:php-fpm5.6(8) Main PID: 16489 (php-fpm5.6) Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec" Tasks: 3 (limit: 2217) Memory: 11.9M CPU: 42ms CGroup: /system.slice/php5.6-fpm.service ├─16489 "php-fpm: master process (/etc/php/5.6/fpm/php-fpm.conf)" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ├─16490 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""> └─16491 "php-fpm: pool www" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ""> Mar 20 22:54:20 test-server systemd[1]: php5.6-fpm.service: Deactivated successfully. Mar 20 22:54:20 test-server systemd[1]: Stopped The PHP 5.6 FastCGI Process Manager. Mar 20 22:54:20 test-server systemd[1]: Starting The PHP 5.6 FastCGI Process Manager... Mar 20 22:54:20 test-server systemd[1]: Started The PHP 5.6 FastCGI Process Manager.
Test and Use PHP 5.6
Use the following steps to create a PHP test file, configure your web server, and wire PHP-FPM to handle PHP requests for dynamic applications.
Create a PHP info file
Create a PHP information file using any editor such as nano.
console
Copy
$ sudo nano /var/www/html/info.php
Add the PHP info snippet
Add the following PHP code to display configuration details.
php
Copy
<?php phpinfo(); ?>
Save and close the file.
Enable required Apache modules
Enable the proxy_fcgi
module so Apache can communicate with PHP-FPM and the setenvif
module for managing environment variables.
console
Copy
$ sudo a2enmod proxy_fcgi setenvif
Your output should look like this:
Considering dependency proxy for proxy_fcgi: Enabling module proxy. Enabling module proxy_fcgi. Module setenvif already enabled To activate the new configuration, you need to run: systemctl restart apache2
Restart Apache to apply modules
console
Copy
$ sudo systemctl restart apache2
Configure Apache to use PHP-FPM
Edit the default site to process PHP via PHP-FPM.
console
Copy
$ sudo nano /etc/apache2/sites-available/000-default.conf
Add the following block inside the <VirtualHost *:80>
section.
apache
Copy
<FilesMatch \.php$> SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/" </FilesMatch>
Save and close the file.
Test the Apache configuration
console
Copy
$ sudo apache2ctl -t
Your output should be similar to the following:
Syntax OK
If you see Syntax OK, your configuration is valid.
Restart Apache to apply changes
console
Copy
$ sudo systemctl restart apache2
Allow HTTP through the firewall
console
Copy
$ sudo ufw allow 80
Reload the firewall
console
Copy
$ sudo ufw reload
Access the PHP info page
Open the /info.php
path using your server IP in a browser such as Chrome.
http://<SERVER-IP>/info.php
PHP information page
Warning
PHP 5.6 no longer receives security updates. For stronger security and performance, upgrade to a newer PHP release. Use PHP 5.6 only when required for legacy software.
Conclusion
You have installed PHP 5.6 on Ubuntu 22.04 and configured PHP-FPM to serve web requests efficiently. You installed PHP 5.6 from a custom PPA, set up PHP-FPM for performance, and configured PHP-FPM to handle PHP traffic on the server. Visit the official PHP documentation for additional details on PHP 5.6 security best practices and configuration options.