PHP2Shell: Swapping CloudPanel's Admin PHP 8.1 for 8.4 with a systemd Drop-in
At the end of the previous post, my second server was in this state: the site's PHP had been upgraded to 8.4.27, the nine unused versions were disabled, and only CloudPanel's own backend PHP was still stuck on 8.1.34.
PHP 8.1 reached end of upstream support at the end of 2025, and the PHP project won't publish any more official 8.1 releases. Some distros or platforms may backport fixes themselves, but you can't assume the package you have installed has been patched. I checked this server: the php8.1-fpm in CloudPanel's repository has no newer version to update to (apt policy shows the installed and candidate versions are the same), and the binary's build date is still December 2025, before this fix. So the backend's PHP was definitely unpatched.
So I first closed the backend's port in the firewall and switched to reaching it through an SSH tunnel. At that point the backend was no longer directly exposed to the internet and the risk of remote attack was much lower, but the old PHP's vulnerability was still there. For example, if another service on the server has something like an SSRF bug, or an attacker has already gained local access some other way, they could still reach the backend from inside the server. So I decided to go one step further: move the backend to 8.4.27.
Most of this post came from me repeatedly asking “why does this work?” along the way. The commands themselves are only a few lines; what's more worth taking away are the two mechanisms behind them, and how to judge before you start whether something will break, and how to confirm afterwards that the switch really happened.
To be clear: this is not the official way
CloudPanel doesn't offer a setting to switch the backend's PHP version. Someone has opened a feature request on GitHub asking for the backend to be moved to a supported version, but as of writing there's no official response.
So what follows is a record of an unofficial change that worked on this one server of mine, not an upgrade procedure for every CloudPanel version. There are a few costs to know up front:
- The backend code was released by the vendor to run on 8.1 and hasn't been officially validated on 8.4; some features may break after the switch.
- Future CloudPanel updates may conflict with your change.
- If something goes wrong, the vendor won't help you with it.
I decided to try anyway because three conditions held: I took a VPS snapshot first; the change lives in a single separate file that can be reverted at any time; and 8443 was already closed to the outside, so even if I broke the backend, the main impact would be that I couldn't get into it for a while. It wouldn't open up a new public entry point.
If you just want to reduce risk for now, do the previous post's “close the port and use an SSH tunnel” first. This post is for people who want to go a step further, or who want to understand how it works.
What the backend's PHP looks like
The one-liner from the previous post for finding every PHP listed eleven master processes on this server. One of them looks like this:
root php-fpm: master process (/home/clp/services/php-fpm/fpm/php-fpm.conf)
First, see which systemd service starts it:
systemctl cat clp-php-fpm
# /usr/lib/systemd/system/clp-php-fpm.service
[Unit]
Description=The CLP PHP 8.1 FastCGI Process Manager
Documentation=man:php-fpm8.1(8)
After=network.target
[Service]
Type=notify
PIDFile=/run/php/clp-php-fpm.pid
ExecStart=/usr/sbin/php-fpm8.1 -R -F -y /home/clp/services/php-fpm/fpm/php-fpm.conf -c /home/clp/services/php-fpm/fpm/php.ini
ExecReload=/bin/kill -USR2 $MAINPID
Restart=always
RestartSec=3
[Install]
WantedBy=multi-user.target
The four arguments on the ExecStart line:
-R: allows FPM pools to run as root (not allowed by default). This affects the worker processes that actually handle requests, not the master process; the master always starts as root and then drops worker privileges according to each pool'suserandgroupsettings. And-Ronly “allows” it: adding it doesn't mean workers will run as root. Their actual identity still depends on the pool config-F: runs in the foreground, managed by systemd-y: specifies the FPM config file-c: specifies the php.ini
Next, ask systemd for the service's main process and see which binary it's actually running:
sudo readlink -f /proc/$(systemctl show -p MainPID --value clp-php-fpm)/exe
# /usr/sbin/php-fpm8.1
Querying systemd for MainPID directly is more accurate than searching by name with pgrep; it won't accidentally pick up other processes that happen to contain the same string.
And with that, the crux of the whole thing appears: the backend is just using the system-installed php-fpm8.1 binary, paired with its own set of config files. The binary is one thing and the configuration is another; the two are separate.
So what happens if you swap the binary for the already-patched php-fpm8.4 on the same server and keep the config as is? To answer that, you first need to understand two things.
Why swapping the binary works: a socket sits between nginx and PHP
When a web request comes in, it flows roughly like this:
瀏覽器 → 後台的 nginx (8443) → /run/clp-php-fpm.sock → php-fpm → 後台的 .php 程式碼
↑
這裡從 8.1 換成 8.4
nginx doesn't execute PHP itself; it hands the request to php-fpm over a socket using the FastCGI protocol. That design has three consequences:
nginx doesn't know or care which version is behind it; all it knows is the socket path.
The socket path is in the config file, not in the binary. The backend's FPM config says where to open the socket, so after swapping the binary, the config is unchanged and so is the socket.
The backend code is just a pile of .php files that anything can execute, as long as the syntax and functions it uses still exist in the new version.
Also, PHP-FPM 8.1 and 8.4 both support the startup arguments used here, so it's worth trying to keep the original config and replace only the binary. But that's only “worth trying”: compatibility of config directives, extensions and the actual service still has to be checked one by one, which I'll cover below.
While we're at it, check whether any site uses this socket:
# 後台的 FPM 開了哪些 socket
sock=$(sudo grep -rhoP '^\s*listen\s*=\s*\K\S+' /home/clp/services/php-fpm/)
echo "$sock"
# 哪些設定檔有用到這些 socket
sudo grep -rl "$sock" /etc/nginx /home/clp/services 2>/dev/null
My result was two sockets (one for the backend itself and one for the file manager), appearing only under /home/clp/services and nowhere in the sites' /etc/nginx. Based on this server's nginx and FPM config, I found no front-end site requests using CloudPanel's FPM socket, so switching the backend's PHP should in theory not change the PHP version the sites use. Note that this check only covers the nginx config; it can't fully rule out other services or admin scripts depending on CloudPanel's original PHP environment.
You might wonder: the site's php8.4-fpm is also running, so won't running a second copy of the same binary for the backend cause a conflict? They're two independent master processes, each reading a different config file, opening different sockets and writing different PID files; they just happen to run the same program. As long as the sockets, PID files and log paths don't overlap, they won't interfere with each other. Each does have its own workers, though, and their memory usage adds up separately, so keep an eye on that on a small server.
Why you can “layer” config on top: systemd drop-ins
Now that we know swapping the binary is feasible, the next question is: how do you change it?
The obvious approach is to edit /usr/lib/systemd/system/clp-php-fpm.service directly, but that file is installed by the CloudPanel package and will be overwritten on the next package update.
systemd configuration is actually layered:
/usr/lib/systemd/system/: the original files installed by packages. They belong to the software vendor and get overwritten when the package updates./etc/systemd/system/服務名稱.service.d/*.conf(where 服務名稱 means “service name”): drop-ins added by the administrator. Package updates usually don't touch these files under/etc.
When systemd starts a service, it reads the original file first and then layers whatever the drop-in specifies on top; anything not specified keeps its original value. So the drop-in only needs the few lines you want to change. Everything else, like Type=notify, PIDFile and Restart=always, carries over from CloudPanel's original config.
This design exists precisely for administrators: leave the vendor's file alone, put your own tweaks somewhere else, package upgrades won't wipe them, and to revert you just delete the drop-in you created. systemctl edit is the command systemd provides for creating drop-ins. (systemctl revert can also undo changes, but its scope is broader; more on that in “How to roll back if it breaks” below.)
One small detail to watch: most settings follow “the later one overrides the earlier one,” but ExecStart is cumulative. Writing it twice gives you two commands, and a normal service only allows one, so the drop-in must first include an empty ExecStart= line to clear the original value, then the new one:
[Service]
ExecStart=
ExecStart=/usr/sbin/php-fpm8.4 ...
Before you start: check what could break
With the mechanisms understood, the next step is judging whether the switch will break anything. I split this into three things you can check in advance, plus one that can only be tested for real.
1. Argument compatibility
systemctl cat already showed the original startup arguments above. The new ExecStart copies them exactly and only changes the binary path. Also check whether anything else in the original service hard-codes 8.1, such as ExecStartPre. On my server, ExecStart was the only place.
Also, the original service is Type=notify, meaning php-fpm has to notify systemd when it's finished starting. The new binary must support this mechanism too, or the service won't be considered started. You'll find out when you actually start it later.
2. The config file parses on the new version
php-fpm has a -t flag that only tests the config file without actually starting, which is perfect for checking whether the backend's config uses any directives that are deprecated in 8.4:
sudo php-fpm8.4 -t \
-y /home/clp/services/php-fpm/fpm/php-fpm.conf \
-c /home/clp/services/php-fpm/fpm/php.ini
If you see test is successful, it passed. Note that -t only means the config file passed the check. It doesn't guarantee the socket can be created or that the service will run properly, let alone that the backend code is compatible; it just rules out one possible cause of breakage.
3. All extensions are present
With a new binary, the loaded extensions also switch to the 8.4 set. If the backend uses an extension that exists for 8.1 but not 8.4, that feature will break.
First check whether the backend's own php.ini loads any extensions manually:
grep -nE '^\s*(zend_)?extension' /home/clp/services/php-fpm/fpm/php.ini
Mine had two lines: extension=memcached.so and extension=redis.so. These give only the filename, not a full path, so PHP looks in the extension directory of whatever version is currently running. After switching to 8.4, it automatically loads the 8.4 builds of these two, provided they're installed for 8.4.
There's another precondition here: this php.ini doesn't set its own extension directory with extension_dir. If it did, and it pointed at the 8.1 directory, 8.4 would try to load extensions compiled for 8.1 and fail. If you see extensions with a full path, or with a version number in the path (some encrypted-code loaders, for example), be especially careful: they'll almost certainly fail to load after a version change.
Besides the php.ini given with -c, PHP also scans each version's own additional config directory (such as /etc/php/8.4/fpm/conf.d/), and many extensions are actually loaded from there. So looking at php.ini alone isn't enough; you need to see which modules PHP actually loads.
First use diff to compare the two versions:
diff \
<(php-fpm8.1 -c /home/clp/services/php-fpm/fpm/php.ini -m 2>&1) \
<(php-fpm8.4 -c /home/clp/services/php-fpm/fpm/php.ini -m 2>&1)
My result showed only two differences:
< imap
> random
imap: PHP 8.4 moved it from core to PECL, so 8.4 lacks it. The backend manages servers and sites, so it's unlikely to need mail-receiving features; this difference is acceptable.random: a built-in module added in 8.2; having an extra one doesn't hurt.
But diff only shows where the two sides differ. If both versions produce the same warning, or neither loads a certain module, diff won't reveal it. So check the 8.4 side directly as well:
php-fpm8.4 -c /home/clp/services/php-fpm/fpm/php.ini -m 2>&1 \
| grep -Ei '^(redis|memcached)$|Warning|Unable to load'
You need to see both redis and memcached lines, with no Warning or Unable to load anywhere, before you can say the extensions the backend needs all load successfully on 8.4.
4. What can only be tested for real: code compatibility
Once everything above passes, the remaining unknown is whether the backend code itself has compatibility issues on 8.4, and that can only be tested by actually clicking through the pages. This is also why CloudPanel hasn't switched yet: they're responsible for every feature in every user's environment, so their testing cost is far higher than ours for changing one server.
Doing it: create the drop-in
Two things before you start: take a snapshot in your VPS provider's control panel, and keep an extra SSH window open so you have a way back if something goes wrong in this one.
systemctl edit opens an editor for writing the drop-in. If you'd rather paste a command, the following works the same way:
sudo mkdir -p /etc/systemd/system/clp-php-fpm.service.d
sudo tee /etc/systemd/system/clp-php-fpm.service.d/override.conf >/dev/null <<'EOF'
[Unit]
Description=The CLP PHP FastCGI Process Manager (override: PHP 8.4)
[Service]
ExecStart=
ExecStart=/usr/sbin/php-fpm8.4 -R -F -y /home/clp/services/php-fpm/fpm/php-fpm.conf -c /home/clp/services/php-fpm/fpm/php.ini
EOF
sudo systemctl daemon-reload
sudo systemctl restart clp-php-fpm
The Description line isn't required, but with it changed, systemctl status will show at a glance that this service has been modified, so you won't forget.
Check the result:
systemctl status clp-php-fpm --no-pager | head -5
sudo readlink -f /proc/$(systemctl show -p MainPID --value clp-php-fpm)/exe
What I saw:
● clp-php-fpm.service - The CLP PHP FastCGI Process Manager (override: PHP 8.4)
Loaded: loaded (/usr/lib/systemd/system/clp-php-fpm.service; enabled; preset: enabled)
Drop-In: /etc/systemd/system/clp-php-fpm.service.d
└─override.conf
Active: active (running) since ... ; 10ms ago
/usr/sbin/php-fpm8.4
The Drop-In section means systemd has picked up our config, and the last line means the service's main process is now the 8.4 binary. If (deleted) appears after the path, the process is still using the old, replaced binary; restart again. The service reaching active (running) also means the 8.4 binary correctly answered the Type=notify startup notification. Now run systemctl cat clp-php-fpm again and you'll see the original file and the drop-in printed one after the other: that's the “layering” described earlier.
Confirm it's running stably
Here's an easy way to be fooled: active (running) is followed by 10ms ago, meaning it had only just started.
The original service sets Restart=always and RestartSec=3, meaning it restarts automatically three seconds after dying. If the new version crashes right after starting and you happen to check the status just as it restarts, you'll still see active (running). So wait a few seconds and see whether it keeps restarting:
sleep 10
systemctl show clp-php-fpm -p NRestarts -p ActiveEnterTimestamp
# 用「正在跑的那個程序」的執行檔查版本
exe=$(sudo readlink -f /proc/$(systemctl show -p MainPID --value clp-php-fpm)/exe)
"$exe" -v | head -1
NRestarts=0 and an unchanged start time mean systemd didn't auto-restart it during the observation period. But that only shows “no problems during that window”; it doesn't prove long-term stability. Just check on it now and then over the next few days.
The version line deliberately looks up the binary from MainPID rather than just running php-fpm8.4 -v, because the latter only asks for the version of the file on disk and doesn't prove the service is actually using it.
Click through the backend
Open another window to watch for errors:
sudo journalctl -u clp-php-fpm -f
Then go into the backend through the SSH tunnel and click through the commonly used features: login, dashboard, site list, site settings (including the PHP settings page), file manager, database manager and user management.
Two areas are especially worth checking:
- File manager: it uses a separate pool within the backend's FPM. It was switched to 8.4 along with everything else, but it's worth actually opening a folder and viewing a file to make sure.
- Database manager (phpMyAdmin): the server information on the right of the home page shows the PHP version. Seeing 8.4.27 there confirms the backend and phpMyAdmin pages now run on 8.4.
Be aware of the scope of this check: the only thing changed was the clp-php-fpm service. If CloudPanel has scheduled jobs or command-line tools that call php8.1 directly, this change doesn't switch them. You can quickly look for anything else still using 8.1:
# 正在跑的程序
ps -eo pid,user,cmd | grep -v grep | grep 'php8\.1'
# 系統排程
sudo grep -rn 'php8\.1' /etc/cron* /var/spool/cron 2>/dev/null
Command-line tools and scheduled jobs don't handle web requests directly, so they're less relevant to how this vulnerability is exploited, but you should still know they weren't switched.
On my server, every backend page worked fine, and I confirmed the backend and phpMyAdmin were now on 8.4.27.
How to roll back if it breaks
If any page breaks, or the backend won't load at all, delete the drop-in you created:
sudo rm /etc/systemd/system/clp-php-fpm.service.d/override.conf
sudo systemctl daemon-reload
sudo systemctl restart clp-php-fpm
The service goes back to CloudPanel's original 8.1. That's also why I was willing to try this: the change lives entirely in one separate file, and not a single character of the original was touched.
You may see systemctl revert clp-php-fpm recommended elsewhere. It also reverts the change, but with a broader scope: it deletes all of the service's drop-ins under /etc/systemd/system/ and /run/systemd/system/, and if the service was masked, it unmasks it as well. If you've used systemctl cat to confirm the service has only the one override you created, revert is fine; if you're not sure, deleting just the file you created is the safer bet.
What I learned
This approach isn't specific to CloudPanel. Any time a vendor's service is tied to an old version, you can think it through the same way:
- First find out what it's actually running:
systemctl catto see how it's started, andMainPIDwithreadlinkto find the binary. - Separate the binary from the configuration: they're often independent, and swapping just one of them is worth trying.
- Change configuration with a drop-in; don't touch the vendor's original files.
- Check whatever can be checked before you start: arguments, config files, dependencies. And for each check, know what it proves and what it doesn't.
- Besides comparing differences, directly confirm that what you need is really there;
diffonly shows what differs. - When confirming the result, ask the running process, not just the file on disk.
- For whatever you can't verify, have a rollback ready, understand exactly what the rollback command touches, and then actually test.
- Don't draw conclusions from a single status check: wait a few seconds, look at the restart count, and check back occasionally afterwards.
References
- PHP Manual: FastCGI Process Manager (FPM)
- systemd.unit — Unit configuration (on drop-ins)
- systemctl (on revert)
- Feature request: upgrade the PHP version used by CloudPanel's own php-fpm - CloudPanel Issue #816
- Upcoming Critical PHP Security Release - CloudPanel Issue #823
- PHP2Shell: Critical PHP vulnerabilities patched, update now! - Help Net Security
Member discussion