How to set up Laravel Bagisto with Nginx and PHP-FPM in Rocky Linux/Alma Linux 8

Bagisto is an easy to use, free and open source Laravel eCommerce platform to build your online shop in no time.

In this guide we will learn how to configure Laravel Bagisto with Nginx and PHP-FPM with MariaDB as the data source.

Related Content:

# Table of Content

  1. Ensure that the server packages are up to date
  2. Disable Selinux
  3. Installing Mariadb
  4. Creating Mysql user for Bagisto
  5. Installing PHP 7.4 In Rocky Linux 8
  6. Installing nginx in Rocky Linux 8
  7. Edit PHP and php-fpm config for Bagisto
  8. Starting and enabling php-fpm service
  9. Installing php composer
  10. Download and configure Bagisto
  11. Configure Nginx to serve Bagosto from virtualhost
  12. Accessing Bagisto from the web url

# 1. Ensure that the server packages are up to date

Let us make sure that our server packages are up to date with this command:

sudo dnf -y update

Install common packages that we will need

sudo dnf install -y git unzip vim

Also configure the timezone

sudo timedatectl set-timezone Africa/Nairobi

# 2. Disable SELinux

Next, let us disable SELinux. We are going to set SELinux to permisive. Edit this file:

sudo vim /etc/selinux/config

Then update this line:

SELINUX=permisive

To ensure that the changes are applied immediately without reboot, use this command:

setenforce 0

# 3. Installing Mariadb

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

Install it with this command:

sudo dnf install -y mariadb-server

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

$ rpm -qi mariadb-server
Name        : mariadb-server
Epoch       : 3
Version     : 10.3.28
Release     : 1.module+el8.4.0+427+adf35707
Architecture: x86_64
Install Date: Mon 10 Jan 2022 11:09:11 PM EAT
Group       : Unspecified
Size        : 85968333
License     : GPLv2 with exceptions and LGPLv2 and BSD
Signature   : RSA/SHA256, Mon 31 May 2021 03:18:29 AM EAT, Key ID 15af5dac6d745a60
Source RPM  : mariadb-10.3.28-1.module+el8.4.0+427+adf35707.src.rpm
Build Date  : Mon 31 May 2021 02:56:08 AM EAT
Build Host  : ord1-prod-x86build003.svc.aws.rockylinux.org
Relocations : (not relocatable)
Packager    : infrastructure@rockylinux.org
Vendor      : Rocky
URL         : http://mariadb.org
Summary     : The MariaDB server and related files
Description :
MariaDB is a multi-user, multi-threaded SQL database server. It is a
client/server implementation consisting of a server daemon (mysqld)
and many different client programs and libraries. This package contains
the MariaDB server and some accompanying files and directories.
MariaDB is a community developed branch of MySQL.

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 10.3 database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-01-11 05:58:54 UTC; 7min ago
     Docs: man:mysqld(8)
           https://mariadb.com/kb/en/library/systemd/
 Main PID: 40293 (mysqld)
   Status: "Taking your SQL requests now..."
    Tasks: 30 (limit: 23176)
   Memory: 83.8M
   CGroup: /system.slice/mariadb.service
           └─40293 /usr/libexec/mysqld --basedir=/usr

Jan 11 05:58:54 rockysrv.citizix.com mysql-prepare-db-dir[40191]: See the MariaDB Knowledgebase at http://mariadb.com/kb or the
Jan 11 05:58:54 rockysrv.citizix.com mysql-prepare-db-dir[40191]: MySQL manual for more instructions.
Jan 11 05:58:54 rockysrv.citizix.com mysql-prepare-db-dir[40191]: Please report any problems at http://mariadb.org/jira
Jan 11 05:58:54 rockysrv.citizix.com mysql-prepare-db-dir[40191]: The latest information about MariaDB is available at http://mariadb.org/.
Jan 11 05:58:54 rockysrv.citizix.com mysql-prepare-db-dir[40191]: You can find additional information about the MySQL part at:
Jan 11 05:58:54 rockysrv.citizix.com mysql-prepare-db-dir[40191]: http://dev.mysql.com
Jan 11 05:58:54 rockysrv.citizix.com mysql-prepare-db-dir[40191]: Consider joining MariaDB's strong and vibrant community:
Jan 11 05:58:54 rockysrv.citizix.com mysql-prepare-db-dir[40191]: https://mariadb.org/get-involved/
Jan 11 05:58:54 rockysrv.citizix.com mysqld[40293]: 2022-01-11  5:58:54 0 [Note] /usr/libexec/mysqld (mysqld 10.3.28-MariaDB) starting as process 40293 ...
Jan 11 05:58:54 rockysrv.citizix.com systemd[1]: Started MariaDB 10.3 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 through prompts to secure and set a root password for the mysql instance.

