
September 08, 2026
11 min read
By Kokil Thapa | Last reviewed: September 2026
Choosing between Nginx vs Apache for PHP Sites in 2026 still trips up teams shipping Laravel, WordPress, or custom PHP on Ubuntu VPS boxes. Both servers terminate HTTP and talk to PHP-FPM, but they differ in concurrency, rewrite rules, and operational cost. I've deployed both on production Linux servers for legal portals, eCommerce stores, and booking apps since 2010. This guide compares real configs, not marketing slides.
What Is the Core Difference Between Nginx and Apache for PHP?
Apache and Nginx are both web servers. They accept HTTP requests and return responses. The split appears in architecture and how PHP gets executed.
Apache traditionally used mod_php, embedding PHP inside each worker process. That model is largely retired. Modern stacks use PHP-FPM as a separate pool regardless of web server. Nginx never ran embedded PHP — it always proxied to FPM via FastCGI.
Apache uses a process-or-thread model with optional MPM modules. Nginx uses an event-driven, non-blocking worker model. Under heavy concurrent load, Nginx typically holds memory more steadily. Apache with mod_php removed and PHP-FPM can still perform well when tuned correctly.
Process Model in Plain Terms
Apache spawns workers based on your MPM choice. prefork uses one process per connection. event handles keep-alive more efficiently. Nginx workers handle thousands of idle connections in one process. For a brochure site with low traffic, the difference barely registers. For a booking portal during peak season, it matters.
How Does Each Web Server Run PHP in 2026?
PHP 8.5 is the current anchor release. Laravel 13 requires PHP 8.3 minimum. Laravel 12 runs on PHP 8.2. Symfony 8.1 needs PHP 8.4.1. Your web server choice does not change PHP version requirements — FPM pool config does.
The correct production pattern for both servers:
- Install PHP-FPM (
php8.5-fpmorphp8.3-fpmdepending on app requirements). - Configure a pool in
/etc/php/8.5/fpm/pool.d/www.conf. - Point Nginx or Apache at the Unix socket or TCP port.
- Enable OPcache in production and reload FPM after deploys.
Nginx FastCGI Block for Laravel
server {
listen 443 ssl http2;
server_name example.com;
root /var/www/app/current/public;
index index.php;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~ \.php$ {
fastcgi_pass unix:/run/php/php8.5-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
} This pattern mirrors what I use on Laravel VPS deployments. The try_files directive sends clean URLs to index.php. That replaces Apache's FallbackResource or rewrite rules.
Apache VirtualHost with PHP-FPM
<VirtualHost *:443>
ServerName example.com
DocumentRoot /var/www/app/current/public
<FilesMatch \.php$>
SetHandler "proxy:unix:/run/php/php8.5-fpm.sock|fcgi://localhost"
</FilesMatch>
<Directory /var/www/app/current/public>
AllowOverride None
Require all granted
</Directory>
</VirtualHost> Enable proxy_fcgi and setenvif modules. Rewrite rules live in the vhost or a central include file — not scattered .htaccess files when you control the server.
Which Server Handles Rewrites and .htaccess Better?
Apache's killer feature is per-directory overrides via .htaccess. WordPress, WooCommerce 11.1, and many shared hosts depend on it. Drop a file in wp-content/uploads or a plugin folder and Apache reads it without a reload.
Nginx ignores .htaccess entirely. Every rewrite must live in server config. That is a feature on VPS boxes you control — one source of truth, no surprise rules from uploaded plugins. It is a blocker on cheap shared hosting where you cannot edit vhosts.
For a WordPress site on managed VPS, I convert .htaccess rules to Nginx try_files and explicit rewrites once. After that, deployments are cleaner. On shared cPanel hosting, Apache is often the only practical option.
WordPress Permalink Equivalent on Nginx
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff2)$ {
expires 30d;
access_log off;
} Static asset caching blocks like this are why WordPress on Nginx often scores better Core Web Vitals. Apache can match this with mod_expires, but Nginx static serving is simpler to reason about.
How Do Nginx and Apache Compare on Performance and Resources?
Benchmarks vary by workload. Synthetic "hello world" tests favour Nginx. Real PHP apps spend most time in FPM and MySQL — not the web server. Still, differences show up under load.
| Criteria | Nginx | Apache |
|---|---|---|
| Concurrent connections | Strong — event-driven workers | Good with event MPM + PHP-FPM |
| Static file serving | Very fast, low memory | Good; often proxied to Nginx anyway |
| .htaccess support | None — vhost only | Native per-directory overrides |
| PHP execution | FastCGI to PHP-FPM | FastCGI via proxy_fcgi |
| Config reload | nginx -t && systemctl reload nginx | apachectl configtest && systemctl reload apache2 |
| Module ecosystem | Focused — reverse proxy, caching | Huge — auth, LDAP, legacy modules |
| Typical stack name | LEMP (Linux, Nginx, MySQL, PHP) | LAMP (Linux, Apache, MySQL, PHP) |
| Shared hosting fit | Rare on budget hosts | Default on most cPanel plans |
| Reverse proxy role | Industry default front-end | Usually origin, not edge |
On a 2 GB VPS running a Laravel booking app, I've seen Nginx idle at 30–50 MB RAM while Apache with similar traffic sits at 80–120 MB. Those numbers shift with modules loaded. Neither gap justifies migration alone — user-facing latency from slow queries hurts more.
For FPM pool tuning, start with pm.max_children based on available RAM. A common formula: divide free memory by average PHP process size (~40–60 MB). Web server choice does not replace this math.
When Should You Migrate From Apache to Nginx?
Migration makes sense when you own the server, traffic is climbing, and rewrite rules are documented. It does not make sense as a weekend side project with 200 undocumented .htaccess files.
I've walked through Apache-to-Nginx migrations on sister legal-tech sites sharing a Deployer 7 pipeline. The app code rarely changes. The work is config translation, SSL cert paths, and FPM socket verification.
Pre-Migration Checklist
- Export all Apache vhost and rewrite rules — grep for
RewriteRuleacross the docroot. - Run
nginx -ton staging before DNS cutover. - Confirm PHP-FPM socket path matches between old and new configs.
- Test file uploads, payment callbacks, and webhook endpoints — they often use custom headers.
- Reload FPM after deploy so OPcache picks up new code.
- Keep Apache config backed up for quick rollback.
A hybrid pattern works well at scale: Nginx as reverse proxy and static file server, Apache as origin for legacy apps. See reverse proxy setup with Nginx for the upstream block. I've used this when a client could not rewrite all Apache rules immediately.
Ubuntu Server Baseline for Either Stack
Whether you pick LEMP or LAMP, start from a hardened base. My usual path follows Ubuntu server setup for PHP apps and the LEMP stack guide. Install UFW, fail2ban, and unattended security updates before exposing port 443.
sudo apt update
sudo apt install nginx php8.5-fpm php8.5-mysql mysql-server
sudo apt install certbot python3-certbot-nginx
sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw enable Swap Apache for apache2 and python3-certbot-apache if you go LAMP. PHP-FPM package names stay the same. Redis 8.10 for session or cache storage is optional but common on Laravel apps I've maintained.
What About Security, Logging, and DevOps in 2026?
Both servers support TLS 1.2+, HTTP/2, and modern cipher suites via Let's Encrypt. Nginx config for security headers is straightforward:
add_header X-Frame-Options "SAMEORIGIN" always;
add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always; Apache equivalents use Header always set inside vhosts. Neither server replaces WAF rules or application-level auth. For client portals with document uploads — like platforms in my legal-tech portfolio — validate MIME types in PHP regardless of web server.
Logging differs slightly. Nginx access logs use a compact default format. Apache's combined log format is familiar to older analytics tools. Ship both to a central store if you run multiple VPS instances. A JSON log formatter helps when parsing structured access logs locally.
Official references stay current: the Nginx documentation, the Apache 2.4 manual, and the PHP-FPM install guide on php.net. Cross-check pool directives there before changing production values.
Hosting Cost Context for Nepal Teams
A managed VPS with Nginx runs Rs 1,500–3,500/month (~USD 11–26) on local and regional providers. Shared Apache hosting starts lower — Rs 500–1,200/month (~USD 4–9). The server choice affects ops time more than the invoice. A misconfigured FPM pool costs more in downtime than the monthly host fee. Factor that into hosting decisions with your agency or in-house team.
For ongoing tuning after launch, support and maintenance covers FPM reloads, cert renewals, and migration rollbacks. Speed optimisation work often starts with static caching on Nginx and query fixes in the app — not swapping web servers for its own sake.
Key Takeaways
- Run PHP-FPM with either Nginx or Apache — do not use mod_php on production systems in 2026.
- Choose Nginx for new VPS deployments, high concurrency, and clean vhost-managed rewrites.
- Stay on Apache when shared hosting, .htaccess per directory, or legacy modules lock you in.
- Tune PHP-FPM pools and OPcache before blaming the web server for slow responses.
- Hybrid Nginx-front, Apache-origin setups let you migrate incrementally without a big-bang cutover.
- Test payment webhooks, file uploads, and SSL reload paths on staging before DNS changes.
People Also Ask
Is Nginx faster than Apache for PHP?
For static files and concurrent connections, Nginx usually wins. For typical PHP page generation, both servers spend most request time in PHP-FPM and the database. Optimise queries and FPM pools first. Then compare web server memory under your actual traffic profile.
Can Apache run PHP-FPM like Nginx?
Yes. Use proxy_fcgi with a Unix socket or TCP upstream pointing at PHP-FPM. This is the standard Apache pattern for PHP 8.x in 2026. It replaces mod_php entirely and matches Nginx's separation of concerns.
Does Laravel require Nginx?
No. Laravel 13 runs on either server as long as PHP 8.3+ and URL rewriting reach public/index.php. Most new Laravel deployments use Nginx because of simpler static handling and lower memory on small VPS boxes. Apache works fine with correct vhost config.
Should WordPress use Nginx or Apache?
WordPress 7.1 runs on both. Shared WordPress hosting almost always means Apache with .htaccess. On a VPS you control, Nginx with converted rewrite rules delivers faster static asset caching. WooCommerce stores benefit from the same pattern — FPM tuning matters more than the web server brand.
Pick the Server That Matches Your Ops Reality
Nginx vs Apache for PHP Sites in 2026 is not a purity contest. Nginx fits new VPS projects, Laravel and API backends, and teams that want centralised config. Apache fits shared hosting, WordPress shops with plugin-driven .htaccess rules, and environments where legacy modules still run billing or auth. Both pair with PHP-FPM 8.3+ and MySQL 9.7 or PostgreSQL 18. Measure your app, document your rewrites, and choose the stack your team can maintain after launch.
Need help choosing or migrating? See the web development services page or review shipped work in the portfolio. For a direct conversation about your stack, contact us. Read more on the blog, browse all services, or learn about my background on about me.
Frequently Asked Questions
0 Comments
Leave a comment
Your email is not published. Comments appear once they have been read. Sign in to have your details filled in.

