Websites & apps

Install OpenCart on a Linux VPS with Nginx

Install OpenCart 4 on an Ubuntu or AlmaLinux VPS with Nginx, PHP-FPM and MariaDB: PHP extensions, database, config files, SEO URL rules, SSL and securing the storage folder.

IntermediateLinux VPS3 min read

OpenCart is a lightweight PHP shop that runs well on a small VPS. This guide installs OpenCart 4 on a Linux VPS with Nginx, PHP-FPM and MariaDB, then applies the security steps the installer reminds you about.

Before you start

Install PHP extensions

OpenCart 4 needs PHP 8.0 or newer with these extensions:

sudo apt install php8.2-fpm php8.2-mysql php8.2-curl php8.2-gd php8.2-mbstring php8.2-xml php8.2-zip php8.2-intl unzip

Set upload_max_filesize = 32M and memory_limit = 256M in /etc/php/8.2/fpm/php.ini, then restart PHP-FPM.

Create the database

sudo mysql -e "CREATE DATABASE opencart CHARACTER SET utf8mb4; CREATE USER 'oc_user'@'localhost' IDENTIFIED BY 'StrongPasswordHere'; GRANT ALL ON opencart.* TO 'oc_user'@'localhost'; FLUSH PRIVILEGES;"

Upload the files

  1. Download the latest OpenCart release zip from the official GitHub releases page.
  2. Extract it. Only the upload folder goes to the web root.
  3. Rename the two sample config files.
cd /tmp && unzip opencart-4*.zip && sudo mkdir -p /var/www/opencart && sudo cp -r upload/. /var/www/opencart/
cd /var/www/opencart && sudo mv config-dist.php config.php && sudo mv admin/config-dist.php admin/config.php
sudo chown -R www-data:www-data /var/www/opencart

Configure Nginx

server {
    listen 80;
    server_name shop.example.com;
    root /var/www/opencart;
    index index.php;

    location / {
        try_files $uri $uri/ @opencart;
    }
    location @opencart {
        rewrite ^/(.+)$ /index.php?_route_=$1 last;
    }
    location ~* /(system/storage|\.git) {
        deny all;
    }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.2-fpm.sock;
    }
}

The @opencart rewrite is what makes SEO URLs work, because Nginx does not read OpenCart's .htaccess. Test with sudo nginx -t and reload. Then add SSL with Certbot.

Run the installer

  1. Open https://shop.example.com/install/.
  2. Accept the licence and confirm all checks are green.
  3. Enter the database details (host localhost, the user and database above) and the admin account.
  4. When it finishes, delete the installer: sudo rm -rf /var/www/opencart/install.

Move the storage folder

After the first admin login, OpenCart shows a warning asking you to move system/storage outside the web root. Use the built-in Move button, or move it to /var/www/storage/ and update DIR_STORAGE in both config.php files. Also rename the admin folder when the dashboard suggests it.

Troubleshooting

  • SEO URLs give 404: the Nginx rewrite is missing, or Use SEO URLs is on without it.
  • Blank page after install: check the PHP-FPM log; a missing extension is the usual cause. See debug a PHP white screen.
  • Permission errors when installing extensions: the files must be owned by the PHP-FPM user.

FAQ

Does OpenCart 4 work on PHP 8.2?

Yes, current OpenCart 4 releases support PHP 8.0–8.2. Older 3.x versions need PHP 7.x, so check before you upgrade PHP.

Why does OpenCart want the storage folder moved?

It holds logs, cache and uploads. Outside the web root, nobody can download those files directly from a browser.

Is a 1 GB VPS enough for OpenCart?

For a small shop, yes, ideally with a swap file. Larger catalogues and more traffic need 2 GB or more.

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.