No results found

Try a different search query

Popular searches:

Add to Cart

Cart

You have no purchases yet

Browse Marketplace

VPS Server Setup for OpenCart

Step-by-step guide to setting up a VPS server for OpenCart: from choosing hosting to performance optimization.

18 min read
3,402
7
1
7
VPS Server Setup for OpenCart

Which services do you install on VPS?

15 votes Multiple choice

Log In to vote

Your own VPS server gives you complete control over your OpenCart hosting environment. In this guide, we'll set up a server from scratch using Ubuntu 22.04, Nginx, PHP 8.2, and MySQL 8.

Choosing VPS Hosting

For OpenCart, I recommend the following minimum specifications:

  • RAM: 2 GB (4 GB for stores with 1000+ products)
  • CPU: 2 vCPU
  • SSD: 40 GB
  • Traffic: 2 TB/month

Don't skimp on the server. Slow hosting = lost customers. The difference between $5 and $20/month can mean thousands of dollars in sales.

— Experience from 50+ OpenCart projects

Initial Server Setup

After connecting to the server via SSH:

# System update
sudo apt update && sudo apt upgrade -y

# Install basic utilities
sudo apt install -y curl wget git unzip htop

# Create deploy user
sudo adduser deployer
sudo usermod -aG sudo deployer

# Configure SSH keys
sudo mkdir -p /home/deployer/.ssh
sudo cp ~/.ssh/authorized_keys /home/deployer/.ssh/
sudo chown -R deployer:deployer /home/deployer/.ssh

Installing Nginx

# Install Nginx
sudo apt install -y nginx

# Start and enable autostart
sudo systemctl start nginx
sudo systemctl enable nginx

Nginx Configuration for OpenCart

# /etc/nginx/sites-available/opencart
server {
    listen 80;
    server_name example.com www.example.com;
    root /var/www/opencart;
    index index.php;

    # Logs
    access_log /var/log/nginx/opencart_access.log;
    error_log /var/log/nginx/opencart_error.log;

    # Gzip compression
    gzip on;
    gzip_types text/plain text/css application/json application/javascript text/xml;

    # Static file caching
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|woff2)$ {
        expires 30d;
        add_header Cache-Control "public, immutable";
    }

    # Deny access to system files
    location ~* (\.twig|\.tpl|\.ini|\.log|(?<!robots)\.txt)$ {
        deny all;
    }

    # SEO URLs
    location / {
        try_files $uri $uri/ @opencart;
    }

    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }

    # PHP processing
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        include fastcgi_params;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 256 16k;
    }
}
Tip: Always test the configuration before restarting: sudo nginx -t

Installing PHP 8.2

# Add repository
sudo add-apt-repository ppa:ondrej/php -y
sudo apt update

# Install PHP and modules
sudo apt install -y php8.2-fpm php8.2-mysql php8.2-curl \
    php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip \
    php8.2-opcache php8.2-intl php8.2-bcmath

PHP Optimization for OpenCart

; /etc/php/8.2/fpm/conf.d/opencart.ini
memory_limit = 256M
upload_max_filesize = 50M
post_max_size = 50M
max_execution_time = 300
max_input_vars = 5000

; OPcache
opcache.enable = 1
opcache.memory_consumption = 128
opcache.max_accelerated_files = 10000
opcache.revalidate_freq = 60

Installing MySQL 8

# Installation
sudo apt install -y mysql-server

# Secure installation
sudo mysql_secure_installation

# Create database and user
sudo mysql -e "CREATE DATABASE opencart CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
sudo mysql -e "CREATE USER 'opencart'@'localhost' IDENTIFIED BY 'strong_password_here';"
sudo mysql -e "GRANT ALL PRIVILEGES ON opencart.* TO 'opencart'@'localhost';"
sudo mysql -e "FLUSH PRIVILEGES;"

SSL Certificate (Let's Encrypt)

# Install Certbot
sudo apt install -y certbot python3-certbot-nginx

# Obtain certificate
sudo certbot --nginx -d example.com -d www.example.com

# Automatic renewal (already configured)

Firewall Configuration

# Basic rules
sudo ufw allow ssh
sudo ufw allow 'Nginx Full'
sudo ufw enable

# Check status
sudo ufw status
Important: Before enabling UFW, make sure the SSH port is allowed, otherwise you'll lose access to the server!

Automatic Backups

#!/bin/bash
# /home/deployer/backup.sh

DATE=$(date +%Y%m%d)
BACKUP_DIR="/home/deployer/backups"

# Database backup
mysqldump -u opencart -p'password' opencart | gzip > $BACKUP_DIR/db_$DATE.sql.gz

# Files backup
tar -czf $BACKUP_DIR/files_$DATE.tar.gz /var/www/opencart

# Delete old backups (older than 7 days)
find $BACKUP_DIR -type f -mtime +7 -delete
# Add to cron (daily at 3:00)
crontab -e
0 3 * * * /home/deployer/backup.sh

Conclusion

Now you have a fully configured VPS server for OpenCart. Don't forget to regularly update the system and monitor server resources.

Next Step: Set up server monitoring using Netdata or similar tools to track performance.
DEV Тестовий

DEV Тестовий

Привіт! Я досвідчений розробник з OpenCart екосистеми з понад 10 роками практики. Технічний стек включає PHP (core мова для OpenCart), MySQL/MariaDB для баз даних, JavaScript/jQuery для фронтенду, HTML5/CSS3/Bootstrap для верстки. Маю глибокий досвід роботи з архітектурою OpenCart (MVC, Event System, OCMOD), інтеграцією платіжних систем та API, оптимізацією продуктивності магазинів. Окрім розробки, займаюся серверним адмініструванням — Linux (Ubuntu/Debian), Apache/Nginx, налаштування VPS/Dedicated серверів, DNS менеджмент, SSL сертифікати, email. Обслуговую понад 5000 інтернет-магазинів по всьому світу, надаючи комплексні рішення від розробки до технічної підтримки.

articles
12
views
53,912
likes
63
followers
3

Related Posts

Comments (7)

Replying to

Please log in to leave a comment

Log In
a
Налаштував за цим гайдом - все працює ідеально!
a
Чи варто одразу налаштовувати Redis?
m
А для Ubuntu 24.04 ці інструкції актуальні?
a
What VPS provider do you recommend for OpenCart?

We use cookies

We use cookies and similar technologies to improve your experience, analyse traffic, and show personalised ads. Read our Cookie Policy for details.