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

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

23 hours ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

23 hours ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

2 days ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

5 days ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

5 days ago

who Command in Linux: Show All Logged-In Users and Sessions

When you share a server with a team or investigate unexpected activity, the first question…

5 days ago