Learn How To Install OpenCart On A LEMP Server

February 29, 2020

Table of Contents

OpenCart is a popular open source shopping cart solution designed to provide excellent functionality, ease of use, and appearance. With OpenCart, you can easily build an online store on a LAMP- or LEMP-based server.

In this tutorial, we will introduce how to install OpenCart on An ITWeb.Services LEMP server instance.

Before further reading, you need to:

  • Deploy a fresh server instance with the one-click IT Web Services LEMP App.
  • https://www.itweb.services/tutorials/linux-guides/how-to-use-sudo-on-debian-centos-and-freebsd”>sudo user from your SSH terminal.

Step 1: Setup a database for OpenCart

Find the default MySQL credentials of IT Web Services LEMP:

sudo cat /root/.my.cnf

Use the credentials displayed on the screen to log into MySQL:

mysql -u root -p

Create a database in the MySQL shell with the following commands. Be sure to replace the database name “opencart”, the user name “opencartuser”, and the password “opencartpassword” with your own ones.

CREATE DATABASE opencart;
CREATE USER 'opencartuser'@'localhost' IDENTIFIED BY 'opencartpassword';
GRANT ALL PRIVILEGES on *.* TO 'opencartuser'@'localhost' IDENTIFIED BY 'opencartpassword' WITH GRANT OPTION;
FLUSH PRIVILEGES;
EXIT;

Step 2: Download the OpenCart package

Download the latest stable version of OpenCart, which as of writing is 2.1.0.2, from its github repository:

cd ~
wget https://github.com/opencart/opencart/archive/2.1.0.2.tar.gz

Unzip the OpenCart package, delete the default files in your server’s Web directory, and then move necessary files into it:

tar -zxvf 2.1.0.2.tar.gz
cd /usr/share/nginx/html/
sudo rm background.jpg index.php logo.png
sudo cp -R ~/opencart-2.1.0.2/upload/* .

Step 3: Prepare the OpenCart installation files

Setup the configuration files:

sudo mv config-dist.php config.php
sudo mv admin/config-dist.php admin/config.php

Modify the ownership of each installation file:

sudo chown -R nginx:nginx ./*
sudo service nginx restart

Step 4: Install OpenCart from your browser

Visit http://[your-server-ip] from your browser to continue the installation.

First, click the “Continue” button to agree the license.

On the second screen, check server requirements for installing OpenCart. With An ITWeb.Services LEMP server instance configured as above, these requirements are already satisfied. Click the “Continue” button to move on.

On the third screen, input the database name, the database username, and the database password you have setup in step 1, then fill in a username, a password and an email address for administration. Click the “Continue” button to finish the installation.

Step 5: Some basic security practices

For security purposes, you should also perform the following instructions on your machine.

Delete the “install” directory:

sudo rm -r /usr/share/nginx/html/install

Rename the “admin” directory to a name which is hard to guess, like “c2tdfjk”:

sudo mv admin c2tdfjk

Modify the “config.php” file in the “c2tdfjk” directory, replace every instance of “admin” with “c2tdfjk”:

cd c2tdfjk
sudo sed -i "s/admin/c2tdfjk/g" config.php

In the future, you can only access your admin panel from “http://[your-server-ip]/c2tdfjk”.

Conclusion

Now, you can visit your new online store from “http://[your-server-ip]”. Enjoy it.

Need help?

Do you need help setting up this on your own service?
Please contact us and we’ll provide you the best possible quote!