YouTube Icon

Code Playground.

How to Install OpenCart on Ubuntu 18.04


How to Install OpenCart on Ubuntu 18.04

OpenCart is a free and open-source PHP online business stage consolidating amazing highlights with adaptability and easy to use interface. 

With highlights like User Management, Multi-Store, Affiliates, Discounts, Product Reviews, Multi-lingual and numerous Payment Gateways, OpenCart is a foundation of decision for some online shippers. 

In this instructional exercise, we will tell you the best way to introduce OpenCart on Ubuntu 18.04 worker. We'll be utilizing Nginx as a web worker, the most recent PHP 7.2 and MySQL/MariaDB as an information base worker. 


Guarantee that you have met the accompanying requirements prior to proceeding with this instructional exercise: 

Have a space name highlighting your public worker IP. We will utilize 

Nginx is introduced on your Ubuntu worker by adhering to these guidelines . 

A SSL authentication introduced for your space to scramble client's data. You can introduce a free Let's Encrypt SSL endorsement by adhering to these directions . 

Update the framework bundles to the most recent forms and introduce the unfasten utility : 

sudo apt update && sudo apt upgrade
sudo apt install unzip

Creating MySQL database

In the event that you have MySQL or MariaDB introduced on your worker you can avoid this progression, if not you can introduce the MySQL 5.7 worker bundle from the Ubuntu's default stores by composing: 

sudo apt install mysql-server mysql-client

For new MySQL establishments, it is prescribed to run the mysql_secure_installation order to improve the security of your MySQL worker. 

Login to the MySQL shell utilizing the accompanying order: 

sudo mysql

From inside the MySQL shell, run the accompanying SQL explanation to make another information base named opencart: 



Next, make a MySQL client account named opencart and award the vital consents to the client by running the accompanying order: 

GRANT ALL ON opencart.* TO 'opencart'@'localhost' IDENTIFIED BY 'change-with-strong-password';

Ensure you change-with-solid secret key with a solid secret key. 

When done, leave the mysql support by composing: 


Installing and Configuring PHP

PHP 7.2 which is the default PHP form in Ubuntu 18.04 is completely upheld and suggested for OpenCart. Since we will utilize Nginx as a web worker we'll additionally introduce the PHP-FPM bundle. 

Run the accompanying order to introduce PHP and all necessary PHP modules: 

sudo 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 administration will naturally begin after the establishment cycle is finished, you can confirm it by printing the administration status: 

sudo systemctl status php7.2-fpm

The yield ought to demonstrate that the fpm administration is dynamic and running. 

? php7.2-fpm.service - The PHP 7.2 FastCGI Process Manager
   Loaded: loaded (/lib/systemd/system/php7.2-fpm.service; enabled; vendor preset: enabled)
   Active: active (running) since Mon 2019-02-25 10:45:42 UTC; 53s ago
     Docs: man:php-fpm7.2(8)
 Main PID: 27446 (php-fpm7.2)
   Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 3 (limit: 505)
   CGroup: /system.slice/php7.2-fpm.service
           ??27446 php-fpm: master process (/etc/php/7.2/fpm/php-fpm.conf)

Set the required and suggested PHP alternatives by altering the php.ini document with sed :: 

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

Installing OpenCart

At the hour of composing this article, the most recent stable form of OpenCart is adaptation 

Prior to downloading the OpenCart document, first make an index which will hold our OpenCart records: 

sudo mkdir -p /var/www/html/

Download the most recent rendition of OpenCart from the OpenCart Github store utilizing the accompanying wget order : 

cd /tmp

Once the download is finished, separate the OpenCart chronicle and move the extricated records into the space's archive root index: 

unzip opencart-*.zip
sudo mv /tmp/upload/* /var/www/html/

Duplicate the designs records utilizing the cp order: 

sudo cp /var/www/html/{config-dist.php,config.php}
sudo cp /var/www/html/{config-dist.php,config.php}

Set the right authorizations with the goal that the web worker can have full admittance to the website's documents and registries utilizing the accompanying chown order : 

sudo chown -R www-data: /var/www/html

Configuring Nginx

At this point, you should as of now have Nginx with SSL authentication introduced on your Ubuntu worker, if not check the requirements for this instructional exercise. 

Open your content manager and make the accompanying record: 

sudo nano /etc/nginx/sites-available/


# Redirect HTTP -> HTTPS
server {
    listen 80;

    include snippets/letsencrypt.conf;
    return 301$request_uri;

# Redirect WWW -> NON WWW
server {
    listen 443 ssl http2;

    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;
    ssl_trusted_certificate /etc/letsencrypt/live/;
    include snippets/ssl.conf;

    return 301$request_uri;

server {
    listen 443 ssl http2;

    root /var/www/html/;
    index index.php;

    # SSL parameters
    ssl_certificate /etc/letsencrypt/live/;
    ssl_certificate_key /etc/letsencrypt/live/;
    ssl_trusted_certificate /etc/letsencrypt/live/;
    include snippets/ssl.conf;
    include snippets/letsencrypt.conf;

    # log files
    access_log /var/log/nginx/;
    error_log /var/log/nginx/;

    location = /favicon.ico {
        log_not_found off;
        access_log off;

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;

    location / {
        try_files $uri $uri/ /index.php?$args;

    location ~ \.php$ {
        include snippets/fastcgi-php.conf;
        fastcgi_pass unix:/run/php/php7.2-fpm.sock;

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
        expires max;
        log_not_found off;


Remember to supplant with your OpenCart space and set the right way to the SSL declaration records. All the HTTP solicitations will be diverted to HTTPS . The bits utilized in this setup are made in this guide . 

Prior to restarting the Nginx administration make a test to be certain that there are no grammar mistakes: 

sudo nginx -t

In the event that there are no mistakes the yield should resemble this: 

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful


At last, restart the Nginx administration by composing: 

sudo systemctl restart nginx

Completing the OpenCart Installation

Since OpenCart is downloaded and the worker arrangement is finished, you can complete the establishment through the web interface. 

Open your program, type your space and a screen like the accompanying will show up: 

Introduce OpenCart permit 

Peruse the OpenCart permit understanding, select the language you might want to utilize and tap on the Continue button. 

Next, you will see the accompanying data page: 

Introduce OpenCart Pre-Installtion 

Ensure all pre-establishment necessities are met and click on the Continue button. 

On the following screen, the arrangement wizard will request that you enter your information base association subtleties. Enter the MySQL client and information base subtleties you recently made. 

Introduce OpenCart Configuration 

Enter a username, secret word and email address for the organization and start the establishment by tapping on the Continue button. 

When the establishment is finished you will be taken to a page advising you that OpenCart has been introduced. 

Introduce OpenCart Configuration 

To get to your OpenCart regulatory dashboard click on the Login to your Administration button. Enter your username and secret word and you will be diverted to the organization dashboard. 

The first occasion when you sign in, a spring up will show up requesting that you move the capacity catalog outside of the web index. 

Introduce OpenCart move stockpiling 

Keep the default Automatically Move alternative and snap on the red Move button. The index where you are moving the capacity catalog must be available by the web worker. 

From here, you can begin tweaking your OpenCart establishment and add new items. 

You'll likewise need to erase the establishment catalog. To do as such, return to the terminal and type the accompanying rm order: 

sudo rm -rf /var/www/html/


Congrats, you have effectively introduced OpenCart on your Ubuntu 18.04 worker. 

OpenCart Documentation is a decent beginning spot to study how to deal with your OpenCart establishment. 

On the off chance that you have questions, don't hesitate to leave a remark beneath.