PHP2Shell: How to Patch Your WordPress Server
This guide shows you how to protect your WordPress server from the PHP2Shell vulnerability, either by patching the server you already have or by moving your site 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. It doesn’t matter how well your WordPress site, themes or plugins are kept up to date: if PHP serves web requests (Apache with mod_php, PHP-FPM and so on), the server is at risk.
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:
- Patch your existing server: the quickest option, and the right one for most people.
- Launch a new instance from our latest image and migrate your site: 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
Step 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.
Step 2: Check Your Ubuntu and PHP Versions
Log in to your server over SSH (see Customizing Your WordPress server if you need a hand with this) and run:
lsb_release -ds
php -v
Step 3: Install the Updates
sudo apt update
sudo apt upgrade -y
This installs the patched PHP packages along with every other pending security update. Then restart the web server so it loads the new PHP:
sudo systemctl restart apache2
If you have switched your site to PHP-FPM, restart that too. This lists the FPM service, if there is one:
systemctl list-units --type=service 'php*-fpm*'
sudo systemctl restart php8.3-fpm
Replace php8.3-fpm with the service name shown on your server.
Step 4: Confirm You Are Patched
Check the installed PHP package version:
dpkg -l | grep -E '^ii +php[0-9.]+-(cli|common) '
Compare the version 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.
Step 5: Check for Signs of Compromise
Because PHP2Shell was exploited before many servers were patched, it’s worth a quick look for anything an attacker may have left behind:
- PHP files in your uploads folder. WordPress never puts PHP files there, so anything this finds deserves a closer look:
sudo find /var/www -path '*wp-content/uploads*' -name '*.php'
- Recently changed PHP files. This lists PHP files changed since mid-October 2026. Expect to see files from WordPress, theme and plugin updates you ran yourself; look for anything you don’t recognise:
sudo find /var/www -name '*.php' -newermt '2026-10-17' -ls
- Administrator accounts. In your WordPress dashboard, go to Users and filter by Administrator. Remove any account you don’t recognise, then change your own password.
If you find something suspicious, the safest response is to move your site to a fresh instance (Option 2), restoring your content rather than copying the old server as-is, and to change all your passwords.
Option 2: Launch a New Instance and Migrate Your Site
Our latest WordPress images already include the PHP2Shell fix. Every image build is automatically checked for it before release. They run the current Ubuntu LTS with the latest WordPress, MariaDB, PHP and phpMyAdmin. Moving to a new instance gets you a fully supported operating system as well as the fix.
Step 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. Give the new instance 5-10 minutes to finish its first boot. Its database credentials are stored at:
/opt/wordpress/default-wordpress-credentials.txt
Don’t run the WordPress installer on the new instance; your existing site will take its place.
Step 2: Back Up Your Site on the Old Server
On your old server, find where WordPress lives and what its database is called:
grep -R DocumentRoot /etc/apache2/sites-enabled/
grep -E "DB_NAME|table_prefix" /var/www/wordpress/wp-config.php
Use the folder from the first command in place of /var/www/wordpress if yours is different (older images used /var/www/html). Then put your site in a quiet state (avoid publishing while you migrate), and create a backup of the database and your wp-content folder:
sudo mysqldump --single-transaction wordpress > ~/wordpress.sql
sudo tar czf ~/wp-content.tar.gz -C /var/www/wordpress wp-content
Replace wordpress in the first command with your DB_NAME if it is different.
Step 3: Copy the Backup to the New Server
From the old server, copy both files across. Use the username for your new instance (ubuntu on AWS, the admin user you chose on Azure) and its IP address:
scp ~/wordpress.sql ~/wp-content.tar.gz ubuntu@NEW-SERVER-IP:~
Your new instance’s SSH key needs to be available on the old server for this. Alternatively, download the files to your computer with SFTP and upload them to the new server (see SFTP: Uploading Files Securely).
Step 4: Restore on the New Server
On the new server, import the database and unpack your content:
sudo mysql wordpress < ~/wordpress.sql
sudo tar xzf ~/wp-content.tar.gz -C /var/www/wordpress
sudo chown -R www-data:www-data /var/www/wordpress/wp-content
If your old $table_prefix was not wp_, set the same prefix in /var/www/wordpress/wp-config.php on the new server. Keep the rest of the new wp-config.php as it is: it already holds the new server’s database credentials.
Step 5: Point Your Site at the New Server
- Using a domain name? Update your DNS record to the new server’s IP address. Once DNS has updated, set up your SSL certificate again on the new server.
- Moving to a new IP or address? WordPress stores its address in the database. Update it to match the new one (this example assumes the default
wp_prefix):
sudo mysql wordpress -e "UPDATE wp_options SET option_value='http://NEW-ADDRESS' WHERE option_name IN ('siteurl','home');"
Log in to your WordPress dashboard on the new server, check your pages, plugins and media, and update any plugins and themes that have updates waiting.
Sending email from Azure? Azure blocks outbound email on port 25 for most subscriptions, so our Azure image doesn’t run a local mail server. Use an SMTP plugin with your email provider, or a service such as SendGrid, for WordPress notifications.
Step 6: Retire the Old Server
Keep the old server stopped (not deleted) for a few days, until you’re happy everything is working on the new one. Then delete it, along with its snapshots, so you’re no longer paying for it.
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 in under an hour.
Need a hand? Our support team can help you patch your server or migrate your site. Just reach out to support@solvedevops.com.
Disclaimer:
All product and company names are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.