LAMP

PHP2Shell: How to Patch Your LAMP Server

This guide shows you how to protect your LAMP server from the PHP2Shell vulnerability, either by patching the server you already have or by moving your applications to a fresh instance from our latest image.

What is PHP2Shell?

PHP2Shell is the name given to two critical vulnerabilities in PHP itself, CVE-2026-109618 and CVE-2026-109619, published on 21 October 2026. They affect PHP 5.4 through 8.5 and allow an attacker to run their own code on a web server just by sending it requests. Any server where PHP answers web requests is at risk, whether through Apache with mod_php or PHP-FPM, no matter what application it runs.

The flaws are being exploited in the wild, so treat this as urgent. Updating PHP is the only complete fix. The PHP developers have said the temporary workarounds that have been published are not enough on their own.

The fixed PHP releases are 8.2.35, 8.3.36, 8.4.27 and 8.5.12. Ubuntu doesn’t change the PHP version number when it patches; instead it ships the fix as a new package release, as shown in the table below.

You have two ways to get protected:

  1. Patch your existing server: the quickest option, and the right one for most people.
  2. Launch a new instance from our latest image and migrate: best if your server runs an Ubuntu release that no longer gets free security updates, or if you’d like a clean start.

Option 1: Patch Your Existing Server

1. Back up first: Before changing anything, take a snapshot of your server’s disk.

  • AWS: EC2 console → Volumes → select your instance’s volume → Actions → Create snapshot.
  • Azure: Azure Portal → your VM → Disks → select the OS disk → Create snapshot.

2. Check your Ubuntu and PHP versions: Log in over SSH and run:

lsb_release -ds
php -v

3. Install the updates: This installs the patched PHP packages along with every other pending security update:

sudo apt update
sudo apt upgrade -y

4. Restart Apache and PHP-FPM: Our LAMP image installs both mod_php and PHP-FPM, so restart Apache and any PHP-FPM service on the server:

sudo systemctl restart apache2
systemctl list-units --type=service 'php*-fpm*'
sudo systemctl restart php8.5-fpm

Replace php8.5-fpm with the service name the second command shows (for example php8.1-fpm on Ubuntu 22.04).

5. Confirm you are patched: Check the installed PHP package version:

dpkg -l | grep -E '^ii +php[0-9.]+-(cli|common) '

Compare it with the table below. Yours should be the same or newer:

Ubuntu release PHP Patched package version
26.04 8.5 8.5.4-0ubuntu1.5
24.04 8.3 8.3.6-0ubuntu0.24.04.13
22.04 8.1 8.1.2-1ubuntu2.28
20.04 7.4 Past standard support: see below

If you installed PHP from another source, such as the ondrej/php PPA, php -v should report one of the fixed releases instead: 8.2.35, 8.3.36, 8.4.27, 8.5.12 or newer.

Running Ubuntu 20.04? Ubuntu 20.04 reached the end of standard support in 2025, so it no longer receives free security updates, and the PHP 7.4 it ships has no official fix. Unless you have an Ubuntu Pro subscription that provides one, the safest path is Option 2 below.

6. Check for signs of compromise: PHP2Shell was exploited before many servers were patched, so take a few minutes to look for anything an attacker may have left behind. This lists PHP files under your web root changed since mid-October 2026:

sudo find /var/www -name '*.php' -newermt '2026-10-17' -ls

Expect to see files you changed yourself; look for anything you don’t recognise, especially in upload or cache folders. It’s also worth checking sudo crontab -l and crontab -l for jobs you didn’t create. If you find something suspicious, move your application to a fresh instance (Option 2), deploying it from your own source code rather than copying the old server’s files, and change all your passwords.

Option 2: Launch a New Instance and Migrate

Our latest LAMP images already include the PHP2Shell fix. Every image build is automatically checked for it before release. They run the current Ubuntu LTS with up-to-date Apache, MariaDB, PHP and phpMyAdmin, so moving to a new instance also gets you a fully supported operating system.

1. Launch the latest image: Launch a new instance from our image on your cloud of choice:

Our AWS and Azure getting-started guides walk you through the launch. Once it has finished its first boot, the new MariaDB and phpMyAdmin credentials are stored at:

/opt/lamp/generated-credentials.txt

2. Back up your applications on the old server: On your old server, list your databases:

sudo mysql -e 'SHOW DATABASES;'

Back up your own databases (leave out the system ones: information_schema, mysql, performance_schema, sys and phpmyadmin), your web files and your Apache site configuration:

sudo mysqldump --single-transaction --databases app_db1 app_db2 > ~/databases.sql
sudo tar czf ~/www.tar.gz -C /var/www html
sudo tar czf ~/apache-sites.tar.gz -C /etc/apache2 sites-available

Replace app_db1 app_db2 with your database names. If your applications live outside /var/www/html, include those folders in the second command too.

Also note down:

  • The database users your applications connect with, and their passwords (usually in each application’s config file).
  • Any cron jobs: crontab -l and sudo crontab -l.
  • Any extra PHP extensions you installed: dpkg -l | grep php.

3. Copy the backup to the new server: From the old server (use your new instance’s username and IP address):

scp ~/databases.sql ~/www.tar.gz ~/apache-sites.tar.gz ubuntu@NEW-SERVER-IP:~

Or download the files to your computer with SFTP and upload them to the new server.

4. Restore on the new server: On the new server, import the databases, then re-create your application database users:

sudo mysql < ~/databases.sql
sudo mysql -e "CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'app-password'; GRANT ALL PRIVILEGES ON app_db1.* TO 'appuser'@'localhost';"

Restore your web files and any custom Apache sites:

sudo tar xzf ~/www.tar.gz -C /var/www
sudo chown -R www-data:www-data /var/www/html
sudo tar xzf ~/apache-sites.tar.gz -C /tmp

Copy your own site files from /tmp/sites-available into /etc/apache2/sites-available, enable each with sudo a2ensite your-site, then check the configuration and reload Apache:

sudo apachectl configtest
sudo systemctl reload apache2

Install any extra PHP extensions your applications need, and add back your cron jobs.

5. Test before you switch: The new image may run a newer PHP version than your old server. For example, Ubuntu 20.04’s PHP 7.4 to Ubuntu 26.04’s PHP 8.5 is a big jump. Browse your applications on the new server’s IP address and check the Apache error log for problems:

sudo tail -f /var/log/apache2/error.log

6. Switch over: Update your DNS records to the new server’s IP address, set up your SSL certificates again, and keep the old server stopped (not deleted) for a few days until you’re happy everything is working. Then delete it and its snapshots.

Conclusion

PHP2Shell is serious, but the fix is simple: update PHP. For most servers that’s a single apt upgrade and a restart. If your server is on an older Ubuntu release, a fresh instance from our latest image gets you patched and fully supported.

Need a hand? Our support team can help you patch your server or migrate your applications. Just reach out to support@solvedevops.com.

Enjoy the Power of LAMP.