• Get In Touch
May 31, 2017

How to Install OpenCart on CentOS 7

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

OpenCart is a free and open source e-commerce web application. It is written in PHP and uses MySQL to store its database. OpenCart is an alternative of Magento and has pretty much a similar set of features.

You can easily manage products, categories, customers, coupons and orders. It also has built-in SEO and multi-store feature that means you can easily manage multiple stores from a single admin interface. You can extend its features using thousands of themes and plugins available. It supports multiple payment gateways, product reviews and ratings, reward points. It is multilingual translated into more than 40 languages and supports multi-currency. More than 342,000 entrepreneurs use OpenCart to run their business.

In this tutorial, we will install OpenCart on CentOS 7 server.

Requirements

OpenCart does not require any special hardware requirements. All the required dependencies will be installed throughout the tutorial. You will need a minimal installation of CentOS 7 with root access on it. If you are logged in as a non-root user, you can run sudo -i to switch to root user.

Installing OpenCart

Before installing any package it is recommended that you update the packages and repository using the following command.

yum -y update

Once you have your system updated, you can proceed to install the LAMP stack. Start the LAMP installation by installing Apache web server and MariaDB, which is a fork of MySQL using the following command.

yum -y install httpd mariadb-server mariadb

OpenCart can be installed on any version of PHP greater than 5.4. Since PHP v5.4 has reached end of life, we will install PHP 7 for increased performance and security. PHP 7 is not included in default YUM repository, hence you will need to add the Webtatic repository in your system. Webtatic repository requires EPEL repository to work. Run the following command to install EPEL repository.

yum -y install epel-release
yum -y update

Now install Webtatic repository using the following commands.

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
yum -y update

To install PHP 7.1 and all the required PHP modules, run the following command.

yum -y install php71w php71w-curl php71w-mysqli php71w-cli php71w-zlib php71w-gd php71w-mcrypt php71w-mbstring php71w-xml

Once you have PHP installed, you can check the version of PHP using the following command.

php -v

You should get output similar to this.

[root@liptan-pc ~]# php -v
PHP 7.1.5 (cli) (built: May 12 2017 21:54:58) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2017 Zend Technologies

Now start Apache web server and enable it to start at boot time using the following command.

systemctl start httpd
systemctl enable httpd

To start MariaDB and enable it to start at boot time using the following commands.

systemctl start mariadb
systemctl enable mariadb

Now run the following commands to secure your MySQL or MariaDB installation.

mysql_secure_installation

It will run a small script which asks you to provide the root password for MariaDB. As we have just installed MariaDB, the root password is not set, just press enter to proceed further. It will ask you if you want to set a root password for your MariaDB installation, choose y and set a strong password for the installation. It will also ask you for removing test databases and anonymous users. Most of the questions are self-explanatory and you should answer yes or y to all the questions.

To create a database we will need to login to MySQL command line first. Run the following command for same.

mysql -u root -p

This will prompt you for the password, provide the root password of MySQL which you have set earlier. Now run the following query to create a new database for your OpenCart installation.

CREATE DATABASE ocart_data;

The above query will create a database named ocart_data. Make sure that you use semicolon at the end of each query as the query always ends with a semicolon. Once the database is created you can create a new user and grant all the permissions to the user for the database. Using root user is not recommended for the databases. To create a new database user, run the following query.

CREATE USER 'ocart_user'@'localhost' IDENTIFIED BY 'StrongPassword';

The above query will create a user with username ocart_user. You can use any preferred username instead of ocart_user. Replace StrongPassword with a strong password. Now provide the appropriate privileges to your database user over the database you have created. Run the following command.

GRANT ALL PRIVILEGES ON ocart_data.* TO 'ocart_user'@'localhost';

Now run the following command to immediately apply the changes on the database privileges.

FLUSH PRIVILEGES;

Exit from MySQL prompt using exit command.

As we have all the dependencies ready, we can now download the install package from OpenCart website.

cd /var/www
wget https://github.com/opencart/opencart/releases/download/2.3.0.2/2.3.0.2-compiled.zip -O opencart.zip

You can always find the link to the latest version of the application on OpenCart download page. Extract the archive using the following command.

unzip opencart.zip -d opencart

If you don’t have unzip installed, you can run yum -y install unzip.

You will also need to rename the configuration files. Run the following commands for same.

mv /var/www/opencart/upload/config-dist.php /var/www/opencart/upload/config.php

mv /var/www/opencart/upload/admin/config-dist.php /var/www/opencart/upload/admin/config.php

Now you will need to create a virtual host for your web application. Run the following command for same.

nano /etc/httpd/conf.d/shop.yourdomain.com.conf

Paste the following lines into the file.

