To run OpenCart efficiently on a VPS, you need to configure your web server properly. This guide covers:
Before configuring OpenCart, install your preferred web server.
sudo apt update
sudo apt install apache2 -y
sudo yum install httpd -y
sudo apt install nginx -y
sudo yum install nginx -y
# For Apache
sudo systemctl enable apache2 && sudo systemctl start apache2
# For Nginx
sudo systemctl enable nginx && sudo systemctl start nginx
On CentOS/RHEL, use httpd instead of apache2 for Apache service.
/var/www/html/opencart/ or /var/www/opencart/) before proceeding.
sudo a2enmod rewrite headers expires
sudo systemctl restart apache2
sudo nano /etc/apache2/sites-available/opencart.conf
For CentOS/RHEL systems, use:
sudo nano /etc/httpd/conf.d/opencart.conf
Add the following configuration (adjust paths and domain names 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>
sudo a2ensite opencart.conf
sudo systemctl restart apache2
For CentOS/RHEL, restart with:
sudo systemctl restart httpd
Now Apache is properly configured for OpenCart!
php7.4-fpm.sock) to match your PHP version.
sudo nano /etc/nginx/sites-available/opencart
For CentOS/RHEL systems:
sudo nano /etc/nginx/conf.d/opencart.conf
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|otf)$ {
expires max;
log_not_found off;
}
}
sudo ln -s /etc/nginx/sites-available/opencart /etc/nginx/sites-enabled/
sudo systemctl restart nginx
For CentOS/RHEL (configuration is already in conf.d directory):
sudo systemctl restart nginx
Now Nginx is configured for OpenCart!
To secure your OpenCart store, install a free SSL certificate from Let's Encrypt.
sudo apt install certbot python3-certbot-apache -y
sudo apt install certbot python3-certbot-nginx -y
sudo yum install certbot python3-certbot-apache -y
sudo yum install certbot python3-certbot-nginx -y
For Apache:
sudo certbot --apache -d yourdomain.com -d www.yourdomain.com
For Nginx:
sudo certbot --nginx -d yourdomain.com -d www.yourdomain.com
Follow the interactive prompts to complete the certificate installation.
Let's Encrypt certificates expire every 90 days. Set up automatic renewal:
sudo crontab -e
Add this line at the end of the file:
0 0 * * * /usr/bin/certbot renew --quiet
This will check daily for certificates nearing expiration and renew them automatically. Now your OpenCart store is running securely on HTTPS!
| Task | Command |
|---|---|
| Install Apache or Nginx | apt install apache2 or apt install nginx |
| Enable Apache Modules | a2enmod rewrite headers expires |
| Create Apache Virtual Host | nano /etc/apache2/sites-available/opencart.conf |
| Enable OpenCart in Apache | a2ensite opencart.conf && systemctl restart apache2 |
| Create Nginx Virtual Host | nano /etc/nginx/sites-available/opencart |
| Enable OpenCart in Nginx | ln -s /etc/nginx/sites-available/opencart /etc/nginx/sites-enabled/ && systemctl restart nginx |
| Enable SSL (HTTPS) | certbot --apache or certbot --nginx |
Following these steps will give you a fully configured, secure OpenCart installation running on your VPS!