Linux, Windows, Virtualization, OpenSource & Blogging

Install Nginx + PHP-FPM + MariaDB on Fedora 26

0

NGINX

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

yum -y install mariadb mariadb-server

Start MariaDB server.

systemctl start mariadb.service

To make the MariaDB start during the every boot, type the following on terminal and hit Enter.

systemctl enable mariadb.service

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

Install Nginx

Install Nginx using the following command.

yum -y install nginx

Start the Nginx after the installation.

systemctl start nginx.service

Iptables and SELinux

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

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

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

Open a web browser and visit http://your-ip-address, you should see the following page; this will confirm you that the Nginx is successfully installed on the server.

Fedora 21 - Nginx Default Page
Fedora 21 – Nginx Default 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.service

Install PHP5-FPM

Next is to install PHP through PHP-FPM (PHP-FPM (FastCGI Process Manager), it is an alternative PHP FastCGI implementation. it has some additional features useful for sites of any size, especially busier sites). Install it by issuing the following command.

yum -y install php-fpm php-mysql 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

Make sure the following values are UN-commented.

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

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.com
Document Root : /usr/share/nginx/html/itzgeek.com

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.com;
root /usr/share/nginx/html/itzgeek.com;

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.com$fastcgi_script_name;
}
}

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

vi /etc/hosts

Add host entry. The line should look like below.

127.0.0.1               localhost.localdomain localhost server.itzgeek.com

Test PHP-FPM support on Virtual host

Create the document root directory.

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

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.com/index.php

This 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.service
systemctl restart php-fpm.service

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

http://server.itzgeek.com

The page look like below:

Fedora 21 - Nginx PHPInfo
Fedora 21 – Nginx PHPInfo

From the above screen shot , 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.

Fedora 21 - Nginx PHPInfo MySQL support
Fedora 21 – Nginx PHPInfo MySQL support

That’s all!

You might also like

Install Nginx + PHP-FPM + MariaDB on Fedora 26

0