Both stacks run Linux, MySQL or MariaDB, and PHP. The difference is the web server: Apache in LAMP, Nginx in LEMP. Both are mature, fast and well supported, and the right choice depends on your applications, your team’s familiarity, and whether you need .htaccess.
At a glance
| LAMP (Apache) | LEMP (Nginx) | |
|---|---|---|
| Architecture | Process/thread-based MPMs (event MPM recommended) | Event-driven, asynchronous |
| PHP handling | PHP-FPM via proxy_fcgi (modern), or mod_php (legacy) |
PHP-FPM via FastCGI |
| Static files and many connections | Good (with event MPM) | Excellent, low memory |
.htaccess per-directory config |
Yes | No (all config in server blocks) |
| Configuration style | Familiar, many modules | Concise, reverse-proxy friendly |
| Shared hosting / control panels | Very common | Common (often Nginx in front of Apache) |
| Reverse proxy and load balancing | Capable (mod_proxy) | A core strength |
Performance
With modern setups (Apache event MPM + PHP-FPM, versus Nginx + PHP-FPM), PHP execution speed is the same: PHP-FPM does the work. The differences:
- Nginx uses less memory per connection, and excels at static files, many concurrent or slow clients (keep-alive, mobile), and acting as a reverse proxy and cache.
- Apache with the old prefork + mod_php combination uses much more memory. If you choose Apache, use event MPM + PHP-FPM. See Apache MPM event with PHP-FPM.
For most sites, page caching and database tuning matter far more than the web server choice. See WordPress TTFB.
.htaccess: the deciding factor for many
Apache reads .htaccess files in each directory. Applications and plugins (WordPress security and caching plugins, some CMSs) write rules there, so non-admin users can change behaviour without server access.
Nginx has no equivalent. Rewrites and rules go in the server block, which is faster (no per-request file lookups), but requires server access to change. Many popular apps document their Nginx rules (WordPress, Laravel, Nextcloud). See Apache .htaccess guide and the ideal Nginx config for WordPress.
Which to choose
| Situation | Pick |
|---|---|
| New VPS for WordPress, Laravel or a custom PHP app | LEMP |
App or plugins that rely on .htaccess rules |
LAMP |
Control panels (cPanel) or clients editing .htaccess |
LAMP (or Nginx in front of Apache) |
| Many sites with reverse proxying, Node/Python apps too | LEMP |
| Team already knows Apache well | LAMP is perfectly fine |
Best of both: Nginx in front of Apache
Some setups use Nginx as a reverse proxy (TLS, static files, caching) with Apache behind it for PHP and .htaccess compatibility. Control panels often do this. It works well, but means two servers to configure. See Apache reverse proxy and Nginx reverse proxy.
OpenLiteSpeed: a third option
OpenLiteSpeed reads Apache-style rewrite rules, has built-in page caching (with the LiteSpeed Cache plugin for WordPress), and an admin web UI. See install OpenLiteSpeed.
Switching between them
Moving from LAMP to LEMP means translating .htaccess rules to Nginx config (redirects, rewrites, access rules), and switching PHP to FPM if you used mod_php. Test on staging first, since rewrite differences are the usual source of 404s. See WordPress permalinks 404.
Install guides
- LEMP: install a LEMP stack on Ubuntu.
- LAMP: install a LAMP stack.
Quick reference
| Question | Answer |
|---|---|
| Faster PHP? | Same (PHP-FPM) |
| Lower memory, static files, proxying? | Nginx |
| Need .htaccess? | Apache |
| Apache setup | Event MPM + PHP-FPM |
| Both | Nginx in front of Apache |
Related: Apache performance tuning and WordPress VPS hosting.