How to Setup Opencart with LAMP (PHP, Apache, Mariadb) on OpenSUSE Leap 15.3

In this guide, we will explore setting up Opencart in a OpenSUSE Leap Server with Apache serving it and Mariadb 10 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.

Prerequisites

To follow along, ensure you have the following:

  • An updated OpenSUSE Leap Server
  • Root access or user with sudo access
  • Internet access

Table of Content

We will execute this in the following steps:

  1. Ensure that the server is up to date
  2. Install and configure Mariadb 10 in OpenSUSE Leap 15.3
  3. Creating mysql user for Opencart
  4. Install php in OpenSUSE Leap 15.3
  5. Installing Apache on OpenSUSE Leap 15.3
  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 zypper refresh
sudo zypper update -y

Install some common packages that we will need later

sudo zypper install -y vim unzip

2. Installing Mariadb in OpenSUSE Leap 15.3

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

Install it with this command:

sudo zypper install -y mariadb

Once mariadb is installed, you can confirm the details using this command:

~> zypper info mariadb
Loading repository data...
Reading installed packages...


Information for package mariadb:
--------------------------------
Repository     : Update repository with updates from SUSE Linux Enterprise 15
Name           : mariadb
Version        : 10.5.13-3.12.1
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 138.2 MiB
Installed      : Yes
Status         : up-to-date
Source package : mariadb-10.5.13-3.12.1.src
Summary        : Server part of MariaDB
Description    :
    MariaDB is an open-source, multi-threaded, relational database management
    system. It's a backward compatible, drop-in replacement branch of the
    MySQL Community Server.

    This package only contains the server-side programs.

The Service will not be started by default. Start with this command:

sudo systemctl start mariadb

Confirm the status with this command:

~> sudo systemctl status mariadb
● mariadb.service - MariaDB database server
     Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
     Active: active (running) since Mon 2021-12-20 09:39:18 UTC; 55s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 27806 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper install (code=exited, status=0/SUCCESS)
    Process: 27854 ExecStartPre=/usr/lib/mysql/mysql-systemd-helper upgrade (code=exited, status=0/SUCCESS)
   Main PID: 27860 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 17 (limit: 4587)
     CGroup: /system.slice/mariadb.service
             └─27860 /usr/sbin/mysqld --defaults-file=/etc/my.cnf --user=mysql

Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: See the MariaDB Knowledgebase at https://mariadb.com/kb or the
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: MySQL manual for more instructions.
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: Please report any problems at https://mariadb.org/jira
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: The latest information about MariaDB is available at https://mariadb.org/.
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: You can find additional information about the MySQL part at:
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: https://dev.mysql.com
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: Consider joining MariaDB's strong and vibrant community:
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27812]: https://mariadb.org/get-involved/
Dec 20 09:39:18 ip-10-2-40-44 mysql-systemd-helper[27860]: 2021-12-20  9:39:18 0 [Note] /usr/sbin/mysqld (mysqld 10.5.13-MariaDB) starting as process 27860 ...
Dec 20 09:39:18 ip-10-2-40-44 systemd[1]: Started MariaDB database server.

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 How to install and Configure Mariadb 10 in OpenSUSE Leap 15.3.

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 7.4 in OpenSUSE Leap 15.3

NextCloud works fine with PHP 7.4. This version is available in the default OpenSUSE repos.

Then install php and dependancies

sudo zypper install -y \
  php \
  php-gd \
  php-curl \
  php-zip \
  php-dom \
  php-xml \
  php-simplexml \
  php-mbstring \
  php-intl \
  php-json \
  php-fpm

For more info on setting up PHP and Apache, check out this guide on How to install and set up PHP and Apache(LAMP stack) on OpenSUSE Leap 15.3.

3. Installing apache on OpenSUSE Leap 15.3

Apache packages are available in the default OpenSUSE Leap 15.3 repositories as apache2. Install it using this command:

sudo zypper install -y apache2

Confirm the installed packages using this command:

~> zypper info apache2
Loading repository data...
Reading installed packages...


