Log inSign up

Building an OpenCart shop from the shell

Download the OpenCart 4 release zip, copy its upload folder to /var/www/opencart, rename the two config-dist.php files and run install/cli_install.php install with your database and admin details. Afterwards delete the install folder, move storage outside the web root, add SEO URL rules to Nginx and finish with HTTPS.

Topic: Websites, CMS and shops · Tested on: Ubuntu 24.04 and 22.04, Debian 12 and 13, Rocky Linux 9, AlmaLinux 9 · Updated 2026-12-03

Why choose OpenCart and what does it need?

OpenCart is a compact PHP store with a small footprint, which makes it a good fit for a 1 to 2 GB VPS. It runs on any recent PHP 8 build with MariaDB or MySQL. The 4.x line is the current one; older 3.x stores still exist but a new project should start on 4.

Before installing, set up a sudo user (see your first SSH session), create DNS records for store.example.net and build a web stack. You can use Nginx with PHP-FPM as shown here or Apache with mod_php, where OpenCart's bundled .htaccess handles the rewrites for you.

How do you install the packages?

Install Nginx, MariaDB and PHP with the extensions OpenCart checks: curl, gd, zip, mbstring, xml and mysqli.

Ubuntu and Debian

sudo apt update
sudo apt install -y nginx mariadb-server php-fpm php-mysql php-curl php-gd php-zip php-mbstring php-xml php-intl unzip
php -v

Rocky Linux 9 and AlmaLinux 9

sudo dnf module reset -y php
sudo dnf module enable -y php:8.2
sudo dnf install -y nginx mariadb-server php-fpm php-mysqlnd php-gd php-pecl-zip php-mbstring php-xml php-intl unzip
sudo systemctl enable --now nginx mariadb php-fpm

Then create a database and account for the store:

sudo mariadb-secure-installation
sudo mariadb -e "CREATE DATABASE opencart CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;"
sudo mariadb -e "CREATE USER 'ocuser'@'localhost' IDENTIFIED BY 'oc-db-secret';"
sudo mariadb -e "GRANT ALL ON opencart.* TO 'ocuser'@'localhost';"

How do you download and place the files?

Each release on the OpenCart GitHub page has a zip whose upload directory is the actual store.

OC_VER=4.1.0.3
cd /tmp
curl -LO https://github.com/opencart/opencart/releases/download/$OC_VER/opencart-$OC_VER.zip
unzip -q opencart-$OC_VER.zip -d oc
sudo mkdir -p /var/www/opencart
sudo cp -a oc/upload/. /var/www/opencart/
cd /var/www/opencart
sudo cp config-dist.php config.php
sudo cp admin/config-dist.php admin/config.php
sudo chown -R www-data:www-data /var/www/opencart

Check the releases page for the newest 4.x tag and set OC_VER to it. Use nginx:nginx as owner on Rocky and Alma. The installer writes database settings into both config.php files, which is why they must exist and be writable.

How do you run the OpenCart CLI installer?

The cli_install.php script performs the same steps as the browser wizard without leaving the terminal.

cd /var/www/opencart/install
sudo -u www-data php cli_install.php install --username storeadmin --password Owner-pass-2026 --email owner@example.net --http_server https://store.example.net/ --db_driver mysqli --db_hostname localhost --db_username ocuser --db_password oc-db-secret --db_database opencart --db_port 3306 --db_prefix oc_

Note the trailing slash on http_server. When it reports success, delete the installer, because a reachable install folder lets anyone reset the store:

sudo rm -rf /var/www/opencart/install

You can also rename the admin folder; if you do, update the paths in admin/config.php to match.

Why move the storage folder, and how?

The system/storage folder holds logs, cache, sessions and downloadable products, so it should not be reachable from the web. The dashboard shows a warning until you move it.

sudo mv /var/www/opencart/system/storage /var/www/opencart-storage
sudo grep -n "DIR_STORAGE" /var/www/opencart/config.php /var/www/opencart/admin/config.php

Edit the DIR_STORAGE line in both files so it reads define('DIR_STORAGE', '/var/www/opencart-storage/');. The dashboard also offers a button that does the move for you; either way, confirm that the warning disappears after a reload.

How do you configure Nginx with SEO URLs?

Send requests that do not match a file to index.php with the path in the _route_ parameter, which is how OpenCart resolves friendly URLs.

server {
    listen 80;
    listen [::]:80;
    server_name store.example.net;
    root /var/www/opencart;
    index index.php;
    client_max_body_size 16m;

    location ~ /\. { deny all; }
    location ~* \.(twig|tpl|ini|log|txt)$ { deny all; }
    location / { try_files $uri $uri/ @opencart; }
    location @opencart { rewrite ^/(.+)$ /index.php?_route_=$1 last; }
    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php8.3-fpm.sock;
    }
    location ~* \.(css|js|png|jpe?g|gif|svg|webp|woff2?)$ { expires 30d; }
}

Use the socket matching your PHP version, or /run/php-fpm/www.sock on Rocky and Alma with fastcgi_params. Reload Nginx, then enable SEO URLs in System, Settings, Server.

How do you add HTTPS and mail?

Open ports 80 and 443 and run Certbot as in the Certbot and Let's Encrypt guide.

sudo ufw allow 'Nginx Full'
sudo certbot --nginx -d store.example.net
curl -sI https://store.example.net | head -n 1

The http_server value was already set to https during install, so the storefront and admin links stay consistent. For order confirmations pick SMTP under System, Settings, Mail and enter the details of an authenticated relay on port 587, as covered in SMTP relay for apps. Port 25 delivery is not something to rely on; ask support with a ticket before planning it.

How do you maintain and back up the shop?

Back up three things: the database, the web root and the moved storage folder.

sudo mariadb-dump --single-transaction opencart | gzip > ~/opencart.sql.gz
sudo tar -czf ~/opencart-files.tar.gz -C /var/www opencart opencart-storage

Upgrades inside the 4.x line are done by replacing the files (keeping both config.php files and your storage folder) and running the upgrade route the release notes describe. Extensions written for 3.x do not work on 4.x, so check compatibility before buying any. When something breaks, the error log is in /var/www/opencart-storage/logs/error.log and in System, Maintenance, Error Logs. For blank pages also read /var/log/nginx/error.log and the PHP-FPM journal with journalctl -u php8.3-fpm.

Plans that fit this guide

Base city prices. Every plan includes a dedicated IPv4 address, IPv6, full root and all 18 images.

All prices
PlanFits becauseSizeMonthlyOrder from
A1-1a small store to start1 vCPU, 1 GB RAM, 25 GB NVMe$3.60/mo$43.20 for 12 months
A1-2more extensions and visitors1 vCPU, 2 GB RAM, 50 GB NVMe$7.20/mo$43.20 for 6 months

Questions about OpenCart shop on Nginx

Is OpenCart 3 still a good choice?

For a new store pick 4.x. Version 3 extensions are not compatible with 4, and new development happens on the 4 line.

Why do category pages return 404 after enabling SEO URLs?

The rewrite to index.php?_route_= is missing or Nginx was not reloaded. Check the @opencart location and run sudo nginx -t.

How do I reset the admin password?

Use the forgotten password link if mail works. Otherwise update the oc_user table with a new hash generated by php -r "echo password_hash('NewPass', PASSWORD_DEFAULT);".

Can OpenCart run on Apache instead?

Yes. Rename .htaccess.txt to .htaccess, enable mod_rewrite and allow overrides for the site directory.

How much server do I need?

A 1 GB plan handles a small store. Choose 2 GB or more once you add many extensions or expect steady traffic.