In this guide, we will explore setting up Opencart in a Ubuntu 20.04 Server with Apache serving it and Mariadb10 acting as the database.
Opencart is an 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.
Related Content:
- How to Setup Opencart with LAMP (PHP, Apache, Mariadb) on OpenSUSE Leap 15.3
- How to Setup Opencart with LAMP (PHP, Apache, Mariadb) on Debian 11
- How to install and set up PHP and Apache(LAMP stack) on Ubuntu 20.04
- How to install and set up PHP and Apache(LAMP stack) on Debian 11
- How to install and Configure Mariadb 10 in Ubuntu 20.04
- How to install and Configure Mariadb 10 in Debian 11
- 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
Prerequisites
To follow along, ensure you have the following:
- An updated Ubuntu 20.04 Server
- Root access or user with sudo access
- Internet access
Ensure that the server is up to date
Before proceeding, it is always a good practice to ensure that the server is up to date. Use these commands to achieve this
|
|
Install some common packages that we will need later
|
|
Installing Mariadb in Ubuntu 20.04
Mariadb is a popular Opensource relational management system. It is available in the default repositories as mariadb-server
.
Install it with this command:
|
|
Mariadb will be installed and started by default in Ubuntu 20.04. Check the status with this
|
|
To ensure that mariadb starts on boot, enable it with this systemd command:
|
|
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 setting up mysql in this guide here.
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:
|
|
After Supplying your password, enter the following to the mysql prompt:
|
|
Now that we have configured our mysql connection, lets go to the next section where we install and configure PHP and Nginx.
Installing PHP in Ubuntu 20.04
Opencart works fine with PHP 7.4. To install php 7.4, we need to enable remi repository so we get the latest version.
Then install php and dependancies
|
|
For more info on setting up PHP and Apache, check out this guide here.
Installing apache on Ubuntu 20.04
Apache packages are available in the default Ubuntu 20.04 repositories as apache2
. Install it using this command:
|
|
Confirm the installed packages using this command:
|
|
The service will be started by default. Check the status using this command:
|
|
To enable the service on boot, use this command
|
|
To confirm that Apache is installed and working fine, please visit the server’s IP address in the browser ([http://server_ip][2]). If you don’t know the server IP, get it using this command in your terminal:
|
|
If all is well, you should see the Apache2 Ubuntu Default Page.
Setting up Opencart
After setting up mysql, php and apache, 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://opencart.citizix.com
. Since Apache serves content from /var/www/html
, I will create my sites directory in that /var/www
directory:
|
|
Make sure your web user has the permission to read, write and execute all directories under the site path:
|
|
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 3.0.3.8
.
Download it with this command:
|
|
Now that the file has been downloaded, we need to extract it. You need the zip command to extract it.
|
|
The content will be extracted to the upload
directory. Let’s move it to our site path with this command:
|
|
Rename config-dist.php
to config.php
and admin/config-dist.php
to admin/config.php
:
|
|
Create a virtual host to serve Opencart
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 http://opencart.citizix.com
.
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:
|
|
The Apache configurations will be stored in the directory /etc/httpd/conf.d/
. Lets create a config for our site:
|
|
Add the following content:
|
|
To apply the changes, please restart apache:
|
|
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 visit http://opencart.citizix.com
. You will get a welcome page, clicking continue you will need to accept terms then verify that the server has been set up as expected. If you installed the required php packages above you should see a green check for each of the items.
Finally you will get to the database configuration and admin user. Fill in the required details and click Continue.
If everything 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
|
|
Lets move the Storage directory and update configs:
|
|
Update the config files as seen in the screenshot.
Conclusion
From the above steps, we were able to set up Ubuntu 20.04 server to serve Opencart.