Web Servers (Apache, Nginx, Caddy)

Mastering Apache Execution Models: The Ultimate Comprehensive Guide

By the Domain India teamPublished 9 min read
Knowledge base article
Contents (9 sections)

Apache's "execution model" is two decisions working together: how Apache itself handles connections (its Multi-Processing Module, or MPM) and how it runs your code, such as PHP, under which user. Those two choices decide how many visitors a server can handle, how much memory it needs and whether one site on the server can read another's files. This guide explains the options that matter in 2026, which ones to avoid, and what Domain India's shared servers use.

Key takeaways

On a server you run, use the event MPM with PHP-FPM through mod_proxy_fcgi, one FPM pool per site running as that site's user. That gives good concurrency, low memory use and user isolation. mod_php with prefork is the legacy setup; mod_ruid2 and mod_fastcgi are unmaintained. On Domain India shared hosting the server is set up for you: PHP runs per account through PHP-FPM, and you can't change the MPM or handler.

1. The two layers of an execution model

Connection handling (MPM)
Decides whether Apache uses one process per connection or threads, and how it treats idle keep-alive connections. Only one MPM can be active.
Code execution (handler)
Decides where PHP, Python or other code runs: inside Apache, in a separate process started per request, or in a persistent pool that Apache forwards requests to. It also decides which user the code runs as.

A third layer often sits in front: a reverse proxy such as nginx that accepts connections and passes them to Apache. It changes the picture, because Apache then sees fewer, shorter connections.

2. The three MPMs

MPMHow it worksUse it when
preforkOne single-threaded process per connectionYou must run mod_php or another module that isn't thread-safe
workerSeveral processes, each with many threadsRarely today; event does the same job better
eventLike worker, but idle keep-alive connections are handed to a listener threadAlmost always, with PHP-FPM or a proxied application

Check which MPM is active with apachectl -V | grep MPM (or httpd -V on AlmaLinux and Rocky Linux). On Ubuntu and Debian, switch with a2dismod mpm_prefork and a2enmod mpm_event; on AlmaLinux and Rocky Linux, edit /etc/httpd/conf.modules.d/00-mpm.conf. HTTP/2 through mod_http2 needs event or worker.

The key setting is MaxRequestWorkers: the number of requests Apache serves at once. Size it to your RAM, together with your PHP-FPM pools, so the server never starts swapping. Our guide to tuning Apache and Nginx has starting values.

3. How Apache runs PHP

HandlerWhere PHP runsRuns asStatus in 2026
mod_phpInside every Apache processApache's userLegacy; forces prefork, no per-site isolation
CGI with suEXECA new process for every requestThe site's userWorks, but slow under load
mod_fcgidPersistent processes started by ApacheThe site's user, with suEXECMaintained; used on some older panel setups
PHP-FPM with mod_proxy_fcgiA separate pool of PHP workersThe pool's user, one pool per siteCurrent standard
mod_lsapiCloudLinux's handlerThe site's userAn option on CloudLinux servers

Why PHP-FPM won. PHP runs outside Apache, so Apache can use the event MPM. Each site gets its own pool running as its own user, which isolates sites from each other. Workers stay alive between requests, so OPcache works well. And you can tune each pool's worker count, memory and timeouts separately.

A minimal virtual host that hands PHP to an FPM pool:

apache
<VirtualHost *:443>
    ServerName example.in
    DocumentRoot /var/www/example.in/public

    <FilesMatch "\.php$">
        SetHandler "proxy:unix:/run/php-fpm/example.in.sock|fcgi://localhost"
    </FilesMatch>
</VirtualHost>

And the matching pool, running as the site's own user:

ini
[example.in]
user = example
group = example
listen = /run/php-fpm/example.in.sock
listen.owner = apache
listen.group = apache
pm = ondemand
pm.max_children = 10
pm.process_idle_timeout = 30s
request_terminate_timeout = 120s

The socket path and the web server's user (apache on AlmaLinux and Rocky Linux, www-data on Ubuntu and Debian) vary by distribution; match them to your system. With PHP-FPM, PHP settings go in the pool file, php.ini or .user.ini. A php_value line in .htaccess only works with mod_php and causes a 500 error otherwise.

4. Privilege separation: running code as the right user

On a server with several sites or users, code from one site must not be able to read another's files. The options:

  • PHP-FPM pools per user. The modern answer: each pool runs as its site's user, and file permissions do the rest.
  • suEXEC. Runs CGI and FastCGI programs as the owner of the virtual host. Still maintained and used with CGI and mod_fcgid.
  • mod_ruid2. Switched Apache's own user per request. It is unmaintained and was never compatible with every module; don't use it on a new server.
  • mpm-itk. Runs each virtual host's Apache processes as a different user. It works, but needs prefork and uses a lot of memory.

On shared hosting, providers add operating-system isolation too. CloudLinux, for example, puts each account in its own virtual file system and enforces per-account CPU, memory and process limits.

5. Other languages: proxy models

For applications that run their own server process, Apache acts as a reverse proxy:

  • Node.js, Python (Gunicorn or Uvicorn), Go, Ruby (Puma): run the app on a local port or socket and forward to it with mod_proxy_http (ProxyPass / http://127.0.0.1:3000/).
  • WebSockets: mod_proxy_http handles them on Apache 2.4.47 and later; older setups needed mod_proxy_wstunnel.
  • Python inside Apache: mod_wsgi is still maintained and works, but a separate Gunicorn or Uvicorn process behind a proxy is more common.
  • Java: use mod_proxy_http to Tomcat's HTTP connector; mod_jk still exists but is rarely needed for new setups.
  • Phusion Passenger: an application server that plugs into Apache and runs Node.js, Python and Ruby apps for you.

mod_fastcgi, which older guides mention, has been abandoned for years. Use mod_proxy_fcgi or mod_fcgid instead.

6. Troubleshooting common problems

  • High memory, swapping. Usually prefork with mod_php, or too many PHP-FPM workers for the RAM. Move to event with PHP-FPM and size MaxRequestWorkers and pm.max_children together.
  • 503 or "server reached MaxRequestWorkers". All workers are busy. Check for slow PHP requests in the FPM slow log before raising the limit.
  • Permission denied on files. The PHP pool's user can't read the files. Check owners and permissions, not just the Apache user.
  • 502 or 504 from a proxy. The backend is down or slower than the proxy's timeout. Check the application's own log first.
  • After a change, nothing works. Run apachectl configtest before every reload, and read the error log (/var/log/httpd/error_log or /var/log/apache2/error.log).

7. What Domain India shared hosting uses

Measured on our servers on 24 September 2026:

ServerWeb serverHow PHP runs
cPanel shared hostingApache with nginx in frontPHP-FPM pool per domain for most sites, CGI with suEXEC for the rest
DirectAdmin shared hostingApache with the event MPMPHP-FPM

Both servers run CloudLinux with per-account limits, and neither runs PHP as an Apache module. What this means for you:

  • You choose your PHP version and settings in your control panel, but not the MPM or handler; see how to change your PHP version.
  • .htaccess and mod_rewrite work, but php_value and php_flag lines in .htaccess cause a 500 error. Use the MultiPHP INI Editor or .user.ini instead.
  • On cPanel, requests that take longer than about 90 seconds end in a 504 from the nginx proxy, whatever max_execution_time says. See resolving gateway errors.
  • To see which handler your domain uses, see PHP-FPM in cPanel.

8. Where Domain India fits

If you want a server where the execution model is already chosen and maintained, shared hosting gives you that. If you want to choose the MPM, handler and pool sizes yourself, a VPS is self-managed with full root access; cPanel is not offered on a VPS. The cards show Domain India list prices on 19 September 2026, excluding 18% GST.

cPanel Starter
₹125/mo + GST
  • 25 GB NVMe SSD Storage
  • 50 GB Monthly Bandwidth
  • 1 Website
  • 10 Email Accounts
See plan details
VPS Starter
₹552.65/mo + GST
  • 1 vCPU
  • 2 GB DDR4 RAM
  • 64 GB NVMe SSD Storage
  • 2 TB Monthly Bandwidth
See plan details

Frequently asked questions

Which Apache MPM should I use?

Use the event MPM on almost every modern server, with PHP running in PHP-FPM. Prefork is only needed if you must run mod_php or another module that isn't thread-safe.

Is mod_php still a good choice?

Not for new servers. mod_php loads PHP into every Apache process, which forces the prefork MPM, uses more memory and runs every site as the same user. PHP-FPM with mod_proxy_fcgi is the current standard.

What is the difference between suEXEC and PHP-FPM?

suEXEC makes Apache run CGI and FastCGI programs as the site owner's user. PHP-FPM runs PHP in separate pools, each configured with its own user. Both isolate sites; PHP-FPM is faster because its workers stay running between requests.

Should I use mod_ruid2?

No. mod_ruid2 is no longer maintained and conflicts with some modules. Use a PHP-FPM pool per user instead.

Can I change the Apache MPM or PHP handler on Domain India shared hosting?

No. These are server-wide settings managed by Domain India. You can change your PHP version and PHP settings in your control panel. For full control, use a VPS.

Why does php_value in .htaccess give a 500 error?

php_value and php_flag only work when PHP runs as an Apache module. With PHP-FPM or CGI, as on Domain India shared hosting, put settings in .user.ini or the control panel's PHP settings instead.

Ready to choose? Compare cPanel hosting and VPS plans, or open a support ticket if your site needs a PHP setting you can't change yourself.

Not sure which hosting fits your application?

Tell us what your site runs and how busy it is, and our support team will recommend shared hosting or a VPS.

Ask our team

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app