OpenCart remains one of the most popular e-commerce CMSs due to its simplicity, extensive extensions, and low entry threshold. However, a standard OpenCart installation on a typical VPS with out-of-the-box settings quickly reaches its performance limits. This is especially noticeable as the catalog grows, the number of orders increases, and payment systems and marketing integrations are added.

The main problem isn't with OpenCart itself, but with the server configuration. Apache with the mod_php module, default MySQL settings, and no caching are only suitable for small stores. With a load of 1,000 or more visitors per day, problems arise: long TTFB, increased page generation time, MySQL lockups, and increased memory consumption.

This article covers advanced server setup for OpenCart using an Nginx + PageSpeed + MySQL + PHP-FPM stack running Ubuntu 20.04/22.04 LTS. This article is designed for VPS or dedicated servers and assumes familiarity with the Linux command line and basic web server principles.

The goal of this guide is to show how to achieve a stable, scalable, and secure configuration suitable for production, with an emphasis on optimizing for high load.


Preparing the server

Before starting any work, it is recommended to create a system backup or VPS snapshot. All changes should first be tested in a staging environment.

System update and base packages

apt update && apt upgrade -yapt install -y curl wget unzip git software-properties-common

Make sure your system is running the latest kernel and security packages.

Setting up a firewall and basic security

For minimal server protection, we use ufw :

apt install -y ufwufw allow OpenSSHufw allow 80ufw allow 443ufw enable

It is also recommended:

  • disable root access via SSH;

  • use key-based authentication;

  • change the default SSH port.

Fail2ban

Fail2ban protects your server from brute-force attacks:

apt install -y fail2bansystemctl enable fail2bansystemctl start fail2ban

The minimal configuration for SSH already works out of the box.


Installing and configuring Nginx

Installing Nginx

apt install -y nginxsystemctl enable nginxsystemctl start nginx

Check that the server is responding on port 80.

Basic nginx.conf optimization

File: /etc/nginx/nginx.conf

worker_processes auto;worker_rlimit_nofile 100000;events { worker_connections 4096; multi_accept on;}http { sendfile on; tcp_nopush on; tcp_nodelay on; keepalive_timeout 65; types_hash_max_size 2048; gzip on; gzip_comp_level 5; gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss; include /etc/nginx/mime.types; default_type application/octet-stream;}

These settings provide a balance between performance and resource consumption.

Server block for OpenCart

server { listen 80; server_name example.com; root /var/www/opencart; index index.php; location / { try_files $uri $uri/ /index.php?$args; } location \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; } location * \.(jpg|jpeg|png|gif|css|js|ico|svg)$ { expires 30d; access_log off; }}

After changing the configuration, be sure to check the syntax:

nginx -t && systemctl reload nginx

PageSpeed module integration

PageSpeed is a content optimization module that performs minification, image compression, and other server-side operations.

Installing ngx_pagespeed

For Ubuntu 22.04, the most common installation methods are either from source or pre-built packages from third-party repositories. Here's an example of installing from a package:

apt install -y nginx-module-pagespeed

Basic PageSpeed Configuration

pagespeed on;pagespeed FileCachePath /var/cache/ngx_pagespeed;pagespeed EnableFilters collapse_whitespace,remove_comments;pagespeed EnableFilters rewrite_images,resize_images;pagespeed EnableFilters lazyload_images;

It is recommended to enable filters gradually and test the site after each change.

Testing

For the initial test, you can use ab :

ab -n 1000 -c 50 http://example.com/

Setting up PHP and MySQL

PHP-FPM

apt install -y php8.1-fpm php8.1-mysql php8.1-gd php8.1-curl php8.1-mbstring php8.1-xml php8.1-zip

File /etc/php/8.1/fpm/php.ini :

memory_limit = 512Mmax_execution_time = 120post_max_size = 64Mupload_max_filesize = 64M

MySQL

apt install -y mysql-servermysql_secure_installation

Key parameters /etc/mysql/mysql.conf.d/mysqld.cnf :

innodb_buffer_pool_size = 2Ginnodb_log_file_size = 256Mmax_connections = 300

The dimensions must be selected based on the amount of RAM.


OpenCart Installation and Integration

cd /var/wwwwget https://github.com/opencart/opencart/releases/download/3.0.3.8/opencart-3.0.3.8.zipunzip opencart-3.0.3.8.zipchown -R www-data:www-data opencart

Check the permissions on storage , image , and cache directories.

After installation in the admin panel, it is recommended:

  • enable caching;

  • set up SEO URL;

  • disable unused modules.


Optimization for high load

Redis or Memcached

apt install -y redis-server

Connecting Redis significantly reduces the load on MySQL when there are a large number of queries.

Monitoring

For production, it is recommended to use a combination of Prometheus and Grafana or external monitoring services.

SSL and CDN

apt install -y certbot python3-certbot-nginxcertbot --nginx

Using a CDN (Cloudflare and similar) reduces server load and speeds up content delivery.


A properly configured server allows OpenCart to operate reliably under high loads without the need for immediate infrastructure scaling. Using Nginx, PHP-FPM, PageSpeed, and optimized MySQL provides a significant performance boost compared to standard configurations.

Next steps include horizontal scaling, moving the database to a separate server, and fine-tuning caching for a specific store. If questions or unusual scenarios arise, we recommend consulting the official documentation and performing load testing before any major changes.


Sources

  • Nginx Documentation

  • OpenCart Documentation

  • Ubuntu Server Guide

  • PHP-FPM Documentation

  • MySQL Performance Tuning Guide