How To Install OpenCart on an Ubuntu 12.04 VPS
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 (v188.8.131.52) from the github repo:
sudo wget https://github.com/opencart/opencart/archive/v184.108.40.206.zip
ls command, you will find the v220.127.116.11.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-18.104.22.168/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!