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:
Ensure that the server packages are up to date
Let us make sure that our server packages are up to date with this command:
Install common packages that we will need
1
| sudo dnf install -y git unzip vim
|
Also configure the timezone
1
| sudo timedatectl set-timezone Africa/Nairobi
|
Disable SELinux
Next, let us disable SELinux. We are going to set SELinux to permisive. Edit this file:
1
| sudo vim /etc/selinux/config
|
Then update this line:
To ensure that the changes are applied immediately without reboot, use this command:
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:
1
| sudo dnf install -y mariadb-server
|
Once mariadb is installed, you can confirm the details using this command:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
| $ 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:
1
| sudo systemctl start mariadb
|
Confirm the status with this command:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
| $ 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:
1
| sudo systemctl enable mariadb
|
Once the mysql service is running, you need to secure it. Mysql provides a commandline utility that will do that:
1
| 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.
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:
After Supplying your root password, enter the following to the mysql prompt:
1
2
3
| create database bagisto;
create user 'bagisto_user'@'%' identified by 'S0mStrongPa$$word';
grant all privileges on bagisto.* to '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.
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:
1
| sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm
|
Enable version 7.4 of php
1
| sudo dnf module enable -y php:remi-7.4
|
You can confirm that the right version is enabled using this command:
1
| sudo dnf module list php
|
Then install php and dependancies
1
2
3
4
5
6
7
8
| sudo dnf install -y php \
php-cli \
php-common \
php-fpm \
php-intl \
php-gd \
php-zip \
php-mysql
|
Check php version
1
2
3
4
5
6
| $ 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.
Installing Nginx in Rocky Linux
Next, let us install Nginx in our system. Use this command to install nginx
1
| sudo dnf install -y nginx
|
Nginx will be not be started by default. Start with this command:
1
| sudo systemctl start nginx
|
Check the status using this command:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| $ 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:
1
| sudo systemctl enable nginx
|
Edit PHP and php-fpm Config for Bagisto
Update the php config to optimize for our app.
Open the php ini file
Then modify these settings to the values shown. Update the timezone to fit yours.
1
2
3
4
| memory_limit = 2G
max_execution_time = 360
date.timezone = Africa/Nairobi
cgi.fix_pathinfo=0
|
Next let us edit the php-fpm settings.
1
| sudo vim /etc/php-fpm.d/www.conf
|
Then update these values
1
2
3
4
5
6
| user = nginx
group = nginx
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
|
Starting and enabling php-fpm service
The php-fpm service is not started by default. Start using this command:
1
| sudo systemctl start php-fpm
|
Confirm by checking the status:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| $ 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
1
| sudo systemctl enable php-fpm
|
Installing php Composer
Composer is used for dependency management
1
2
3
4
| 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
1
| sudo mv composer.phar /usr/local/bin/composer
|
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 Downloads page. Use this command to download and extract Bagisto in the terminal:
1
2
3
| 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
1
| sudo mv bagisto-1.3.3/ /var/www/bagisto
|
Switch to the directory and install dependencies using composer
1
2
| cd /var/www/bagisto
sudo /usr/local/bin/composer install
|
Ensure Nginx owns the content
1
| sudo chown -R nginx.nginx /var/www/bagisto/
|
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
:
1
| 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:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
| 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.
1
| sudo systemctl restart php-fpm nginx
|
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.