Information for package apache2:
--------------------------------
Repository     : Update repository with updates from SUSE Linux Enterprise 15
Name           : apache2
Version        : 2.4.43-3.32.1
Arch           : x86_64
Vendor         : SUSE LLC <https://www.suse.com/>
Installed Size : 4.3 MiB
Installed      : Yes
Status         : up-to-date
Source package : apache2-2.4.43-3.32.1.src
Summary        : The Apache Web Server
Description    :
    This version of httpd is a major release of the 2.4 stable branch,
    and represents the best available version of Apache HTTP Server.
    New features include Loadable MPMs, major improvements to OCSP support,
    mod_lua, Dynamic Reverse Proxy configuration, Improved Authentication/
    Authorization, FastCGI Proxy, New Expression Parser, and a Small Object
    Caching API.

     See /usr/share/doc/packages/apache2/, http://httpd.apache.org/, and
    http://httpd.apache.org/docs-2.4/upgrading.html.

The service will no tbe started by default.

sudo systemctl start apache2

Check the status using this command:

~> sudo systemctl status apache2
● apache2.service - The Apache Webserver
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; disabled; vendor preset: disabled)
     Active: active (running) since Wed 2021-12-22 06:58:45 UTC; 53s ago
   Main PID: 27333 (httpd-prefork)
     Status: "Processing requests..."
      Tasks: 6
     CGroup: /system.slice/apache2.service
             ├─27333 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache>
             ├─27340 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache>
             ├─27341 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache>
             ├─27342 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache>
             ├─27343 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache>
             └─27344 /usr/sbin/httpd-prefork -DSYSCONFIG -C PidFile /var/run/httpd.pid -C Include /etc/apache2/sysconfig.d//loadmodule.conf -C Include /etc/apache2/sysconfig.d//global.conf -f /etc/apache>

Dec 22 06:58:45 ip-10-2-40-44 systemd[1]: Starting The Apache Webserver...
Dec 22 06:58:45 ip-10-2-40-44 systemd[1]: Started The Apache Webserver.

To enable the service on boot, use this command

sudo systemctl enable apache2

If you have a firewalld installed and enabled on your machine, remember to allow traffic to the Apache2 web server via the firewall before going to the next step.

$ sudo firewall-cmd --permanent --add-port=80/tcp
$ sudo firewall-cmd --permanent --add-port=443/tcp
$ sudo firewall-cmd --reload

For Apache to serve php files

sudo zypper install -y apache2-mod_php7

Then enable the php7 module

sudo a2enmod php7

Finally restart apache2 to apply the module addition

sudo systemctl restart apache2

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 http://opencart.citizix.com. Since Apache serves content from /srv/www/htdocs, I will create my sites directory in that /srv/www directory:

sudo mkdir /srv/www/opencart.citizix.com

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

sudo chown -R wwwrun:wwwrun /srv/www/opencart.citizix.com

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:

curl -LO https://github.com/opencart/opencart/releases/download/3.0.3.8/opencart-3.0.3.8.zip

Now that the file has been downloaded, we need to extract it. You need the zip command to extract it.

unzip opencart-3.0.3.8.zip

The content will be extracted to the upload directory. Let’s move it to our site path with this command:

sudo mv upload/* /srv/www/opencart.citizix.com/

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

cd /srv/www/opencart.citizix.com/
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 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:

dig -t A opencart.citizix.com

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

sudo vim /etc/apache2/conf.d/opencart.citizix.com.conf

Add the following content:

<VirtualHost *:80>
    ServerName opencart.citizix.com
    ServerAlias opencart.citizix.com

    ServerAdmin admin@citizix.com

    DocumentRoot /srv/www/opencart.citizix.com
    ErrorLog /var/log/apache2/opencart.citizix.com.error.log
    CustomLog /var/log/apache2/opencart.citizix.com.requests.log combined

    <Directory "/srv/www/opencart.citizix.com">
        Options Indexes
        AllowOverride All
        Require all granted
        DirectoryIndex index.php
    </Directory>
</VirtualHost>

Test the config to ensure it is set up correctly:

~> sudo apachectl configtest
Syntax OK

To apply the changes, please restart apache:

sudo systemctl reload 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 http://opencart.citizix.com, 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/opencart.citizix.com/
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/opencart.citizix.com/system/storage/ /var/www/storage/

Update the config files as seen in the screenshot.

Conclusion

From the above steps, we were able to set up OpenSUSE Leap 15.3 server to serve Opencart.

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