PHP can work either as a CLI scrip or a as module for a web server.
There are several web server options available for using PHP.
- Apache HTTP Server: Apache is one of the most widely used web servers and supports PHP through the use of the
mod_phpmodule. - Nginx: Nginx is a high-performance web server known for its scalability and efficient handling of
concurrent connections. It can be used with PHP via
FastCGIorPHP-FPM(FastCGI Process Manager). - IIS: IIS is the web server provided by Microsoft for Windows-based servers. It can run PHP applications
using the PHP module or
PHP-FPM. - Lighttpd: Lighttpd is a lightweight web server designed for speed and efficiency. It can be used with PHP through
FastCGI.
Apache vs Nginx in practice
Further reading: open_in_new Apache vs Nginx: a practical view .
Summary: Nginx handles thousands of concurrent connections easily, stays lightweight, and excels at serving static files.
Apache
- Flexibility — dynamically loadable modules (many language interpreters).
- MPM modules for multiprocessing:
mpm_preforkmpm_workermpm_event
Nginx
- Handles on the order of 10,000 concurrent connections.
- Lightweight and very strong for static content.
- Designed to hand off dynamic requests to other software (PHP-FPM, uWSGI, etc.).
Administrators often pick Nginx for efficient resource use and responsiveness under load, and because it works well as both a web server and a reverse proxy.
To run PHP behind Nginx, use one of: HTTP, FastCGI, SCGI, uWSGI, or memcache.
Further reading: open_in_new Nginx, PHP-FPM — what is it?
Andrew Dorokhov