How to Install OpenCart on Ubuntu 20.04 with Nginx

Updated on December 6, 2021
How to Install OpenCart on Ubuntu 20.04 with Nginx header image

OpenCart is a popular open-source eCommerce store solution designed to offer excellent functionality, simplicity, and management of online stores from a single back-end dashboard. With OpenCart, you can quickly build a complete online shopping store and customize it with free extensions for your needs.

In this article, you will install OpenCart on a Ubuntu 20.04 server running on a LEMP (Nginx, MySQL, PHP) stack. But first, your installation needs to meet a few requirements.

Install Prerequisites

  • Deploy a Ubuntu 20.04 LEMP Server from the Vultr Marketplace Apps
  • SSH to the server and log in as root.
  • Update the server.

Optionally, you can configure a domain name to point to your server.

Create a Database for OpenCart

  1. Login to MySQL.

     $ mysql -u root
  2. Create a new database for OpenCart.

     mysql> create database opencart;
  3. Create a new database user and a strong password.

     mysql> create user 'admin’@’localhost' IDENTIFIED BY 'YOUR_STRONG_PASSWORD';
  4. Grant the user full rights to the OpenCart database.

     mysql> GRANT ALL PRIVILEGES ON opencart.* TO 'admin’@’localhost';
  5. Refresh rights and Exit the MySQL console.


Download OpenCart

  1. Download the latest stable version of OpenCart from its Github repository. In this article, we install version, consider checking for the latest version.

     $ wget
  2. Extract files from the OpenCart Zip archive.

     $ unzip -d opencart
  3. Move the extracted files to your web server root directory; by default, Nginx uses /usr/share/nginx/html.

     $ sudo mv opencart/upload/* /usr/share/nginx/html
  4. Change ownership rights to the user and group nginx identified by www-data.

     $ sudo chown -R www-data:www-data  /usr/share/nginx/html

Prepare Installation Files

Set up OpenCart by renaming the template configuration files to the production names.

$ cd /usr/share/nginx/html
$ sudo mv config-dist.php config.php
$ sudo mv admin/config-dist.php admin/config.php

Configure the Firewall

Allow HTTP and HTTPS traffic on your server.

$ sudo ufw allow 80 
$ sudo ufw allow 8080
$ sudo ufw allow http
$ sudo ufw allow https

Install a Free SSL/TLS Certificate

  1. Since most modern browsers and OpenCart use HTTPS, you must install a free SSL/TLS certificate to avoid certificate errors. To do so, install certbot and its Nginx plugin.

     $ sudo apt install certbot python3-certbot-nginx
  2. Request a new SSL certificate for your domain.

     $ certbot –nginx -d
  3. Enter your email address and agree to the terms of service, then configure your HTTPS settings, and once done, a valid certificate will be installed on your server.

     - Congratulations! Your certificate and chain have been saved at:
     Your key file has been saved at:

Install OpenCart

  1. Visit your server's public IP Address or the associated domain name through a web browser to start the OpenCart installation process.
  2. Click Continue to agree to the product terms and conditions on the main welcome screen.

  3. OpenCart will attempt to check if your server meets all requirements; once passed, click Continue.

  4. Input the database name, username, and password created on Step 1 of this article.

    OpenCart Database Settings

  5. Click continue to finish the installation process and access your main OpenCart administrator dashboard to make further configurations.

Securing OpenCart

  1. If you have installed OpenCart on a production server, it is recommended to secure your server by performing the following instructions.

  2. Delete the installation file.

     $ sudo rm -r /usr/share/nginx/html/install
  3. Change File Permissions for the following files to 644.

     $ sudo chmod  644 /usr/share/nginx/html/config.php
     $ sudo chmod  644 /usr/share/nginx/html/index.php
     $ sudo chmod  644 /usr/share/nginx/html/admin/config.php
     $ sudo chmod  644 /usr/share/nginx/html/admin/index.php
     $ sudo chmod  644 /usr/share/nginx/html/system/startup.php
  4. Secure the Administrator directory/Login URL by renaming it.

     $ sudo mv /usr/share/nginx/html/admin privatemin
  5. Your Login URL will be changed from admin to privatemin with the above command. You can change it to your preferred secret keyword, and you will be able to access your OpenCart server dashboard through it.

    For example:


Congratulations, you have installed OpenCart on your Ubuntu 20.04 server. You can create and configure your new store by visiting your server IP or associated domain name.