How to Install & Optimize OpenCart on a VPS
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:
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.
- Access the MySQL command line:
sudo mysql -u root -p - 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;
5. Configure Apache/Nginx for OpenCart
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
- Open your web browser and navigate to:
http://yourdomain.com/install - Follow the installation wizard:
- Database Host: localhost
- Database Name: opencart
- Database User: opencart_user
- Database Password: (Use the password you created earlier)
- Complete the installation process through the web interface.
- 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:
- Navigate to System > Settings > Server
- Find Enable Gzip Compression and set it to level 5-9
- 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!


