If your DirectAdmin server feels sluggish under moderate load, PHP-FPM (FastCGI Process Manager) is one of the most impactful changes you can make. PHP-FPM replaces the older FastCGI and mod_php execution modes with a dedicated process manager that handles PHP requests more efficiently, reduces memory fragmentation, and gives you per-user resource controls that standard FastCGI simply doesn't support.
This guide walks through enabling PHP-FPM on DirectAdmin, configuring per-user pools, setting up isolated PHP-FPM jails for multi-tenant security, and diagnosing performance problems with FPM's built-in slow log.
What Is PHP-FPM and Why Does It Matter for DirectAdmin Servers?
PHP execution in web servers has evolved through several modes, each with different performance and isolation characteristics:
- mod_php — PHP runs as an Apache module. Simple but memory-heavy; PHP loads even for static file requests. No user isolation.
- FastCGI (suPHP/CGI) — PHP runs as a separate process, improving isolation but spawning a new process per request. High overhead under load.
- PHP-FPM — PHP runs as a pool of pre-forked worker processes. Requests are handled by existing workers (no process spawn overhead), memory is shared across requests in the pool, and each user or domain can have a separate pool with dedicated resource limits.
For hosting servers with multiple accounts, PHP-FPM delivers three critical advantages: lower per-request CPU overhead, memory pooling that prevents individual accounts from consuming all server RAM, and the ability to run each user's PHP under their own Unix user ID (preventing cross-account file access).
💡 None of these worked? Skip the guesswork.
Get Expert Help →Step 1: Enable PHP-FPM Mode in DirectAdmin
DirectAdmin uses its own build system (CustomBuild 2.0) to compile and configure PHP. Enabling PHP-FPM requires two steps: setting the PHP execution mode and rebuilding the configuration files.
cd /usr/local/directadmin/custombuild
./build set php1_mode php-fpm
If you run multiple PHP versions (e.g., PHP 7.4 and PHP 8.2), set the mode for each:
./build set php1_mode php-fpm
./build set php2_mode php-fpm
./build php
This step compiles PHP with FPM support. Depending on your server specs, this takes 5-20 minutes. Do not interrupt the process.
./build rewrite_confs
This regenerates Apache/Nginx virtual host configuration files to use PHP-FPM sockets instead of the previous execution mode.
systemctl restart directadmin
systemctl restart httpd # or: systemctl restart apache2
ps aux | grep php-fpm
systemctl status php-fpm8.2 # adjust version as needed
You should see multiple PHP-FPM worker processes. The master process runs as root; worker processes run as individual user accounts.
cd /usr/local/directadmin/custombuild
./build set isolated_fpm 1
./build rewrite_confs
After enabling, check a user's pool config for the chroot directive:
grep -i chroot /etc/php-fpm.d/username.conf
The output should show: chroot = /home/username
Inside a chroot jail, PHP's open_basedir and include paths must be relative to the jail root. If applications break after enabling isolated FPM, check that they aren't loading files from outside the user's home directory (e.g., from /usr/share/ or /etc/).
Edit the user's pool config file (/etc/php-fpm.d/username.conf) and add:
slowlog = /var/log/php-fpm/username-slow.log
request_slowlog_timeout = 5s
This logs a stack trace for any PHP request taking more than 5 seconds.
systemctl reload php-fpm8.2
tail -f /var/log/php-fpm/username-slow.log
Each entry shows the script file, line number, and function call stack — making it straightforward to identify which database queries or file operations are causing slowdowns.
Common PHP-FPM Issues on DirectAdmin and How to Fix Them
PHP-FPM socket permission errors (502 Bad Gateway)
Apache cannot connect to the PHP-FPM socket. Check that the socket file's owner matches what Apache expects:
ls -la /var/run/php-fpm/username.sock
The socket should be owned by apache:apache (or www-data:www-data on Debian). If wrong, check the listen.owner and listen.group settings in the pool config and reload PHP-FPM.
PHP-FPM pool exhaustion (504 Gateway Timeout)
All workers in a pool are busy — new requests queue and eventually time out. Symptoms: sporadic 504 errors during traffic spikes. Fix: increase pm.max_children in the pool config, then reload PHP-FPM. Also check if a slow script is holding workers — enable slow log to identify it.
Memory consumption growing over time
PHP-FPM workers accumulate memory from leaked objects or unclosed resources. Prevent this by setting pm.max_requests = 500 — workers automatically restart after handling 500 requests, releasing any leaked memory.
For a deeper analysis of server performance bottlenecks beyond PHP, CloudHouse's server management team can audit your DirectAdmin configuration and implement systematic performance tuning across the full stack.
FAQs
What's the difference between PHP-FPM and FastCGI in DirectAdmin?
FastCGI (suPHP/CGI mode) spawns a new PHP process for each request — high overhead under load. PHP-FPM maintains a pool of pre-forked worker processes that handle requests without spawning new processes. The result is lower latency, better memory efficiency, and per-user resource limits that FastCGI cannot provide.
How do I set different PHP versions per domain in DirectAdmin with PHP-FPM?
DirectAdmin supports multiple PHP versions simultaneously. In WHM-equivalent DirectAdmin admin panel, go to Admin Panel > PHP Manager, assign different PHP versions per user or domain. Each version runs as a separate PHP-FPM pool. Ensure both PHP versions are compiled with FPM mode enabled: ./build set php1_mode php-fpm && ./build set php2_mode php-fpm && ./build php.
How much RAM does PHP-FPM use per worker process?
A typical PHP worker running WordPress uses 40-80 MB RAM. PHP workers running Magento or large Laravel applications can use 100-200 MB each. Check actual usage on your server: ps aux | grep php-fpm | awk '{print $6}' (output in KB). Use this to calculate safe pm.max_children values without overcommitting RAM.
Can I apply PHP-FPM only to specific users, not the whole server?
DirectAdmin's build system applies PHP-FPM server-wide. You cannot mix PHP-FPM and FastCGI per user in the same installation. However, you can control per-user pool sizes — set low-traffic users to pm = ondemand with pm.max_children = 3 so they use minimal resources, while high-traffic users get larger pools with pm = dynamic.
My PHP-FPM was working but now throws 502 errors after a DirectAdmin update. What happened?
DirectAdmin updates via CustomBuild can regenerate configuration files, sometimes overwriting custom pool configs or resetting PHP execution mode. After any DirectAdmin or PHP update, verify: (1) grep php_mode /usr/local/directadmin/custombuild/options.conf still shows php-fpm. (2) Socket paths in virtual host configs still match the FPM pool configs. Run ./build rewrite_confs to regenerate configs after updates.
