Kokil Thapa - Professional Web Developer in Nepal
Freelancer Web Developer in Nepal with 15+ Years of Experience

Kokil Thapa is an experienced full-stack web developer focused on building fast, secure, and scalable web applications. He helps businesses and individuals create SEO-friendly, user-focused digital platforms designed for long-term growth.

Nginx vs Apache for PHP Sites in 2026

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.

PHP Request Flow: Nginx vs ApacheBrowserNginxEvent workersApacheMPM + modulesPHP-FPM 8.5FastCGI socketMySQL 9.7Query layerBoth servers proxy to PHP-FPM — never use mod_php in 2026
Nginx vs Apache for PHP sites: both terminate HTTP and forward dynamic requests to PHP-FPM over FastCGI

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:

  1. Install PHP-FPM (php8.5-fpm or php8.3-fpm depending on app requirements).
  2. Configure a pool in /etc/php/8.5/fpm/pool.d/www.conf.
  3. Point Nginx or Apache at the Unix socket or TCP port.
  4. 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.

Shared PHP-FPM LayerNginx vhost configApache vhost configPHP-FPM Poolpm = dynamic | OPcache onLaravel / WordPress AppWeb server choice affects routing — FPM tuning affects PHP speed
PHP-FPM sits below both Nginx and Apache — pool tuning matters more than web server brand for PHP execution

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.

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.

CriteriaNginxApache
Concurrent connectionsStrong — event-driven workersGood with event MPM + PHP-FPM
Static file servingVery fast, low memoryGood; often proxied to Nginx anyway
.htaccess supportNone — vhost onlyNative per-directory overrides
PHP executionFastCGI to PHP-FPMFastCGI via proxy_fcgi
Config reloadnginx -t && systemctl reload nginxapachectl configtest && systemctl reload apache2
Module ecosystemFocused — reverse proxy, cachingHuge — auth, LDAP, legacy modules
Typical stack nameLEMP (Linux, Nginx, MySQL, PHP)LAMP (Linux, Apache, MySQL, PHP)
Shared hosting fitRare on budget hostsDefault on most cPanel plans
Reverse proxy roleIndustry default front-endUsually 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.

Pick Nginx or Apache for PHPNew VPS you control?Yes → NginxNo → check hostShared cPanel?Apache defaultNeed .htaccess per folder?ApacheNginx + vhostHigh traffic Laravel? Nginx front + optional Apache originLegacy mod_rewrite only? Migrate rules before switchingBoth use PHP-FPM — never mod_php in production
Decision tree for Nginx vs Apache for PHP sites — hosting control and .htaccess dependency drive the choice

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 RewriteRule across the docroot.
  • Run nginx -t on 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.

Hybrid: Nginx Edge + Apache OriginClientsNginx EdgeSSL + static cacheStatic filesServed directlyApache OriginLegacy .htaccessPHP-FPM PoolShared backendIncremental migration path — Nginx handles TLS and assets firstUsed on production legal-tech and booking portals
Hybrid Nginx plus Apache setup — common migration path for PHP sites with legacy rewrite rules

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

Both accept HTTP requests and return responses, but their architecture differs. Apache uses a process-or-thread model with optional MPM modules like prefork or event. Nginx uses event-driven, non-blocking workers that handle thousands of idle connections in one process. For PHP, both modern stacks terminate HTTP and forward dynamic requests to PHP-FPM over FastCGI. Apache historically embedded PHP via mod_php, but that model is largely retired. Nginx never ran embedded PHP. Under heavy concurrent load on a booking portal during peak season, Nginx typically holds memory more steadily, though Apache with PHP-FPM can perform well when tuned correctly.

Nginx wins on static files and concurrent connections. Real PHP latency usually sits in FPM and MySQL, not the web server. Tune those first.

The correct production pattern for both is identical at the PHP layer: install PHP-FPM, 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, and reload FPM after deploys. PHP 8.5 is the current anchor release. Laravel 13 requires PHP 8.3 minimum, Laravel 12 runs on PHP 8.2, and Symfony 8.1 needs PHP 8.4.1. Your web server choice does not change PHP version requirements. Pool tuning matters more than whether you run LEMP or LAMP. Avoid mod_php on production systems entirely.

Yes. Apache uses proxy_fcgi with a Unix socket or TCP upstream to PHP-FPM, replacing mod_php in modern PHP 8.x stacks.

No. Laravel 13 needs PHP 8.3 plus clean URL rewriting to public/index.php. Both Nginx and Apache work with PHP-FPM configured correctly.

