FastCGI or Apache: Choosing a Server for OpenCart
OpenCart is a PHP application, and its performance depends heavily on how the PHP code is processed and how the web server is configured. The main approaches are:
-
Apache + mod_php is the classic option: PHP runs as a module of Apache itself.
-
Apache / Nginx + FastCGI + PHP-FPM — PHP runs in a separate process pool (PHP-FPM), and the web server only proxies requests to it via FastCGI.
???? What is Apache and what is PHP-FPM
???? Apache
Apache is one of the oldest and most widely used web servers. It:
-
Easy to set up and compatible with a wide range of software.
-
Supports
.htaccessfiles, which OpenCart uses for routing and SEO rules.
Disadvantages of Apache:
-
Each request can launch a separate process or thread, which can be very resource-intensive under high loads.
-
Static and dynamic processing are performed in a single process, which reduces scalability.
???? FastCGI and PHP-FPM
FastCGI is a protocol that allows a web server to delegate PHP processing to other processes.
PHP-FPM (FastCGI Process Manager) is a manager of these PHP processes that:
-
Supports a pool of worker processes.
-
Allows you to flexibly configure the number of processes.
-
Better memory management and process lifetime.
Advantages of FastCGI/PHP-FPM:
✔ High performance under load
✔ Flexible workflow management
✔ Optimization with OPcache
✔ Can be used with both Nginx and Apache
Flaws:
❌ More complex setup, especially when migrating from an existing Apache environment
❌ When used without an external server (e.g. Nginx), fine-grained configuration is required
???? OpenCart: Application Features
Practical experience shows that:
-
Apache works well out of the box by default , no additional configuration is required.
-
PHP-FPM usually provides better response under high load (large number of concurrent users).
-
Many people use Nginx + PHP-FPM because Nginx serves static files faster and handles a large number of connections better, while PHP-FPM only handles PHP requests.
-
However, when switching to FastCGI, you need to rewrite the rules from
.htaccess(which requires additional settings for OpenCart).
???? Comparison Chart: Apache vs. FastCGI (PHP-FPM)
| Criterion | Apache + mod_php / Apache + PHP-FPM | FastCGI + PHP-FPM |
|---|---|---|
| Easy to set up | ⭐⭐⭐⭐⭐ (easy) | ⭐⭐⭐ (requires skills) |
| .htaccess support | ⭐⭐⭐⭐⭐ | ⭐☆☆☆☆ (without Apache, you need to convert the rules) |
| Performance under load | ⭐⭐⭐ | ⭐⭐⭐⭐ |
| Scalability | ⭐⭐ | ⭐⭐⭐⭐ |
| RAM usage | ⭐⭐ (more) | ⭐⭐⭐ (more optimal) |
| Static file performance | ⭐⭐ (without accelerator) | ⭐⭐⭐⭐ (if with Nginx) |
| Configuring a PHP process pool | ⭐⭐ | ⭐⭐⭐⭐ |
| Compatibility with OpenCart without changes | ⭐⭐⭐⭐ | ⭐⭐⭐ (sometimes changes are needed) |
| OS/server qualification required | ⭐⭐ | ⭐⭐⭐ |
???? When to choose what
???? Apache + mod_php
???? When you want minimal settings
???? Small/medium project
???? No requirement to serve hundreds of simultaneous visitors
???? A good choice for launching a store on standard hosting.
???? FastCGI + PHP-FPM (often with Nginx)
???? When performance and scalability matter
???? You have a powerful VPS or dedicated server
???? High traffic and high load
???? Willingness to adapt server configurations
???? This option is more often used for manufacturing online stores with high traffic .
???? Result
If you value maximum speed and stability under high load , then the FastCGI + PHP-FPM combination (usually with Nginx) is the best choice. But if you want simplicity and compatibility , classic Apache remains a good option for a long time.
Excellent ????
I'll give practical, minimal examples of configurations that are actually used for OpenCart in production.
I will show 2 options :
-
Apache + PHP-FPM (recommended over mod_php)
-
Nginx + PHP-FPM (maximum performance)
All examples are for OpenCart 3.x , PHP 7.4 / 8.x.
???? Option 1: Apache + PHP-FPM
???? Architecture
Apache → FastCGI → PHP-FPM
✔ Pros
-
.htaccessworks -
Minimal changes for OpenCart
-
Easier migration
1️⃣ Install Apache modules
a2enmod proxya2enmod proxy_fcgia2enmod rewritea2enmod headerssystemctl restart apache2
2️⃣ Apache VirtualHost for OpenCart
/etc/apache2/sites-available/opencart.conf
ServerName example.com ServerAlias www.example.com DocumentRoot /var/www/opencart AllowOverride All Require all granted SetHandler "proxy:unix:/run/php/php8.1-fpm.sock|fcgi://localhost" ErrorLog ${APACHE_LOG_DIR}/opencart_error.log CustomLog ${APACHE_LOG_DIR}/opencart_access.log combined
Activate the site:
a2ensite opencartsystemctl reload apache2
3️⃣ PHP-FPM pool (optimal)
/etc/php/8.1/fpm/pool.d/ www.conf
pm = dynamicpm.max_children = 20pm.start_servers = 4pm.min_spare_servers = 2pm.max_spare_servers = 6php_admin_value[memory_limit] = 256Mphp_admin_value[max_execution_time] = 120php_admin_value[upload_max_filesize] = 64Mphp_admin_value[post_max_size] = 64M
Restart:
systemctl restart php8.1-fpm
4️⃣ .htaccess (OpenCart standard)
RewriteEngine OnRewriteBase /RewriteRule ^sitemap.xml index.php?route=extension/feed/google_sitemap [L]RewriteRule ^googlebase.xml index.php?route=extension/feed/google_base [L]RewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
???? Option 2: Nginx + PHP-FPM (recommended for high load)
???? Architecture
Nginx → FastCGI → PHP-FPM
✔ Pros
-
Maximum speed
-
Less RAM
-
Holds the load perfectly
❗ Minus
-
.htaccessdoes NOT work (rules need to be moved)
1️⃣ Nginx configuration for OpenCart
/etc/nginx/sites-available/opencart
server { listen 80; server_name example.com www.example.com; root /var/www/opencart; index index.php index.html; access_log /var/log/nginx/opencart.access.log; error_log /var/log/nginx/opencart.error.log; location / { try_files $uri $uri/ /index.php?_route_=$uri&$args; } location \.php$ { include fastcgi_params; fastcgi_pass unix:/run/php/php8.1-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_read_timeout 300; } location * \.(jpg|jpeg|png|gif|ico|css|js|woff2?)$ { expires 30d; access_log off; } location /\. { deny all; }}
Activate:
ln -s /etc/nginx/sites-available/opencart /etc/nginx/sites-enabled/nginx -tsystemctl reload nginx
2️⃣ PHP-FPM pool (same as above)
Works without changes .
3️⃣ Migrating OpenCart SEO rules to Nginx
location = /sitemap.xml { rewrite ^ /index.php?route=extension/feed/google_sitemap last;}location = /googlebase.xml { rewrite ^ /index.php?route=extension/feed/google_base last;}
???? What to choose in practice
| Situation | Recommendation |
|---|---|
| Shared hosting | Apache |
| VPS / server | Apache + PHP-FPM |
| High load | Nginx + PHP-FPM |
| Maximum speed | Nginx + PHP-FPM |
| Minimum settings | Apache |
???? My practical advice
-
Up to 1–5 thousand visitors/day → Apache + PHP-FPM
-
5–50,000 visitors/day → Nginx + PHP-FPM
-
Marketplace / B2B / API → Nginx + PHP-FPM + Redis
| Criterion | Apache + PHP-FPM | Nginx + PHP-FPM |
|---|---|---|
| Easy to launch | ⭐⭐⭐⭐⭐ | ⭐⭐⭐ |
| Speed | ⭐⭐⭐⭐ | ⭐⭐⭐⭐⭐ |
| How .htaccess works | ✅ | ❌ |
| Under load | Average | Great |
| Recommended for | VPS / shared | High-load stores |
Leave a Comment