Tutorials

Install OpenCart on Ubuntu 18.04 with Nginx and PHP 7.2

OpenCart is a free, open-source PHP e-commerce platform used by hundreds of thousands of merchants worldwide. It includes everything most online stores need right away: multi-store support, user accounts, discount codes, affiliate programs, product reviews, multiple payment gateways, and multi-language support.

OpenCart’s admin dashboard gives store owners a clear view of orders, customers, and revenue without needing to touch code. This guide shows you how to install OpenCart on Ubuntu 18.04 using Nginx, PHP 7.2, and MySQL.

Prerequisites:

  • A domain name pointing to your server’s public IP
  • Nginx installed with a Let’s Encrypt SSL certificate
  • Sudo access

Install OpenCart on Ubuntu: Database, PHP, and File Setup

Update the system and install the unzip utility:

bashsudo apt update && sudo apt upgradesudo apt install unzip

Create the MySQL database. Log into MySQL and set up the database and user:

bashsudo mysql
sqlCREATE DATABASE opencart;GRANT ALL ON opencart.* TO 'opencart'@'localhost' IDENTIFIED BY 'change-with-strong-password';EXIT;

Install PHP 7.2 with all modules OpenCart requires:

bashsudo apt install php7.2-common php7.2-cli php7.2-fpm php7.2-opcache php7.2-gd php7.2-mysql php7.2-curl php7.2-intl php7.2-xsl php7.2-mbstring php7.2-zip php7.2-bcmath php7.2-soap

PHP-FPM starts automatically. Raise the memory limits and execution time in php.ini to handle large product catalogs and image uploads:

bashsudo sed -i "s/memory_limit = .*/memory_limit = 1024M/" /etc/php/7.2/fpm/php.inisudo sed -i "s/upload_max_filesize = .*/upload_max_filesize = 256M/" /etc/php/7.2/fpm/php.inisudo sed -i "s/zlib.output_compression = .*/zlib.output_compression = on/" /etc/php/7.2/fpm/php.inisudo sed -i "s/max_execution_time = .*/max_execution_time = 18000/" /etc/php/7.2/fpm/php.inisudo sed -i "s/;date.timezone.*/date.timezone = UTC/" /etc/php/7.2/fpm/php.inisudo sed -i "s/;opcache.save_comments.*/opcache.save_comments = 1/" /etc/php/7.2/fpm/php.ini

Download and extract OpenCart. Create the document root and download version 3.0.3.1:

bashsudo mkdir -p /var/www/html/example.comcd /tmpwget https://github.com/opencart/opencart/releases/download/3.0.3.1/opencart-3.0.3.1.zipunzip opencart-*.zipsudo mv /tmp/upload/* /var/www/html/example.com/

Copy the configuration templates and set file ownership so Nginx can access the site files:

bashsudo cp /var/www/html/example.com/{config-dist.php,config.php}sudo cp /var/www/html/example.com/admin/{config-dist.php,config.php}sudo chown -R www-data: /var/www/html

Configure Nginx and Set Correct File Permissions

Create an Nginx server block at /etc/nginx/sites-available/example.com. The configuration needs three server blocks: one to redirect HTTP to HTTPS, one to redirect www to the non-www domain, and a main HTTPS block. The main block sets root to /var/www/html/example.com, enables index.php, uses try_files $uri $uri/ /index.php?$args for routing, and passes PHP requests to unix:/run/php/php7.2-fpm.sock. Add a location block to serve static files like images, CSS, and JavaScript directly with long expiry headers.

Replace example.com with your domain and update the SSL certificate paths to your Let’s Encrypt files.

Test the configuration and restart Nginx:

bashsudo nginx -tsudo systemctl restart nginx

Complete the OpenCart Installation via Web Wizard

Open your domain in a browser. The OpenCart setup wizard starts automatically:

  1. Accept the license agreement and select your language
  2. Confirm all pre-installation checks are green — they verify PHP module availability and directory permissions
  3. Enter your MySQL database name, username, and password. OpenCart tests the connection before continuing
  4. Set an admin username, strong password, and email address for the store
  5. Click Continue

When you first access the admin dashboard, a prompt asks you to move the storage directory outside of the web root. Choose Automatically Move and click the Move button. Leaving the storage folder inside the web root is a security risk.

Remove the installation directory to prevent unauthorized reinstallation:

bashsudo rm -rf /var/www/html/example.com/install

OpenCart is now running on your Ubuntu 18.04 server. Visit the OpenCart documentation to learn how to add products, configure payment gateways, and manage your store. Leave a comment below if you run into any issues.

Cyber Defence

Recent Posts

Install Anaconda on Ubuntu 18.04: Python Data Science Setup Guide

Anaconda is the most widely used Python distribution for data science and machine learning. It bundles…

1 hour ago

Install WordPress on Ubuntu 18.04 with Nginx and PHP 7.2

WordPress is the most popular open-source CMS in the world, powering over 40% of all websites…

1 hour ago

Install Magento 2 on Ubuntu 18.04 with Composer and Nginx

Magento is an enterprise-class, open-source e-commerce platform written in PHP. It is built for merchants who…

2 hours ago

Install WildFly on Ubuntu 18.04: Java App Server Setup Guide

Install WildFly on Ubuntu 18.04: Java App Server Setup GuideWildFly (formerly JBoss) is an open-source,…

2 hours ago

Install Drupal on Ubuntu 18.04 with Composer, Nginx, and PHP

Drupal is one of the most widely used open-source CMS platforms in the world. Written in…

1 day ago

Set Up an FTP Server on Ubuntu 18.04 with vsftpd and SSL

FTP (File Transfer Protocol) is a standard network protocol for transferring files between a local client…

1 day ago