A lot of people dream about running their own store, or may be they already have a store but want to expand on that by offering their products online. Having the ability to offer your products to the world is what most companies are doing today, so if you are thinking of launching an online store, then OpenCart is one of the most used eCommerce platforms available to make this dream a reality. Follow this tutorial on How to install OpenCart on Debian.
It always seems impossible until its done.
Nelson Mandela
Table of Contents
Requirements
- You will need a Virtual Private Server from a reliable provider like Sebae
- Your OS should be the latest Debian release, currently 11
- You will need root access to the server
We always advise keeping to the latest Debian release, this will also ensure your servers are secure as possible. Running an online store also means you will be taking customer information such as names and addresses, it is therefore your responsibility to ensure the data is kept safe.
You can follow our tutorial on how to keep Debian automatically updated.
Before You Begin
Login to your VPS as root, and get the OS up to date.
apt update && apt upgrade
let the process run, once finished Debian should be ready.
Step 1: Install Apache for OpenCart on Debian
First of all, we need to download and install the Apache Web Server, this will be serving the OpenCart web pages to you and your customers.
apt install apache2 apache2-utils
During the install process, apt will prompt to continue, if you are happy please enter ‘Y‘
Once complete, lets verify Apache is running with the following command;
systemctl status apache2
The output should be similar as below
root@debtraining:~# systemctl status apache2
* apache2.service - The Apache HTTP Server
Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2021-10-26 20:47:21 UTC; 42s ago
Docs: https://httpd.apache.org/docs/2.4/
Main PID: 12485 (apache2)
Tasks: 55 (limit: 38054)
Memory: 4.9M
CPU: 48ms
CGroup: /system.slice/apache2.service
|-12485 /usr/sbin/apache2 -k start
|-12486 /usr/sbin/apache2 -k start
`-12487 /usr/sbin/apache2 -k start
Oct 26 20:47:21 debtraining systemd[1]: Starting The Apache HTTP Server...
Oct 26 20:47:21 debtraining systemd[1]: Started The Apache HTTP Server.
You can also verfiy Apache is accessible by entering the URL of your server like this
http://IP_Server_Address
If everything is looking like the above then Apache is now installed and running.
Step 2: Install PHP & Extensions for OpenCart on Debian
Now we have Apache up and running, we need to install PHP & the extensions needed to run OpenCart on Debian. To do this run the following command
apt-get install php-common php-cli php-fpm php-opcache php-gd php-mysql php-curl php-intl php-xsl php-mbstring php-zip php-bcmath php-soap unzip libapache2-mod-php
Once the installer has finished downloading and installing PHP, you may see the following
As the message suggests, we need to run a2enconf php7.4-fpm to enable this extension
a2enconf php7.4-fpm
Then lets restart Apache to load the new config
systemctl reload apache2
Now, using a text editor, lets edit the php.ini file to support OpenCart. The defaults will not be suitable and will cause errors. To do this run this command:
nano /etc/php/7.4/fpm/php.ini
Find the following lines and change them to match as follows
max_execution_time = 300
Mmemory_limit = 256
upload_max_filesize = 200M
opcache.save_comments=1
date.timezone = Europe/London
Once complete, save the file and exit.
Step 3: Installing MariaDB for OpenCart on Debian
Now we have Apache running with PHP, the next step is to install the database on MariaDB that will run OpenCart. MariaDB is an easy to use database engine and most of all, its free to use.
To install MariaDB run the following command:
apt install mariadb-server mariadb-client
You can check MariaDB is running by running the following command
systemctl status mariadb
Now we need to secure the MariaDB installation. To do this run the following command:
mysql_secure_installation
You will be asked a series of questions, our recommendation is to set a complex password, remove the test database and the anonymous users. We also stronly advise disallowing root remote login.
Once you have completed securing MariaDB, its now time to create the database used by OpenCart.
Login to MariaDB as root by issuing the following command:
mysql -u root -p
Now create a new database:
CREATE DATABASE opencartdatabase;
Now we have to create a new user which will be used to access the database by OpenCart, then we need to grant access to this user. To do this run the following commands:
CREATE USER 'opencart'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON opencartdatabase . * TO 'opencart'@'localhost';
The first command will create a new user called opencart with a password (you must change password to your own strong password).
The second command will then grant all privileges to the opencartdatabase for the user opencart.
Next type the following to exit:
exit;
Step 3: Download And Install OpenCart
Now we have MariaDB and Apache set up, we can now download OpenCart and extract the contents to a folder.
To download OpenCart, run the following commands:
cd /tmp
wget https://github.com/opencart/opencart/releases/download/3.0.3.8/opencart-3.0.3.8.zip
Now lets extract the contents of the file by running the following:
unzip opencart-3.0.3.8.zip
Now lets move the new folder to the Apache webroot directory by running the following:
mv upload /var/www/html/opencart
Next we need to copy the sample config files for OpenCart so that OpenCart can read them, to do this run the following:
cp /var/www/html/opencart/config-dist.php /var/www/html/opencart/config.php
cp /var/www/html/opencart/admin/config-dist.php /var/www/html/opencart/admin/config.php
Next lets allow Apache access to the files:
chown -R www-data:www-data /var/www/html/opencart/
chmod -R 775 /var/www/html/opencart/
Now we can finally load the OpenCart URL in a browser and finish off the configuration:
http://yourserverIP/opencart/install/index.php
You should now be presented with the installer screen which will allow to us to complete the OpenCart on Debian installation
Click continue, and you will be presented with a list of pre-installation requirements. With the work we have just done, all of the status messages should be green
Now click continue. Next we need to fill out the database details that OpenCart will use to make the connection to the MariaDB database we just created.
Hostname = localhost
username = opencart
Password = the password you set in the previous step
Database = opencartdatabase
Leave the port as 3306 and also leave the Prefix as oc_
You now need to create your username and password that will be used to login to the admin portal of OpenCart. We suggest admin and a strong password. Be sure to set a valid email address incase you forget your password.
Now click continue and you are set.
We next need to remove the install folder for security reasons, to do this run the following command within SSH:
rm -rf /var/www/html/opencart/install
To access your OpenCart shop, go to the URL: http://IP_address/opencart/
To access the admin portal, go to the URL: http://IP_address/opencart/admin/
Step 4: Move The OpenCart Storage Directory
When you login to the admin portal, you will be prompted to move the storage folder outside of the main OpenCart folder, this is for security reasons.
From the drop down, choose Manually Move and it will give you instructions on what to do.
Within SSH do the following:
mv /var/www/html/opencart/system/storage/ /var/storage/
Change the following line:
define('DIR_STORAGE', DIR_SYSTEM . 'storage/');
So it looks like this:
define('DIR_STORAGE', '/var/storage/');
Now edit the admin config file and do the same:
vi /var/www/html/opencart/admin/
Once again change the following line:
define('DIR_STORAGE', DIR_SYSTEM . 'storage/');
so it looks like this:
define('DIR_STORAGE', '/var/storage/');
Step 5: Start Adding Products to OpenCart
The installation is now complete. We suggest you have a look around in the admin portal and familiarise yourself with the different menus.
OpenCart is very flexiable, and you can add themes to your shop to make it look more like your brand. There are demo products already added to the store for you to look at and edit. Once you get used to how it works you will be able to add your own categories and products.
Now you have learned how to install OpenCart on Debian.
You can view more information on OpenCart at the official website