Patch PHP2Shell on PHP
PHP2Shell is two remote code execution flaws in the PHP interpreter itself. The only fix is a PHP update, to 8.2.35, 8.3.36, 8.4.27 or 8.5.12, applied to every SAPI you run.
- You need
- Root or sudo on the server. A source build also needs a C compiler and the PHP build dependencies.
- Updated
- By
- PXL
Fixed in
- 8.2.35
- 8.3.36
- 8.4.27
- 8.5.12
Affected: Every release older than the fixed versions. PHP 8.1 and older are end of life and get no official release.
Update from your package manager first
The fastest fix is the update your distribution or PHP vendor already ships. On Debian and Ubuntu it is in the security repositories or in Ondřej Surý’s packages; on the Red Hat family it comes through the module streams. Install it, then reload PHP-FPM. The per-distribution guides list the exact package versions. Build from source only when no package covers your branch or your build.
Pull the latest package lists and upgrade PHP and its modules, then reload PHP-FPM.
sudo apt update && sudo apt upgrade
sudo systemctl reload php8.3-fpmInstall the build dependencies
To build from source you need a C compiler and the development headers for the extensions you build. The sets below cover a typical web build: XML, SQLite, OpenSSL, cURL, zlib, mbstring, zip and GD. Building Apache mod_php also needs Apache’s apxs tool, noted in each tab. The autoconf, bison and re2c packages matter only when you build from a Git branch, as in the end-of-life section below; a release tarball ships a ready configure script.
sudo apt-get update
sudo apt-get install -y build-essential pkg-config autoconf bison re2c \
libxml2-dev libsqlite3-dev libssl-dev libcurl4-openssl-dev zlib1g-dev \
libonig-dev libzip-dev libpng-dev libjpeg-dev libfreetype6-dev
# Apache mod_php also needs: sudo apt-get install -y apache2-devDownload and verify the source
Fetch the tarball for your branch from php.net/distributions, along with its .asc signature. Check the SHA256 against the value on the downloads page, then verify the GPG signature with the release manager’s key from php.net/gpg-keys.php. Verify before you extract.
curl -O https://www.php.net/distributions/php-8.3.36.tar.xz
curl -O https://www.php.net/distributions/php-8.3.36.tar.xz.asc
sha256sum php-8.3.36.tar.xz # compare with php.net/downloads.php
gpg --verify php-8.3.36.tar.xz.asc php-8.3.36.tar.xz
tar -xf php-8.3.36.tar.xz && cd php-8.3.36Configure for your SAPI
The command-line interpreter builds by default. Add a flag for each server SAPI you run (--enable-fpm for PHP-FPM, --with-apxs2 for Apache mod_php), then the --with-* and --enable-* flags for the extensions you need. The same binary serves every SAPI you enable; run ./configure --help for the full list.
./configure \
--prefix=/usr/local/php \
--enable-fpm --with-fpm-user=www-data --with-fpm-group=www-data \
--enable-mbstring --with-openssl --with-curl --with-zlib \
--with-zip --enable-gd --with-jpeg --with-freetype \
--with-pdo-mysql --with-mysqliCompile and install
Build with every core, run the test suite if you want the extra check (it is optional and slow), then install. Copy a php.ini from the production template and create the PHP-FPM pool configuration from the bundled defaults.
make -j"$(nproc)"
make test # optional
sudo make install
sudo cp php.ini-production /usr/local/php/lib/php.ini
sudo cp /usr/local/php/etc/php-fpm.conf.default /usr/local/php/etc/php-fpm.conf
sudo cp /usr/local/php/etc/php-fpm.d/www.conf.default /usr/local/php/etc/php-fpm.d/www.confEvery SAPI needs the update
The flaw is in the interpreter, so one PHP update fixes PHP-FPM, Apache mod_php and php-cgi at once. But each runs its own processes, and the new binary takes effect only after they restart. Restart every SAPI you run; a package upgrade reloads PHP-FPM but leaves other servers and long-lived workers on the old binary. PHP rates the risk highest for mod_php, where an unauthenticated request can trigger the flaw before any application code runs.
sudo systemctl restart php8.3-fpm # PHP-FPM
sudo systemctl restart apache2 # Apache mod_php
# php-cgi: restart whatever spawns it (spawn-fcgi, your supervisor, the web server)PHP 7.4, 8.0 and 8.1 (end of life)
These branches get no packaged release from the PHP project. Given the severity, the PHP security team published minimal source backports as branches in php-src: PHP-7.4-CVE-2026-109618-109619, PHP-8.0-CVE-2026-109618-109619 and PHP-8.1-CVE-2026-109618-109619. Build the matching branch from source. Because it is a Git checkout rather than a release tarball, run ./buildconf first, which needs autoconf, bison and re2c. If you would rather not compile, use a backport from your distribution or LTS vendor, or move to a supported branch. The branch names are linked from the php.net advisory; confirm them there before you build.
# Example: the PHP 8.1 backport branch
git clone https://github.com/php/php-src.git
cd php-src
git checkout PHP-8.1-CVE-2026-109618-109619
./buildconf --force
./configure --enable-fpm --with-apxs2=/usr/bin/apxs2
make -j"$(nproc)"
sudo make installConfirm the update
Check the PHP version of the running server process as well as the CLI.
php-fpm8.3 -v # or: php -v