How to Install OpenCart on Ubuntu 20.04

Install OpenCart on Ubuntu 20.04

In this article, we will have explained the necessary steps to install and configure OpenCart on Ubuntu 20.04 LTS. Before continuing with this tutorial, make sure you are logged in as a user with sudo privileges. All the commands in this tutorial should be run as a non-root user.

OpenCart is a free and open-source PHP-based e-commerce platform that combines useful and powerful features along with a user-friendly user interface. The platform makes it easy to manage products, orders, and users in a seamless manner. In addition, it comes packed with handy plugins that extend the platform’s functionality.

Install OpenCart on Ubuntu 20.04

Step 1. First, before you start installing any package on your Ubuntu server, we always recommend making sure that all system packages are updated.

sudo apt update
sudo apt upgrade

Step 2. Install LAMP Stack.

OpenCart is built with PHP. You can host it like you would any other web app is written in PHP. So, you’re going to need to set Ubuntu up as either a LAMP server. If you haven’t done so already, use our traditional LAMP guide.

Step 3. Download and Install OpenCart on the Ubuntu system.

Now we need to download the OpenCArt zipped file. First, navigate to /tmp directory:


Once downloaded, unzip the OpenCart zip file:

mv upload/ /var/www/html/opencart

After that, using the cp command, copy the configuration files:

cp /var/www/html/opencart/config-dist.php /var/www/html/opencart/config.php
cp /var/www/html/opencart/admin/config-dist.php /var/www/html/opencart/admin/config.php

Next, change the permission of OpenCArt folder to Apache’s www-data user and group, for that the syntax will be:

chmod -R 755 /var/www/html/opencart/
chown -R www-data:www-data /var/www/html/opencart/

Step 4. Creating a MariaDB database for OpenCart.

OpenCart uses the MariaDB database to store all its data. Log in to your MariaDB server with the following command and enter your MariaDB root password:

mysql -u root -p

Once you’re in the MariaDB console, create a new database:

MariaDB [(none)]> CREATE DATABASE opencartdb;
MariaDB [(none)]> CREATE USER 'opencartuser'@'localhost' IDENTIFIED BY 'Your-Strong-Password';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON opencartdb . * TO 'opencartuser'@'localhost';
MariaDB [(none)]> exit;

Step 5. Configuring Apache for OpenCart.

We are going to create a virtual host file for OpenCart:

nano /etc/apache2/sites-available/opencart.conf

And add the following content to the file:

<VirtualHost *:80>    
      ServerAdmin [email protected]
      DocumentRoot /var/www/html/opencart/upload/

      ErrorLog ${APACHE_LOG_DIR}/error.log
      CustomLog ${APACHE_LOG_DIR}/access.log combined

      <Directory /var/www/html/opencart/upload/>
         Options FollowSymlinks
         AllowOverride All
         Require all granted

For the new configuration to take effect, restart the Apache service by typing:

sudo a2ensite opencart.conf 
sudo a2enmod rewrite
sudo systemctl restart apache2

Step 5. Completing the OpenCart Installation.

You can now open your favorite web browser and enter the domain, you should see the OpenCart setup wizard complete. Please follow the wizard carefully:

That’s all you need to do to install OpenCart on Ubuntu 20.04 LTS Focal Fossa. I hope you find this quick tip helpful. For further reading on the OpenCart open source PHP-based online e-commerce solution, please refer to their official knowledge base. If you have questions or suggestions, feel free to leave a comment below.