How to Install OpenCart on Ubuntu 18.04

Install OpenCart on Ubuntu 18

OpenCart is a free and open-source shopping cart system. It is a PHP-based platform for creating online stores, delivering all standard e-commerce functionalities needed for managing an online shop. OpenCart has free lifetime support, software updates, and is localized in many languages and currencies, making it one of the most popular and widely-used self-hosted e-commerce platforms available. In this tutorial, we will show you how to install OpenCart on your Ubuntu 18.04 server.

Requirements:

  • For the purposes of this tutorial, we will use an Ubuntu 18.04 VPS
  • Full SSH root access or a user with sudo privileges is also required.

1. Getting Started

First, you will need to login to your server via SSH as the root user:

ssh root@IP_ADDRESS -p PORT_NUMBER

and replace “IP_ADDRESS” and “PORT_NUMBER” with your actual server IP address and SSH port number.

Once logged in, let’s make sure that your Ubuntu 18.04 server is up-to-date by running the following commands:

$ sudo apt-get update
$ sudo apt-get upgrade

This will update the package index and will update the software currently installed on the server to the latest version.

Once your system is fully up-to-date, we can now proceed with the OpenCart installation.

2. Install the MySQL Database Server

Next, we will install the MySQL server. To install the default package, run the following command:

$ sudo apt-get install mysql-server

This will install MySQL 5.7 on your server, but it will not prompt you to set a password or make any other configuration changes. Because this leaves your installation of MySQL insecure, in order to improve the security of your MySQL server, we recommend that you run the ‘mysql_secure_installation‘ script by typing the following command:

$ mysql_secure_installation

This script will help you to perform important security tasks like setting up a root password, disable remote root login, remove anonymous users, etc.

3. Create a Database for OpenCart

Now, we will create our MySQL database for our OpenCart site. Log in to your MySQL server with the following command and enter your MySQL root password:

sudo mysql -u root -p

In this section, we will create a new MySQL database opencart and assign user access to it to a new user admin_user with the password Strong_Password:

CREATE DATABASE opencart;
GRANT ALL PRIVILEGES ON opencart.* TO 'admin_user'@'localhost' IDENTIFIED BY 'Strong_Password';
FLUSH PRIVILEGES;
exit;

Don’t forget to replace ‘Strong_Password’ with an actual strong password.

4. Install Apache and PHP

To install the Apache web server, run the following command:

$ sudo apt-get install apache2

After the installation is complete, you should enable Apache to start automatically upon server reboot with:

$ sudo systemctl enable apache2

You can also check the status of your Apache service with the following command:

$ sudo systemctl status apache2

Output:

apache2.service - The Apache HTTP Server
   Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset:
  Drop-In: /lib/systemd/system/apache2.service.d
           └─apache2-systemd.conf
   Active: active (running)
  Process: 728 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCES
 Main PID: 855 (apache2)
    Tasks: 6 (limit: 2321)
   CGroup: /system.slice/apache2.service
           ├─855 /usr/sbin/apache2 -k start
           ├─876 /usr/sbin/apache2 -k start
           ├─877 /usr/sbin/apache2 -k start
           ├─878 /usr/sbin/apache2 -k start
           ├─879 /usr/sbin/apache2 -k start
           └─880 /usr/sbin/apache2 -k start

Since OpenCart is a PHP-based application, our next step is to install PHP and some PHP extensions required by OpenCart:

$ sudo apt-get install php libapache2-mod-php
$ sudo apt-get install php-cli php-common php-mbstring php-gd php-intl php-xml php-mysql php-zip 
php-curl php-xmlrpc

Restart the Apache web server to load the PHP modules:

$ sudo systemctl restart apache2

Now check the PHP version installed on your server:

$ php -v

Output:

PHP 7.2.10-0ubuntu0.18.04.1 (cli) (built: Sep 13 2018 13:45:02) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.10-0ubuntu0.18.04.1, Copyright (c) 1999-2018, by Zend Technologies

5. Download the Latest Release of OpenCart

The latest version of OpenCart (v.3.0.3.1) can be downloaded from the OpenCart website (recommended for end users) or directly from Github (recommended for web developers). The download page also offers access to previous versions of OpenCart.

$ sudo wget https://github.com/opencart/opencart/releases/download/3.0.3.1/opencart-3.0.3.1.zip
$ sudo unzip opencart-3.0.3.1
$ sudo mv upload/ /var/www/html/opencart
$ sudo cd /var/www/html/opencart/
$ sudo cp config-dist.php config.php
$ sudo cp admin/config-dist.php admin/config.php

Then run the commands below to set the correct permissions for OpenCart to function.

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

6: Configure Apache2

We can now create our virtual host files. Run the following command to create the virtual host configuration file for your domain, your_domain.com:

$ sudo nano /etc/apache2/sites-available/your_domain.com.conf

Then copy and paste the content below into the file and save it. Replace the “your_domain.com” with your own domain name and directory root location.

<VirtualHost *:80>
     ServerAdmin admin@your_domain.com
     DocumentRoot /var/www/html/opencart/
     ServerName your_domain.com ServerAlias www.your_domain.com <Directory /var/www/html/opencart/> Options FollowSymlinks AllowOverride All Order allow,deny allow from all </Directory> ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost>

Save the file and exit.

Activate the virtual host by creating a symbolic link :

$ sudo ln -s /etc/apache2/sites-available/your_domain.com.conf /etc/apache2/sites-enabled/your_domain.com.conf

Restart Apache for the changes to take effect:

$ sudo systemctl restart apache2

To access your OpenCart installation, you will need to type the following URL in your web browser:

http://your_domain.com/

and you will see the following screen:

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
How to Install OpenCart on Ubuntu 18.04
How to Install OpenCart on Ubuntu 18.04

Read the agreement and click ‘CONTINUE’ to proceed.

The next screen will display the pre-installation information to make sure your installation is set up as required.

How to Install OpenCart on Ubuntu 18.04
How to Install OpenCart on Ubuntu 18.04

Finally, you will be required to select a DB driver (in our case MySQL) and enter the database values that you created above as shown below. You will also need to create a username and a password for login to your OpenCart admin section.

How to Install OpenCart on Ubuntu 18.04
How to Install OpenCart on Ubuntu 18.04
How to Install OpenCart on Ubuntu 18.04
How to Install OpenCart on Ubuntu 18.04

Once you install OpenCart, you must remove the Install directory, however, you shouldn’t touch any other directories.

$ sudo rm -rf install/

How to Install OpenCart on Ubuntu 18.04

Congratulations. You have successfully installed OpenCart on your Ubuntu 18.04 VPS.

Of course, you don’t have to do any of this if you use one of our Linux VPS Hosting services, in which case you can simply ask our expert Linux admins to install OpenCart for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, please share it with your friends on the social networks using the share shortcuts below, or simply leave a comment in the comment section. Thanks.

1 thought on “How to Install OpenCart on Ubuntu 18.04”

Leave a Comment