Era Host hosting
EraHost – Free Domain, Cheap Hosting!
Client Area
Support 24/7
Menu

How to Install & Optimize OpenCart on a VPS

5 min read
22.11.2025

1. Choose the Right VPS for OpenCart

For optimal performance of your OpenCart store, selecting appropriate VPS specifications is crucial. The following recommendations are based on store size and expected traffic:

OpenCart VPS Install Optimize
OpenCart on VPS — install + tune; LEMP + Redis + CDN is the sweet spot.

For related OpenCart configuration topics, see Configure Apache/Nginx for OpenCart on a VPS, Configure MySQL for OpenCart on VPS, Fix ZIP Extension Needs to Be Loaded, and Install ZIP Extension for OpenCart.

Store Size CPU RAM Storage
VPS-1/2 for small store (1-500 products) 2/4 vCPU 6-9 GB RAM 60GB+ NVMe
VPS-2/3 for medium store (500-5,000 products) 4/8 vCPU 9-16 GB RAM 120GB+ NVMe
VPS-4/5 for large store (5,000+ products) 12/16+ vCPU 24-32 GB+ RAM 350GB+ NVMe

These specifications are recommended based on Era.Host VPS packages for optimal OpenCart performance.

2. Update the Server & Install Required Packages

First, update your system and install the necessary software packages.

For Ubuntu/Debian Systems

sudo apt update && sudo apt upgrade -y
sudo apt install apache2 mariadb-server php php-mysql php-curl php-gd php-xml php-mbstring php-zip unzip curl -y

For CentOS/RHEL Systems

sudo yum update -y
sudo yum install httpd mariadb-server php php-mysql php-curl php-gd php-xml php-mbstring php-zip unzip curl -y

Enable and Start Services

# For Ubuntu/Debian
sudo systemctl enable apache2 mariadb
sudo systemctl start apache2 mariadb

# For CentOS/RHEL
sudo systemctl enable httpd mariadb
sudo systemctl start httpd mariadb

3. Install OpenCart on the VPS

Download and Extract OpenCart

cd /var/www/html
sudo wget https://github.com/opencart/opencart/releases/download/4.0.2.3/opencart-4.0.2.3.zip
sudo unzip opencart-4.0.2.3.zip
sudo mv upload opencart
sudo rm opencart-4.0.2.3.zip

Set Proper Permissions

sudo chown -R www-data:www-data /var/www/html/opencart
sudo chmod -R 755 /var/www/html/opencart

Create OpenCart Configuration Files

sudo cp /var/www/html/opencart/config-dist.php /var/www/html/opencart/config.php
sudo cp /var/www/html/opencart/admin/config-dist.php /var/www/html/opencart/admin/config.php

4. Configure MySQL Database for OpenCart

Set up a secure database and user for your OpenCart installation.

  1. Access the MySQL command line:
    sudo mysql -u root -p
  2. Run the following SQL commands (replace StrongPassword123! with your own strong password):
    CREATE DATABASE opencart;
    CREATE USER 'opencart_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
    GRANT ALL PRIVILEGES ON opencart.* TO 'opencart_user'@'localhost';
    FLUSH PRIVILEGES;
    EXIT;
Linux VDS
High performance for your projects
  • Root access and flexible setup
  • Control panel
  • NVMe disks
  • DDR5
Linux VDS

5. Configure Apache/Nginx for OpenCart

Tip: Choose either Apache or Nginx based on your preference. Nginx generally offers better performance for high-traffic OpenCart stores.

For Apache

Edit the Apache configuration:

sudo nano /etc/apache2/sites-available/opencart.conf

Add the following configuration (adjust domain and paths as needed):

<VirtualHost *:80>
    ServerAdmin admin@yourdomain.com
    DocumentRoot /var/www/html/opencart/
    ServerName yourdomain.com
    ServerAlias www.yourdomain.com

    <Directory /var/www/html/opencart/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/opencart_error.log
    CustomLog ${APACHE_LOG_DIR}/opencart_access.log combined
</VirtualHost>

Enable the site and restart Apache:

