On this page
- What are the risks of running end-of-life PHP?
- How do you install PHP 7.4 or 5.6 on Ubuntu?
- How do you install them on Debian with the Sury repository?
- How do you install old PHP side by side on Rocky or Alma?
- How do you give the legacy site its own pool and socket?
- How do you point Nginx or Apache at the old version?
- What breaks when old code meets a modern database?
- How do you reduce exposure while the app is still live?
- How do you plan the move off the old version?
- Questions
What are the risks of running end-of-life PHP?
PHP 7.4 reached end of life in November 2022 and PHP 5.6 at the end of 2018, so newly found bugs in the language itself are no longer fixed by the PHP project. Repository maintainers may still rebuild these packages for new systems, but they do not promise security patches for them.
The practical risk depends on exposure. An internal tool reached only over a VPN is very different from a public shop with a login form. Old applications also tend to bundle outdated libraries, which are often the easier target. Treat the legacy version as a bridge with an end date, not as a permanent setup, and keep the rest of the server current.
How do you install PHP 7.4 or 5.6 on Ubuntu?
Add the Ondrej PPA and install the versioned packages; they live in their own folders and do not replace PHP 8.
sudo apt install -y software-properties-common
sudo add-apt-repository -y ppa:ondrej/php
sudo apt update
sudo apt install -y php7.4-fpm php7.4-cli php7.4-mysql php7.4-mbstring \
php7.4-xml php7.4-curl php7.4-gd php7.4-zip
php7.4 -v
systemctl status php7.4-fpm --no-pagerFor PHP 5.6, use the same names with 5.6, such as php5.6-fpm and php5.6-mysql. Check availability for your release first with apt-cache policy php5.6-fpm, since very old branches may not be built for every new Ubuntu version.
How do you install them on Debian with the Sury repository?
After adding the Sury source as shown in PHP and PHP-FPM, install the old branch by its versioned name.
apt-cache policy php7.4-fpm php5.6-fpm
sudo apt install -y php7.4-fpm php7.4-cli php7.4-mysql php7.4-mbstring php7.4-xml
php7.4 -vEach version gets its own configuration tree under /etc/php/7.4/ and its own socket at /run/php/php7.4-fpm.sock, so nothing collides with /etc/php/8.2/ or /etc/php/8.4/.
Installing extra PHP versions can change the CLI default. Pin it back to your main version:
sudo update-alternatives --config php
sudo update-alternatives --set php /usr/bin/php8.3How do you install old PHP side by side on Rocky or Alma?
Remi ships parallel packages with a prefix (php74, php56) that install under /opt/remi and never touch the base PHP.
sudo dnf config-manager --set-enabled crb
sudo dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-9.noarch.rpm
sudo dnf install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
sudo dnf list available 'php74*fpm' 'php56*fpm'
sudo dnf install -y php74-php-fpm php74-php-cli php74-php-mysqlnd \
php74-php-mbstring php74-php-xml php74-php-gd
sudo systemctl enable --now php74-php-fpm
php74 -vPaths for this build are /etc/opt/remi/php74/ for configuration, /etc/opt/remi/php74/php-fpm.d/www.conf for the pool and /var/opt/remi/php74/run/php-fpm/www.sock for the socket. Swap 74 for 56 where the 5.6 build is listed. The base php-fpm service stays on PHP 8.
How do you give the legacy site its own pool and socket?
Create a dedicated Linux user and a pool file for the old version, so the old code runs with its own identity.
sudo useradd --system --home /var/www/legacy.example.net --shell /usr/sbin/nologin legacy
sudo chown -R legacy:legacy /var/www/legacy.example.netOn Debian or Ubuntu create /etc/php/7.4/fpm/pool.d/legacy.conf:
[legacy]
user = legacy
group = legacy
listen = /run/php/php7.4-legacy.sock
listen.owner = www-data
listen.group = www-data
listen.mode = 0660
pm = ondemand
pm.max_children = 5
pm.process_idle_timeout = 30s
php_admin_value[open_basedir] = /var/www/legacy.example.net:/tmp
php_admin_value[disable_functions] = exec,passthru,shell_exec,system,proc_open,popen
php_admin_flag[allow_url_include] = off
php_admin_flag[expose_php] = offsudo php-fpm7.4 -t && sudo systemctl restart php7.4-fpm
ls -l /run/php/php7.4-legacy.sockOn Rocky or Alma use /etc/opt/remi/php74/php-fpm.d/legacy.conf, set the socket to /var/opt/remi/php74/run/php-fpm/legacy.sock and set listen.owner to apache or nginx. The full pool pattern is in PHP-FPM pools.
How do you point Nginx or Apache at the old version?
Only the legacy virtual host changes; it names the 7.4 socket while other sites keep theirs.
# Nginx, inside the legacy server block
location ~ \.php$ {
try_files $uri =404;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.4-legacy.sock;
}# Apache, inside the legacy <VirtualHost>
<FilesMatch "\.php$">
SetHandler "proxy:unix:/run/php/php7.4-legacy.sock|fcgi://localhost"
</FilesMatch>Apache on Debian or Ubuntu needs sudo a2enmod proxy_fcgi setenvif for this, and the SetHandler inside the virtual host takes priority over a globally loaded mod_php for that site. Moving every site to PHP-FPM and switching Apache to the event worker is still the cleaner end state. Test and reload with sudo nginx -t or sudo apachectl configtest followed by a reload.
What breaks when old code meets a modern database?
Authentication and removed functions are the two common problems.
- PHP 5.6 drivers cannot speak the
caching_sha2_passwordmethod used by MySQL 8 accounts. Create the legacy account withIDENTIFIED WITH mysql_native_password BY '...', or use MariaDB, which still defaults to the native method. - Code written for PHP 5 may call
mysql_connect(), which exists in 5.6 but was removed in PHP 7. That alone decides whether 7.4 is possible. - Old TLS libraries in the app may fail against current HTTPS endpoints; outbound API calls are worth testing early.
Give the legacy app its own database account limited to its own schema, as shown in MySQL users and privileges.
How do you reduce exposure while the app is still live?
Limit who can reach it, limit what it can do and watch it closely.
- Restrict the admin path by IP in the web server, or put the whole site behind a VPN such as WireGuard if only staff use it.
- Keep
open_basediranddisable_functionsin the pool, and make the code folder read-only to the pool user except for upload or cache folders. - Add rate limits on login pages (Nginx rate limiting) and fail2ban rules on repeated failures.
- Back up files and database daily, so a compromise can be rolled back quickly.
A separate small VPS for the legacy app is also a clean option: if it is ever breached, your current sites are on a different machine.
How do you plan the move off the old version?
Measure what breaks on PHP 8 with a static scan, fix it in a copy and switch the socket when tests pass.
composer require --dev phpcompatibility/php-compatibility squizlabs/php_codesniffer
vendor/bin/phpcs --config-set installed_paths vendor/phpcompatibility/php-compatibility
vendor/bin/phpcs -p --standard=PHPCompatibility --runtime-set testVersion 8.3 src/Then clone the site to a staging host name with a PHP 8 pool, exercise its pages and switch the live virtual host. The steps for moving between versions are in upgrading PHP. When nothing uses the old branch any more, remove it with sudo apt purge 'php7.4*' or sudo dnf remove 'php74*'.
Plans that fit this guide
Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.
Questions about Run PHP 7.4 or 5.6 for legacy apps
Can PHP 7.4 and PHP 8.3 run at the same time?
Yes. Each version has its own FPM service, configuration folder and socket. The web server decides per site which socket receives PHP requests.
Which PHP version does the command line use?
On Debian and Ubuntu, the one set with update-alternatives --set php; call php7.4 directly for the old one. On Rocky and Alma, php is the base version and php74 runs the Remi build.
Is PHP 5.6 still available for new distributions?
Availability varies by repository and release. Check with apt-cache policy php5.6-fpm or dnf list available 'php56*' before you plan around it.
Do I get security updates for PHP 7.4 from these repositories?
Do not count on it. The PHP project stopped fixing 7.4 in 2022, so treat the packages as unsupported and isolate the site.
Should the legacy site get its own server instead?
If it handles logins, payments or personal data, a separate small VPS is a sensible boundary. Deploy one from the console and move only that site.