OpenCart is a lightweight eCommerce platform that runs efficiently on a VPS (Virtual Private Server). This guide will cover:
For optimal performance of your OpenCart store, selecting appropriate VPS specifications is crucial. The following recommendations are based on store size and expected traffic:
| 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.
First, update your system and install the necessary software packages.
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
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
# 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
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
sudo chown -R www-data:www-data /var/www/html/opencart
sudo chmod -R 755 /var/www/html/opencart
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
Set up a secure database and user for your OpenCart installation.
sudo mysql -u root -p
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;
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
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
http://yourdomain.com/install
sudo rm -rf /var/www/html/opencart/install
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');
In OpenCart Admin Panel:
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.
| 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!