How to install LEMP on Fedora 22 – Nginx + PHP + MariaDB



Nginx is a free, open-source, high-performance HTTP server. This tutorial shows you how to install LEMP on  Fedora 22. Nginx is known for its stability, rich feature set, simple configuration, and low resource consumption. 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 login as root or switch to root user.

$ su

Installing MariaDB:

First we will install the MySQL by issuing the following command.

# dnf -y install mariadb mariadb-server

Start MySQL server.

# systemctl start mariadb.service

To make the MySQL to 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.

Installing Nginx:

Install Nginx using the following command.

# dnf -y install nginx

Start the Nginx after the installation.

# systemctl start nginx.service

Iptables and SELinux:

Configure firewall to allow http request from the external network. Here we will be using static firewall rules, so will disable firewalld and enable iptables and ip6tables.

# dnf -y install iptables-services
# systemctl mask firewalld.service
# systemctl enable iptables.service
# systemctl enable ip6tables.service

Start both iptables and ip6tables.

# systemctl stop firewalld.service
# systemctl start iptables.service
# systemctl start ip6tables.service

Allow apache through firewall, we will allow both http and https traffic.

# iptables -I INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
# iptables -I INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT
# service iptables save

If you get any error of SELinux on the Nginx logs, here is the tutorial on setting SELinux policy for Nginx.Open web browser and visit http://your-ip-address, you should see the following page; this will confirm you that the ngnix is successfully installed on the server.

Fedora 21 - Nginx Default Page
Fedora 22 – Nginx Default Page

The default nginx document root on Fedora 22 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

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

# dnf -y install php-fpm php-mysql php-cli

Edit /etc/php.ini.

# vi /etc/php.ini

set cgi.fix_pathinfo=0


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

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

Change the listening port.

listen = 9000

Make sure the following values are UN-commented.

pm.min_spare_servers = 5
pm.max_spare_servers = 35

Enabling PHP-FPM Support on Virtual Host:

Lets create name based virtual host on Nginx server for the following details.

Server Name :
Document Root : /usr/share/nginx/html/

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 {
root /usr/share/nginx/html/;

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

location ~ \.php$ {
include /etc/nginx/fastcgi_params;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME /usr/share/nginx/html/$fastcgi_script_name;

Create host entry for your domain ( in /etc/hosts file.

# vi /etc/hosts

Add host entry , the line should look like below.               localhost.localdomain localhost

Testing PHP-FPM support on Virtual host:

Create the document root directory.

# mkdir /usr/share/nginx/html/

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/

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
# systemctl enable php-fpm.service

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

The page will look like below:

Fedora 22 - Nginx PHPInfo
Fedora 22 – 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 22 – Nginx PHPInfo MySQL support

That’s all!


Linux :

Nginx :


MariaDB :

You might also like

How to install LEMP on Fedora 22 – Nginx + PHP + MariaDB