How To Install OpenCart on an Ubuntu 12.04 VPS
This article covers a version of Ubuntu that is no longer supported. If you are currently operate a server running Ubuntu 12.04, we highly recommend upgrading or migrating to a supported version of Ubuntu:
- Upgrade to Ubuntu 14.04.
- Upgrade from Ubuntu 14.04 to Ubuntu 16.04
- Migrate the server data to a supported version
Reason: Ubuntu 12.04 reached end of life (EOL) on April 28, 2017 and no longer receives security patches or updates. This guide is no longer maintained.
This guide might still be useful as a reference, but may not work on other Ubuntu releases. If available, we strongly recommend using a guide written for the version of Ubuntu you are using. You can use the search functionality at the top of the page to find a more recent version.
OpenCart is an widely used Open Source E-Commerce CMS which uses PHP & MySQL. It has its own Psuedo MVC structure and it is easier to handle and faster to setup. More information can be seen on OpenCart site.
This tutorial require the user to have root privileges. You can check that here: Initial Server Setup. Before working with OpenCart, you need to have LAMP installed on your VPS. If you don't have it, then you can install it by following this tutorial: Installing LAMP Stack.
Once we have the above requirements, we can start with the OpenCart installation.
Step One: Download OpenCart
First, we will navigate to the root folder where OpenCart will be installed. To do this, open the terminal and type in the following command:
Then we will download the latest release of OpenCart (v18.104.22.168) from the github repo:
sudo wget https://github.com/opencart/opencart/archive/v22.214.171.124.zip
ls command, you will find the v126.96.36.199.zip file in your www directory.
Now to unzip this folder, we will need to have Unzip module installed. In case you don't have it, you can install it by inputting:
sudo apt-get install unzip
Now we will unzip this downloaded OpenCart zip file in the current directory:
If you traverse the directory of extracted OpenCart folder, you will find the upload folder inside. We have to move the files & folders present in
uploads folder into the root
www folder. The next command will do that for us:
mv -v /var/www/opencart-188.8.131.52/upload/* /var/www
You can now find all the core files & folders of OpenCart directly sitting in your root www folder.
Step Two: Create Database for OpenCart
We will need to create a database which will be required during OpenCart Installation.
Log into your MySQL shell by command:
mysql -u root -p
Let's create the database first (I'm setting my database name as opencart, but you can choose whatever name you want):
CREATE DATABASE opencart; Query OK, 1 row affected (0.00sec)
In next steps, we will create a new database user with a password and grant access to the opencart database created above. Run the following commands carefully and keep noting down the username & password you choose.
Create database user:
CREATE USER opencartuser@localhost; Query OK, 0 rows affected (0.00 sec)
Set password for this user:
SET PASSWORD FOR opencartuser@localhost= PASSWORD("yourpassword"); Query OK, 0 rows affected (0.00 sec)
Grant this new user permission to access the opencart database:
GRANT ALL PRIVILEGES ON opencart.* TO opencartuser@localhost IDENTIFIED BY 'yourpassword'; Query OK, 0 rows affected (0.00 sec)
Then we refresh MySQL so that the changes are effective:
FLUSH PRIVILEGES; Query OK, 0 rows affected (0.00 sec)
We are done with Database part, So now, we can log out of the MySQL Shell:
Step Three: Renaming Config Files and Giving Ownership to Apache User
Now we need to rename the OpenCart config files from
config.php. There are two such files: one in the direct
www folder and one inside the
cp /var/www/config-dist.php /var/www/config.php
cp /var/www/admin/config-dist.php /var/www/admin/config.php
We will give the ownership of our opencart files to the apache user by running the following command:
sudo chown www-data:www-data * -R sudo usermod -a -G www-data username
Step Four: Almost Done
You are good to go. Simply hit your IP Address in browser (http://198.102.*.*/) to access the installation screen. After accepting the terms and conditions, you should see a screen similar to this:
All green indicates you are good to go ahead. In some cases, it might say that cURL & GD are not installed. It simply means that these php5 libraries are not installed on your VPS. You can install these libraries by running this simple command:
sudo apt-get install php5-curl php5-gd
Then you can refresh the page again and you should find the status against cURL & GD changed. On the third step, you will be asked to enter the database credentials we created above and then you are done :)
Once you have installed OpenCart, it is good practice and necessary from a security point of view to delete your install folder. We should be careful that only the install folder is to be deleted and not admin, catalog, or system folders. You can use the following command.
rm -rf /var/www/install/
Congratulations! You have just setup your own e-commerce site using OpenCart!