sudo a2ensite opencart.conf
sudo systemctl restart apache2

For Nginx

Create an Nginx configuration file:

sudo nano /etc/nginx/sites-available/opencart

Add the following configuration:

server {
    listen 80;
    server_name yourdomain.com www.yourdomain.com;
    root /var/www/html/opencart/;
    index index.php index.html index.htm;

    location / {
        try_files $uri $uri/ /index.php?$query_string;
    }

    location ~ \.php$ {
        include fastcgi_params;
        fastcgi_pass unix:/run/php/php7.4-fpm.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot|ttf|otf)$ {
        expires max;
        log_not_found off;
    }
}

Enable the site and restart Nginx:

sudo ln -s /etc/nginx/sites-available/opencart /etc/nginx/sites-enabled/
sudo systemctl restart nginx

6. Complete the OpenCart Web Installation

  1. Open your web browser and navigate to:
    http://yourdomain.com/install
  2. Follow the installation wizard:
    • Database Host: localhost
    • Database Name: opencart
    • Database User: opencart_user
    • Database Password: (Use the password you created earlier)
  3. Complete the installation process through the web interface.
  4. After successful installation, remove the install directory for security:
    sudo rm -rf /var/www/html/opencart/install

7. Optimize OpenCart for Performance

Enable Caching with Redis

Install Redis for enhanced caching performance:

sudo apt install redis-server -y
sudo systemctl enable redis
sudo systemctl start redis

Enable Redis in OpenCart by editing the config.php files. Add these lines before the closing ?>:

define('CACHE_DRIVER', 'redis');
define('CACHE_HOSTNAME', 'localhost');
define('CACHE_PORT', '6379');

Enable Gzip Compression

In OpenCart Admin Panel:

  1. Navigate to System > Settings > Server
  2. Find Enable Gzip Compression and set it to level 5-9
  3. Save the changes

Set Up a Cron Job for Automatic Maintenance

sudo crontab -e

Add this line at the end of the file:

0 0 * * * php /var/www/html/opencart/system/cron.php > /dev/null 2>&1

This runs a daily cleanup of cache and logs to keep your store optimized.

8. Summary of OpenCart VPS Installation

Step Command/Description
Update VPS & Install Software apt install apache2 mariadb-server php php-mysql unzip curl -y
Download & Extract OpenCart wget opencart.zip && unzip opencart.zip
Set File Permissions chown -R www-data:www-data /var/www/html/opencart
Create MySQL Database CREATE DATABASE opencart;
Configure Apache/Nginx Create vHost file & restart services
Run Web Installation Access http://yourdomain.com/install
Optimize Performance Enable Redis, Gzip, and set up a cron job

Following this comprehensive guide will ensure your OpenCart store is properly installed, configured, and optimized for peak performance on your VPS!

Frequently asked questions
2 vCPU / 4 GB RAM / 40 GB SSD for stores up to ~1000 SKUs and low-to-moderate traffic. 4/8/80 for 5k-10k SKUs and active traffic. Above that, split DB to its own VPS. Image-heavy stores need disk that scales with catalog size and time. SSD is non-negotiable.
innodb_buffer_pool_size = 60-70% of RAM, query_cache_type = 0 (deprecated MySQL 8 anyway), tmp_table_size = 64M+. Many OpenCart queries are complex joins on product attributes — generous buffer pool is key. Also enable slow query log to find product searches that need indexing.
Significant for image-heavy stores. Product page with 5 product images renders 5x faster with CDN edge cache. Setup: CloudFront/Cloudflare in front of /image/ path. Origin still serves dynamic page content. Cloudflare free tier handles most stores; paid for large catalogs.
Multi-server setup (load balancer in front of multiple OpenCart instances) — Redis sessions let sessions survive across servers. Single-server: file-based sessions work fine until you grow. Move to Redis when you actually need it; premature optimization for single-VPS stores.
Related articles
Setting Up PrestaShop on a VDS (Virtual Dedicated Server)
Bitrix Virtual Appliance (BitrixVA)
Solving vqmod::bootup Error — "PHP domdocument Extension Required"