<VirtualHost *:80>
    ServerAdmin me@liptanbiswas.com
    DocumentRoot "/var/www/opencart/upload"
    ServerName shop.yourdomain.com
    ServerAlias www.shop.yourdomain.com
    <Directory "/var/www/opencart/upload">
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        Allow from all
        Require all granted
    </Directory>
    ErrorLog "/var/log/httpd/shop.yourdomain.com-error_log"
    CustomLog "/var/log/httpd/shop.yourdomain.com-access_log" combined
</VirtualHost>

Replace shop.yourdomain.com with any domain or subdomain you want to use to access the application. Save the file and exit from the editor. Run the following command to restart your Apache server.

systemctl restart httpd

Now you will need to provide the ownership of the application to web server user using the following command.

cd /var/www
chown -R apache:apache /var/www/opencart

You may also need to allow HTTP traffic on port 80 through the firewall if you are running one. Run the following commands to do so.

firewall-cmd --zone=public --permanent --add-service=http
firewall-cmd --reload

You will also need to disable SELinux. To temporary disable SELinux without restarting the server, run the following command.

setenforce 0

To completely disable the SELinux you will need to edit /etc/selinux/config file.

nano /etc/selinux/config

Find the following line:

SELINUX=enforcing

Change it to:

SELINUX=disabled

Now complete the installation using a web browser, go to the following link using your favourite web browser.

http://shop.yourdomain.com

You will see the following page.

HP_NO_IMG/data/uploads/users/96ef1f90-83ed-46f0-9b58-aa6ee50a1451/791273242.png” alt=”” />

Click Continue button to proceed further. In next interface, the installer will check if your system meets all the requirements to install OpenCart. If you have followed the tutorial correctly, then you will have all the requirements satisfied.

HP_NO_IMG/data/uploads/users/96ef1f90-83ed-46f0-9b58-aa6ee50a1451/1205768858.png” alt=”” />

Click Continue button to proceed further. In next interface, you will need to provide database and administrator details.

HP_NO_IMG/data/uploads/users/96ef1f90-83ed-46f0-9b58-aa6ee50a1451/83526459.png” alt=”” />

Choose the database driver as MySQLi. Provide username, password and database name which you have created earlier. Leave the default value in hostname, port and prefix text box. Provide administrator username, password and email. Click Continue button to proceed further.

OpenCart is now installed, before accessing the admin panel, you are required to delete the install folder. Run the following command for same.

rm -rf /var/www/opencart/upload/install

You can now access the shop’s front end at the following URL:

http://shop.yourdomain.com

You will see the following site.

HP_NO_IMG/data/uploads/users/96ef1f90-83ed-46f0-9b58-aa6ee50a1451/470044280.png” alt=”” />

To access the administration dashboard, go to the following link.

http://shop.yourdomain.com/admin

HP_NO_IMG/data/uploads/users/96ef1f90-83ed-46f0-9b58-aa6ee50a1451/608715451.png” alt=”” />

Conclusion

In this tutorial, we have learned to install OpenCart on CentOS 7 server. You can now use OpenCart to sell your goods online to people of a large area. It will increase the sales and profit.

Want your very own server? Get our 1GB memory, Xeon V4, 25GB SSD VPS for £10.00 / month.
Get a Cloud Server

Share this Article!

Related Posts

Node.js Authentication – A Complete Guide with Passport and JWT

Node.js Authentication – A Complete Guide with Passport and JWT

Truth be told, it’s difficult for a web application that doesn’t have some kind of identification, even if you don’t see it as a security measure in and of itself. The Internet is a kind of lawless land, and even on free services like Google’s, authentication ensures that abuses will be avoided or at least […]

Node.js and MongoDB: How to Connect MongoDB With Node

Node.js and MongoDB: How to Connect MongoDB With Node

MongoDB is a document-oriented NoSQL database, which was born in 2007 in California as a service to be used within a larger project, but which soon became an independent and open-source product. It stores documents in JSON, a format based on JavaScript and simpler than XML, but still with good expressiveness. It is the dominant […]

Using MySQL with Node.js: A Complete Tutorial

Using MySQL with Node.js: A Complete Tutorial

Although data persistence is almost always a fundamental element of applications, Node.js has no native integration with databases. Everything is delegated to third-party libraries to be included manually, in addition to the standard APIs. Although MongoDB and other non-relational databases are the most common choice with Node because if you need to scale an application, […]

Node.Js Vs Django: Which Is the Best for Your Project

Node.Js Vs Django: Which Is the Best for Your Project

Django and NodeJs are two powerful technologies for web development, both have great functionality, versatile applications, and a great user interface. Both are open source and can be used for free. But which one fits your project best? NodeJs is based on JavaScript, while Django is written in Python. These are two equally popular technologies […]

Nodejs Vs PHP:  Which Works Best?

Nodejs Vs PHP: Which Works Best?

Before getting into the “battle” between Node.js and PHP we need to understand why the issue is still ongoing. It all started with the increased demand for smartphone applications, their success forcing developers to adapt to new back-end technologies that could handle a multitude of simultaneous requests. JavaScript has always been identified as a client-side […]