For more info on how to install and configure mariadb in Rocky Linux check out How to install and Configure Mariadb 10 in Rocky Linux/Alma Linux 8.

# 4. Creating mysql user for Bagisto

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 nextcloud:

Connect to mysql server:

mysql -u root -p

After Supplying your root password, enter the following to the mysql prompt:

create database bagisto;
create user '<meta charset="utf-8">bagisto_user'@'%' identified by 'S0mStrongPa$$word';
grant all privileges on <meta charset="utf-8">bagisto.* to '<meta charset="utf-8">bagisto_user'@'%';

Now that we have configured our mysql connection, let’s go to the next section where we install and configure PHP and Nginx.

# 5. Installing PHP 7.4 in Rocky Linux

Bagisto works fine with PHP 7.4. The default php version in Rocky Linux might be outdated. To have control over the php version, let us install the remi release repo using this command:

sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm

Enable version 7.4 of php

sudo dnf module enable -y php:remi-7.4

You can confirm that the right version is enabled using this command:

sudo dnf module list php

Then install php and dependancies

sudo dnf install -y php \
    php-cli \
    php-common \
    php-fpm \
    php-intl \
    php-gd \
    php-zip \
    php-mysql

Check php version

$ php -v
PHP 7.4.27 (cli) (built: Dec 14 2021 17:17:06) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.27, Copyright (c), by Zend Technologies

For more info on setting up PHP and Nginx, check out this guide How to Install and set up PHP and Nginx (LEMP) on Rocky Linux/Alma Linux 8.

# 6. Installing Nginx in Rocky Linux 8

Next, let us install Nginx in our system. Use this command to install nginx

sudo dnf install -y nginx

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

sudo systemctl start nginx

Check the status using this command:

