Install Nginx + MariaDB + PHP on Fedora 27 / Fedora 26

0

Nginx is a free, open-source, high-performance HTTP server. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption.

This tutorial shows you how to install Nginx on Fedora 27 with PHP support (through PHP-FPM) and MariaDB support.

PHP-FPM is an alternative PHP FastCGI implementation. It has some additional features useful for sites of any size, especially busier sites).

The first thing you need to do is to log in as root or switch to root user.

su -

Install MariaDB

First, we will install the MariaDB by issuing the following command.

dnf -y install mariadb mariadb-server

Start MariaDB server.

systemctl start mariadb

Auto-start MariaDB during every boot, type the following on terminal and hit Enter.

systemctl enable mariadb

Next is to make the MariaDB secure by using the mysql_secure_installation command.

Install Nginx

Install Nginx using the following command.

dnf -y install nginx

Start the Nginx after the installation.

systemctl start nginx

IPtables

Issue the following commands to allow HTTP request through the firewall.

firewall-cmd --permanent --add-service=http
firewall-cmd --reload

SELinux

If you get any error of SELinux on the Nginx logs, here is the tutorial on setting SELinux policy for Nginx.

setenforce 0

Open a web browser and visit

http://your-ip-address

You should see the following page and this will confirm you that the Nginx is successfully installed on the server.

Install Nginx + MariaDB + PHP on Fedora 27- Nginx Test Page
Install Nginx + MariaDB + PHP on Fedora 27- Nginx Test Page

The default nginx document root on Fedora 26 is /usr/share/nginx/html/. The configuration files are under /etc/nginx directory.

Enter the following command to enable Nginx to start at system startup.

systemctl enable nginx

Install PHP5-FPM

Next is to install PHP through PHP-FPM (PHP-FPM (FastCGI Process Manager).

dnf -y install php-fpm php-mysqlnd php-cli

Edit /etc/php.ini.

vi /etc/php.ini

set cgi.fix_pathinfo=0

cgi.fix_pathinfo=0

Edit /etc/php-fpm.d/www.conf file,

vi /etc/php-fpm.d/www.conf

Change this line.

FROM:

listen = /run/php-fpm/www.sock

TO:

listen = 9000

Make sure the following values are UN-commented.

[.More.]
pm.min_spare_servers = 5
[.More.]
pm.max_spare_servers = 35
[.More.]

Set PHP-FPM to start automatically on system boot.

systemctl enable php-fpm

Enable PHP-FPM Support on Virtual Host

Let us create name-based virtual host on Nginx server for the following details.

Server Name : server.itzgeek.local
Document Root : /usr/share/nginx/html/itzgeek.local

Create the configuration file called virtual.conf and Edit /etc/nginx/conf.d/virtual.conf.

vi /etc/nginx/conf.d/virtual.conf

Add the following content.

server {
server_name server.itzgeek.local;
root /usr/share/nginx/html/itzgeek.local;

location / {
index index.html index.htm index.php;
}

location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/itzgeek.local$fastcgi_script_name;
}
}

Create a host entry for your domain (server.itzgeek.local) in /etc/hosts file.

vi /etc/hosts

Add a host entry like below.

127.0.0.1               localhost.localdomain localhost server.itzgeek.local

Test PHP-FPM support on Virtual host

Create the document root directory.

mkdir /usr/share/nginx/html/itzgeek.local

For testing the PHP, Place one PHP file on to the document root of the created virtual host, In the terminal copy/paste the following line:

vi /usr/share/nginx/html/itzgeek.local/index.php

This command will open up a file called index.php, Copy/Paste this line into the index.php file:

<?php phpinfo(); ?>

Save and close the file. use Esc + :wq for saving the file.

Restart the services.

systemctl restart nginx
systemctl restart php-fpm

Now open up your web browser and type your domain in the web address:

http://server.itzgeek.local

The page should look like below:

Install Nginx + MariaDB + PHP on Fedora 27 - PHP Information
Install Nginx + MariaDB + PHP on Fedora 27 – PHP Information

From the above screenshot, PHP is working, and it’s working through FPM/FastCGI, as shown in the Server API line.

If you scroll further down, you will see all modules that are already enabled in PHP. Scroll down the browser and look for the MySQL support information.

Install Nginx + MariaDB + PHP on Fedora 27 - PHP MySQL Support
Install Nginx + MariaDB + PHP on Fedora 27 – PHP MySQL Support

That’s all.

You might also like

Install Nginx + MariaDB + PHP on Fedora 27 / Fedora 26

0