How to Setup Opencart with LAMP (PHP, Apache, Mariadb) on Debian 11

In this guide, we will explore setting up Opencart in a Debian 11 Server with Apache serving it and Mariadb10 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.

# Prerequisites

To follow along, ensure you have the following:

  • An updated Debian 11 Server
  • Root access or user with sudo access
  • Internet access

# Steps

We will execute this in the following steps:

  1. Ensure that the server is up to date
  2. Install and configure Mariadb 10 in Debian 11
  3. Creating mysql user for Opencart
  4. Install php in Debian 11
  5. Installing Apache on Debian 11
  6. Setting up Opencart in the server
  7. Create a virtual host to serve the Opencart
  8. Going through Opencart installation process

# 1. 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

sudo apt update
sudo apt upgrade -y

Install some common packages that we will need later

sudo apt install -y vim unzip

# 2. Installing Mariadb in Debian 11

Mariadb is a popular Opensource relational management system. It is available in the default repositories as mariadb-server.

Install it with this command:

sudo apt install -y mariadb-server

Mariadb will be installed and started by default in Debian 11. Check the status with this

$ sudo systemctl status mariadb
● mariadb.service - MariaDB 10.5.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Tue 2021-12-14 05:51:32 UTC; 26s ago
       Docs: man:mariadbd(8)
    Process: 20983 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 20984 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 20986 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq>
    Process: 21048 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 21050 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 21034 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 14 (limit: 4626)
     Memory: 78.3M
        CPU: 672ms
     CGroup: /system.slice/mariadb.service
             └─21034 /usr/sbin/mariadbd

Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21055]: mysql
Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21055]: performance_schema
Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21055]: Phase 6/7: Checking and upgrading tables
Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21055]: Processing databases
Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21055]: information_schema
Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21055]: performance_schema
Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21055]: Phase 7/7: Running 'FLUSH PRIVILEGES'
Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21055]: OK
Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21713]: Checking for insecure root accounts.
Dec 14 05:51:34 ip-10-2-40-188 /etc/mysql/debian-start[21720]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables

To ensure that mariadb starts on boot, enable it with this systemd command:

sudo systemctl enable mariadb

Once the mysql service is running, you need to secure it. Mysql provides a commandline utility that will do that:

sudo mysql_secure_installation

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

# 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 PHP and Nginx.

# 4. Installing PHP in Debian 11

Opencart works fine with PHP 7.4. This version is available in the default Debian repos.

Then install php and dependancies, use this command:

sudo apt install -y \
  php \
  php-cli \
  php-gd \
  php-curl \
  php-zip \
  php-dom \
  php-xml \
  php-simplexml \
  php-mbstring \
  php-intl \

For more info on setting up PHP and Apache, check out this guide here.

# 5. Installing apache on Debian 11

Apache packages are available in the default Debian 11 repositories as apache2. Install it using this command:

sudo apt install -y apache2

Confirm the installed packages using this command:

$ apt-cache policy apache2
  Installed: 2.4.51-1~deb11u1
  Candidate: 2.4.51-1~deb11u1
  Version table:
 *** 2.4.51-1~deb11u1 500
        500 bullseye-security/main amd64 Packages
        100 /var/lib/dpkg/status
     2.4.48-3.1+deb11u1 500
        500 bullseye/main amd64 Packages

The service will be started by default. Check the status using this command:

$ sudo 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-12-14 03:01:04 UTC; 5min ago
   Main PID: 19103 (apache2)
      Tasks: 6 (limit: 4626)
     Memory: 12.8M
        CPU: 59ms
     CGroup: /system.slice/apache2.service
             ├─19103 /usr/sbin/apache2 -k start
             ├─19105 /usr/sbin/apache2 -k start
             ├─19106 /usr/sbin/apache2 -k start
             ├─19107 /usr/sbin/apache2 -k start
             ├─19108 /usr/sbin/apache2 -k start
             └─19109 /usr/sbin/apache2 -k start

Dec 14 03:01:04 ip-10-2-40-188 systemd[1]: Starting The Apache HTTP Server...
Dec 14 03:01:04 ip-10-2-40-188 systemd[1]: Started The Apache HTTP Server.

To enable the service on boot, use this command

sudo systemctl enable apache2

To confirm that Apache is installed and working fine, please visit the server’s IP address in the browser (http://server_ip). If you don’t know the server IP, get it using this command in your terminal:

curl -4

If all is well, you should see the Apache2 Debian Default Page.

# 6. 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 Since Apache serves content from /var/www/html, I will create my sites directory in that /var/www directory:

sudo mkdir /var/www/

Make sure your web user has the permission to read, write and execute all directories under the site path:

sudo chown -R $USER:$GROUP /var/www/

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

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:

sudo mv upload/* /var/www/

Rename config-dist.php to config.php and admin/config-dist.php to admin/config.php:

cd /var/www/
mv config-dist.php config.php
mv admin/config-dist.php admin/config.php

# 7. 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

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

The Apache configurations will be stored in the directory /etc/httpd/conf.d/. Lets create a config for our site:

sudo vim /etc/apache2/sites-available/

Add the following content:

<VirtualHost *:80>
    ServerName <meta charset="utf-8">
    ServerAlias <meta charset="utf-8">
    DocumentRoot /var/www/<meta charset="utf-8">
    DirectoryIndex index.php
    ErrorLog /var/log/apache2/<meta charset="utf-8">
    CustomLog /var/log/<meta charset="utf-8">apache2/<meta charset="utf-8"> combined

To apply the changes, please restart apache:

sudo systemctl reload <meta charset="utf-8">apache2

# 8. 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, I am welcomed by this page:

Opencart Setup Step 1

Opencart Setup Step 1

The page above is asking you to accept the terms. Click Continue to go to the next page:

Opencart Setup Step 2 a

Opencart Setup Step 2 a
Opencart Setup Step 2 b

Opencart Setup Step 2 b

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:

Opencart Setup Step 3

Opencart Setup Step 3

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:

Opencart Setup Step 4

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/
rm -rf installation

Lets move the Storage directory and update configs as seen in this screenshot:

Opencart Move storage dir

Opencart Move storage dir

sudo mv /var/www/ /var/www/storage/

Update the config files as seen in the screenshot.

# Conclusion

From the above steps, we were able to set up Debian 11 server to serve Opencart.

comments powered by Disqus
Citizix Ltd
Built with Hugo
Theme Stack designed by Jimmy