Apache's killer feature is per-directory overrides via .htaccess. WordPress 7.1, WooCommerce 11.1, and many shared hosts depend on it. Drop a file in wp-content/uploads and Apache reads it without a reload. Nginx ignores .htaccess entirely. Every rewrite must live in server config, which is cleaner on VPS boxes you control but a blocker on cheap shared hosting where you cannot edit vhosts. For WordPress on managed VPS, convert .htaccess rules to Nginx try_files and explicit rewrites once. On shared cPanel hosting, Apache is often the only practical option because you lack vhost access.

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 through explicit expires blocks on js, css, and image files. WooCommerce stores benefit from the same pattern. Static asset caching is 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. FPM tuning matters more than the web server brand for either setup.

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. Nginx handles concurrent connections strongly with event-driven workers. Apache is good with event MPM plus PHP-FPM. Nginx serves static files very fast with low memory. On a 2 GB VPS running a Laravel booking app, Nginx idle at 30 to 50 MB RAM while Apache with similar traffic sits at 80 to 120 MB. Neither gap justifies migration alone. Slow queries hurt user-facing latency more than web server choice.

Migration makes sense when you own the server, traffic is climbing, and rewrite rules are documented. It does not make sense as a weekend project with 200 undocumented .htaccess files. The app code rarely changes. The work is config translation, SSL cert paths, and FPM socket verification. Export all Apache vhost and rewrite rules, run nginx -t on staging before DNS cutover, confirm PHP-FPM socket paths match, test file uploads and payment callbacks, reload FPM after deploy for OPcache, and keep Apache config backed up for rollback. I've walked through this on sister legal-tech sites sharing a Deployer 7 pipeline.

A hybrid pattern works well at scale: Nginx as reverse proxy and static file server, Apache as origin for legacy apps. This is a common migration path for PHP sites with legacy rewrite rules you cannot centralise immediately. Nginx handles TLS termination, static assets, and high-concurrency front-end traffic. Apache continues serving dynamic PHP requests with existing mod_rewrite rules and modules. I've used this when a client could not rewrite all Apache rules immediately. It lets you migrate incrementally without a big-bang cutover. Once rewrites are documented and converted, you can drop Apache from the chain entirely.

No. Both Nginx and Apache should run PHP-FPM as a separate pool in production. Mod_php embeds PHP inside each Apache worker process, which is the traditional Apache model but largely retired for good reason. It couples web server memory to PHP process size and makes tuning harder under load. The correct pattern installs php8.5-fpm or php8.3-fpm depending on app requirements, configures the pool, and connects via FastCGI. Nginx always used this separation. Apache now matches it through proxy_fcgi with SetHandler pointing at the FPM Unix socket. This is standard for PHP 8.x in 2026.

A managed VPS with Nginx runs Rs 1,500 to 3,500 per month, roughly USD 11 to 26, on local and regional providers. Shared Apache hosting starts lower at Rs 500 to 1,200 per month, roughly USD 4 to 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 ongoing tuning, cert renewals, and migration rollbacks into hosting decisions with your agency or in-house team. Speed optimisation often starts with static caching on Nginx and query fixes in the app, not swapping web servers for its own sake.

Start from a hardened base regardless of stack choice. Install UFW, fail2ban, and unattended security updates before exposing port 443. For LEMP: apt install nginx, php8.5-fpm, php8.5-mysql, mysql-server, certbot with python3-certbot-nginx, then allow OpenSSH and Nginx Full through UFW. Swap nginx for apache2 and python3-certbot-apache if you go LAMP. PHP-FPM package names stay the same either way. Redis 8.10 for session or cache storage is optional but common on Laravel apps. My usual path follows Ubuntu server setup for PHP apps. Both stacks pair with MySQL 9.7 or PostgreSQL 18 depending on application needs.

Web server choice does not replace FPM pool math. Start with pm.max_children based on available RAM. A common formula: divide free memory by average PHP process size, roughly 40 to 60 MB per child. On a 2 GB VPS, getting this wrong causes 502 errors or memory exhaustion long before Nginx versus Apache becomes the bottleneck. Enable OPcache in production and reload FPM after deploys so new code loads. Cross-check pool directives in the official PHP-FPM install guide on php.net before changing production values. I've seen teams blame the web server for slow responses when the real fix was FPM pool sizing and query optimisation.

Both support TLS 1.2 plus, HTTP/2, and modern cipher suites via Let's Encrypt. Nginx security headers like X-Frame-Options, X-Content-Type-Options, and Referrer-Policy go in server blocks. Apache equivalents use Header always set inside vhosts. Neither server replaces WAF rules or application-level auth. For client portals with document uploads, validate MIME types in PHP regardless of web server. Logging differs slightly: Nginx access logs use a compact default format, while Apache combined log format is familiar to older analytics tools. Ship both to a central store if you run multiple VPS instances. Test SSL reload paths on staging before DNS changes.

Share this article

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.

Quick Contact Options
Choose how you want to connect me: