In this guide, we will explore setting up Opencart in a Centos 8 Server with Apache serving it and Mysql 8 acting as the database.
Opencart is a FREE and open-source eCommerce platform. Everything you need to create, scale and run your business”. It is an Open Source online store management system. It is PHP-based, using a MySQL database and HTML components.
Apache is a popular web web server software that is often used to serve php content. Mysql is also a popular relational management system used by popular websites.
- How to Setup Opencart with LAMP (PHP, Apache, Mariadb) on Debian 11
- How to Setup Opencart with LAMP (PHP, Apache, Mariadb) on Ubuntu 20.04
- Installing and Configuring Mysql Server 8 on Centos 8
- Mysql Permissions – Create, Update, Delete Database Users
- Install Apache PHP 7.4 (LAMP) stack on Centos 8
- How to install and Enable Remi Repository in Centos 6/7/8
To follow along, ensure you have the following:
- An updated Rocky Linux 8 Server
- Root access or user with sudo access
- Internet access
Table of Content
We will execute this in the following steps:
- Ensuring the server is up to date
- Install and configure mysql
- Creating mysql user for opencart
- Install and configure Apache and php
- Copying the Opencart content to the server
- Create a virtual host to serve the content
- Going through Opencart installation process
1. Ensuring the server is up to date
Ensure the server packages are up to date using this command:
sudo dnf -y update
2. Install and configure mysql
Mysql is a popular relational managementn system. It is available in the default repositories as
Install it with this command:
sudo dnf install mysql-server
You will need to start and enable to ensure its always started when the server starts.
sudo systemctl start mysql sudo systemctl status mysqld
Once the mysql service is running, you need to secure it. Mysql provides a commandline utility that will do that:
The above command will take you throuh prompts to secure and set a root password for the mysql instance.
Check more info on Installing and settingn up mysql in this guide here
3. Creating mysql user for opencart
It is always recommended to have a dedicated user for each app that connects to the DB. Check out this guide on managing mysql permissions here. We will set up a database, user and password to be used by opencart:
Connect to mysql server:
mysql -u root -p
After Supplying your password, enter the following to the mysql prompt:
create database opencart; create user 'opencart_user'@'%' identified by 'S0mStrongPa$word'; grant all privileges on opencart.* to 'opencart_user'@'%';
Now that we have configured our mysql connection, lets go to the next section where we Install and configure Apache and php.
4. Install and configure Apache and php
We need Apache and php to serve the Opencart Site. Apache is available in the default repositories. Install it with this command:
sudo dnf install httpd
Since the service will not be stared by default, we need to start and enable it using this command:
sudo systemctl start httpd sudo systemctl enable httpd
Confirm that its running using this command. You should see
sudo systemctl status httpd
To install php, we need to enable remi repository so we get the latest version. Opencart works with PHP 7.3 and above. Lets install php 7.4.
Enable Remi repo with this command:
sudo dnf install dnf-utils http://rpms.remirepo.net/enterprise/remi-release-8.rpm
Enable php 7.4:
sudo dnf module enable php:remi-7.4
Then install php and dependancies
sudo dnf install -y php php-mysqlnd php-gd php-zip
5. Copying the Opencart content to the server
After setting up mysql and php, we need to download the Opencart Installation file and set it in the server. We need to create a directory in the server where the content will be hosted.
I am going to be setting up Opencart to be served from the domain
http://site1.citizix.com. Since Apache serves content from
/var/www/html, I will create my sites directory in that
Now lets download and extract Opencart content. Opencart uses github to track its releases. Head over to github releases page for Opencart here and grab the latest release. As of the writting of this article, the latest version is
Download it with this command:
curl -LO https://github.com/opencart/opencart/releases/download/184.108.40.206/opencart-220.127.116.11.zip
Now that the file has been downloaded, we need to extract it. You need the zip command to extract it.
# Install the zip command if you don't have it already sudo dnf install -y unzip unzip opencart-18.104.22.168.zip
The content will be extracted to the
upload directory. Let’s move it to our site path with this command:
sudo mv upload/* /var/www/site1.citizix.com/
Make sure your web user has the permission to read, write and execute all directories under the site path:
sudo chown -R apache.apache /var/www/site1.citizix.com
Rename config-dist.php to config.php and admin/config-dist.php to admin/config.php:
cd /var/www/site1.citizix.com/ mv config-dist.php config.php mv admin/config-dist.php admin/config.php
6. Create a virtual host to serve the content
Now that the software packages required has been installed and the Opencart content has been copied, we need an Apache virtual host to serve the content for our site
Apache Virtual host files specifies the configuration of each sites and tell the Apache web server how to respond to various domain requests.
Please note that the DNS for the domainto be used should already be configured to point to the IP address of the server.
Confirm that with:
dig -t A site1.citizix.com
The Apache configurations will be stored in the directory
/etc/httpd/conf.d/. Lets create a config for our site:
sudo vim /etc/httpd/conf.d/site1.citizix.com.conf
Add the following content:
<VirtualHost *:80> ServerName site1.citizix.com ServerAlias site1.citizix.com DocumentRoot /var/www/site1.citizix.com DirectoryIndex index.php ErrorLog /var/log/httpd/site1.citizix.com.error.log CustomLog /var/log/httpd/site1.citizix.com.requests.log combined </VirtualHost>
To apply the changes, please restart apache:
sudo systemctl restart httpd
7. Going through Opencart installation process
Once the above set up is done, we should be ready to start installing opencart. Visit the url defined in the virtual host above to initiate the set up process. In my case when I visir http://site1.citizix.com, I am welcomed by this page:
The page above is asking you to accept the terms. Click Continue to go to the next page:
The above step is to verify that the server is set up as expected. If you installed the required php packages above you should see a green check for each of the items.
Click Continue to go to the next step:
The step above is where you set up your database configuration and admin user. Fill in the required details and click Continue.
If everuthing is Ok, you will be taken to the final step which tells you that the installation was successful:
Up to this point Opencart is set up and ready to use.
Final set up
Lets remove the installation directory in the server as recommended by that warning in the last page
cd /var/www/site1.citizix.com/ rm -rf installation
Lets move the Storage directory and update configs as seen in this screenshot:
sudo mv /var/www/site1.citizix.com/system/storage/ /var/www/storage/
Update the config files as seen in the screenshot.
From the above steps, we were able to set up Rocky Linux 8 server to serve Opencart.