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
- A VPS with 1–2 GB RAM, Ubuntu 22.04/24.04 or AlmaLinux 9, and sudo access.
- Nginx, PHP-FPM and MariaDB installed. See install a LEMP stack.
- A domain pointed at the server.
- On shared hosting instead? Use install OpenCart on cPanel.
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 unzipSet 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
- Download the latest OpenCart release zip from the official GitHub releases page.
- Extract it. Only the
uploadfolder goes to the web root. - 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.phpsudo chown -R www-data:www-data /var/www/opencartConfigure 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
- Open
https://shop.example.com/install/. - Accept the licence and confirm all checks are green.
- Enter the database details (host
localhost, the user and database above) and the admin account. - 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.