$ sudo systemctl status nginx
● nginx.service - The nginx HTTP and reverse proxy server
   Loaded: loaded (/usr/lib/systemd/system/nginx.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-01-11 06:15:10 UTC; 6s ago
  Process: 42317 ExecStart=/usr/sbin/nginx (code=exited, status=0/SUCCESS)
  Process: 42315 ExecStartPre=/usr/sbin/nginx -t (code=exited, status=0/SUCCESS)
  Process: 42313 ExecStartPre=/usr/bin/rm -f /run/nginx.pid (code=exited, status=0/SUCCESS)
 Main PID: 42318 (nginx)
    Tasks: 3 (limit: 23176)
   Memory: 5.5M
   CGroup: /system.slice/nginx.service
           ├─42318 nginx: master process /usr/sbin/nginx
           ├─42319 nginx: worker process
           └─42320 nginx: worker process

Jan 11 06:15:10 rockysrv.citizix.com systemd[1]: Starting The nginx HTTP and reverse proxy server...
Jan 11 06:15:10 rockysrv.citizix.com nginx[42315]: nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
Jan 11 06:15:10 rockysrv.citizix.com nginx[42315]: nginx: configuration file /etc/nginx/nginx.conf test is successful
Jan 11 06:15:10 rockysrv.citizix.com systemd[1]: Started The nginx HTTP and reverse proxy server.

Active: active (running) indicate that the service is now up and running.

To enable the service on boot, use this command:

sudo systemctl enable nginx

# 7. Edit PHP and php-fpm Config for Bagisto

Update the php config to optimize for our app.

Open the php ini file

sudo vim /etc/php.ini

Then modify these settings to the values shown. Update the timezone to fit yours.

memory_limit = 2G
max_execution_time = 360
date.timezone = Africa/Nairobi
cgi.fix_pathinfo=0

Next let us edit the php-fpm settings.

sudo vim /etc/php-fpm.d/www.conf

Then update these values

user = nginx
group = nginx

listen.owner = nginx
listen.group = nginx
listen.mode = 0660

# 8. Starting and enabling php-fpm service

The php-fpm service is not started by default. Start using this command:

sudo systemctl start php-fpm

Confirm by checking the status:

$ sudo systemctl status php-fpm
● php-fpm.service - The PHP FastCGI Process Manager
   Loaded: loaded (/usr/lib/systemd/system/php-fpm.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2022-01-11 09:22:55 EAT; 31s ago
 Main PID: 43022 (php-fpm)
   Status: "Processes active: 0, idle: 5, Requests: 0, slow: 0, Traffic: 0req/sec"
    Tasks: 6 (limit: 23176)
   Memory: 16.0M
   CGroup: /system.slice/php-fpm.service
           ├─43022 php-fpm: master process (/etc/php-fpm.conf)
           ├─43023 php-fpm: pool www
           ├─43024 php-fpm: pool www
           ├─43025 php-fpm: pool www
           ├─43026 php-fpm: pool www
           └─43027 php-fpm: pool www

Jan 11 09:22:55 rockysrv.citizix.com systemd[1]: Starting The PHP FastCGI Process Manager...
Jan 11 09:22:55 rockysrv.citizix.com php-fpm[43022]: [11-Jan-2022 09:22:55] WARNING: [pool www] ACL set, listen.owner = 'nginx' is ignored
Jan 11 09:22:55 rockysrv.citizix.com php-fpm[43022]: [11-Jan-2022 09:22:55] WARNING: [pool www] ACL set, listen.group = 'nginx' is ignored
Jan 11 09:22:55 rockysrv.citizix.com systemd[1]: Started The PHP FastCGI Process Manager.

Enable the service to start on boot

sudo systemctl enable php-fpm

# 9. Installing php Composer

Composer is used for dependency management

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '906a84df04cea2aa72f40b5f787e49f22d4c2f19492ac310e8cba5b96ac8b64115ac402c8cd292b8a03482574915d1a8') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php
php -r "unlink('composer-setup.php');"

Move the downloaded phar file to bin

sudo mv composer.phar /usr/local/bin/composer

# 10. Download and configure Bagisto

Now that we have successfully configured the LEMP server in our system, let us download and set up Bagisto. You can get the latest version of Bagisto from the Download page. Use this command to download and extract Bagisto in the terminal:

cd /tmp
curl -LO https://github.com/bagisto/bagisto/archive/refs/tags/v1.3.3.tar.gz
tar -xzvf v1.3.3.tar.gz

Move the extracted content to /var/www where it can be served by nginx

sudo mv bagisto-1.3.3/ /var/www/bagisto

Switch to the directory and install dependencies using composer

cd /var/www/bagisto
sudo /usr/local/bin/composer install

Ensure Nginx owns the content

sudo chown -R nginx.nginx /var/www/bagisto/

# 11. Configure Nginx to serve Bagisto from a virtual host

We managed to download the NextCloud content to /var/www/bagisto. The next bit it to set up Nginx to serve it.

Let’s create virtual site in the directory that nginx serves content here /etc/nginx/conf.d:

sudo vim /etc/nginx/conf.d/bagisto.conf

For this to work please ensure that the DNS records used is mapped with the server IP.

Add the following content:

server {
    listen 80;
    server_tokens off;
    client_max_body_size 100M;
    server_name bagisto.citizix.com;

    root /var/www/bagisto/public;
    index index.php;

    if ($host !~* ^(bagisto.citizix.com)$) {
        return 444;
    }

    location / {
        proxy_read_timeout 600;
        proxy_connect_timeout 600;
        proxy_send_timeout 600;
        try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
        fastcgi_index index.php;
        include /etc/nginx/fastcgi_params;
        fastcgi_pass unix:/run/php-fpm/www.sock;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    }
}

Once the abve changes have been made, we need to restart the nginx server and the php-fom server. Use these commands in the terminal to achieve that.

sudo systemctl restart php-fpm nginx

# 12. Accessing Bagisto from the web url

Then head to your set domain, http://bagisto.citizix.com/for me.

You will be taken through Server configuration, Environment Configuration, Database configuration. Once that is done, you can start the installation. Finally you Create a Administrator and add SMTP configs.

# Conclusion

In this guide we managed to set up LEMP stack to serve the Bagisto eComerce platform.

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