Setting Up Nginx with MariaDB and PHP/PHP-FPM on Fedora 24 Server and Workstation

You must have probably installed Fedora 24 server edition on your machine and you are eager and looking forward to setting up a web server to run websites and web applications. Look no further, because we shall do all that here, with simple and easy steps that you will appreciate at the end.

Install Nginx, MariaDB, PHP and PHP-FPM on Fedora 24

Install Nginx, MariaDB, PHP and PHP-FPM on Fedora 24

In this how to guide, we shall run through the different steps of how you can install LEMP stack on your Fedora 24 web server. Similar to LAMP, but under LEMP, we use Nginx web server.

Don’t Miss: Install LAMP (Linux, Apache, MariaDB and PHP) on Fedora 24 Server

Step 1: Updating System Packages

You can get started by updating your system packages as follows:

# dnf update
Update Fedora 24 Server

Update Fedora 24 Server

When that is done, proceed to install the composite LEMP packages.

Step 2: Install Nginx Web Server

Nginx is an alternative to Apache web server, it is light weight and consumes less system resource hence its high performance, stability and flexibility in enterprise productions environments.

To install Nginx on Fedora 24, issue the command below:

# dnf install nginx  
Install Nginx on Fedora 24 Server

Install Nginx on Fedora 24 Server

Once the installation is complete, you need to manage the Nginx service on your system. First you need to set it to start automatically at boot time by running the command below:

# systemctl enable nginx.service

Then start the service as follows:
# systemctl start nginx.service

Next, check to see that Nginx server is running, you can issue the command below to do that:

# systemctl status nginx.service
Start and Verify Nginx Web Server

Start and Verify Nginx Web Server

In order to view your Nginx web server over HTTP/HTTPS protocol, you need to allow access to it through the system firewall. To do so, run the following commands:

# firewall-cmd --permanent --add-service=http
# firewall-cmd --permanent --add-service=https

Then reload the system firewall configurations to effect the above changes as follows:

# systemctl reload firewalld
Open Apache Ports on Firewalld

Open Apache Ports on Firewalld

Now move on to set your Nginx server_name directive, using your favorite editor, open the file /etc/nginx/nginx.conf and find the configuration directive as shown:

server_name server-ip-address;
Configure Nginx Web Server

Configure Nginx Web Server

Note: The Nginx document directory root is /usr/share/nginx/html, and this is where you can place all your web files.

One more important thing to do under Nginx installation is to check whether the Nginx installation index page can load in your web browser, therefore open your web browser and enter the URL:

http://server-ip-address

You should be able to view this page below:

Check Nginx Web Page

Check Nginx Web Page

Step 3: Install MariaDB Server

MariaDB is a fork of the most famous MySQL relational database server, to install MariaDB on Fedora 24 server, issue the command below:

# dnf install mariadb-server
Install MariaDB on Fedora 24 Server

Install MariaDB on Fedora 24 Server

After completing the MariaDB installation, you need to enable, start and verify the service by running following series of commands.

# systemctl enable mariadb-service  
# systemctl start mariadb-service 
# systemctl status mariadb-service  
Start and Verify MariaDB Service

Start and Verify MariaDB Service

Now it’s time to secure your MariaDB installation using following command:

# mysql_secure_installation

After executing above command, you will be asked a few questions as follows:

Enter current password for root(enter for none): Here, Simply press [Enter]
Next you will be asked to set a root user password for your MariaDB server.
Set root password? [Y/n]: y and hit [Enter]
New password: Enter a new password for root user
Re-enter new password: Re-enter the above password 
Remove anonymous users? [Y/n]: y to remove anonymous users
It is not always good to keep your system open to remote access by root user, in case an attacker lands on your root user password, he/she can cause damage to your system. 
Disallow root login remotely? [Y/n]: y to prevent remote access for root user. 
Remove test database and access to it? [Y/n]: y to remove the test database
Finally, you need to reload privileges tables on your database server for the above changes to take effect.
Reload privileges tables now? [Y/n]: y to reload privileges tables 
Secure MariaDB Installation

Secure MariaDB Installation

Step 4: Install PHP and Modules

To install PHP on Fedora 24 along with its modules, use the command below:

# dnf install php php-commom php-fpm php-mysql php-gd
Install PHP and PHP-FPM Module

Install PHP and PHP-FPM Module

Now that PHP and some PHP modules have completed installing, you need to configure PHP so that you can run PHP files.

By default, PHP-FPM is configured to be used with Apache web server, but for our case here, we are using Nginx web server. Therefore we need to change that setting in the steps below:

Using your favorite editor, open the file /etc/php-fpm.d/www.conf as follows:

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

Then change the values of user and group from apache to nginx in the following lines:

; RPM: apache Choosed to be able to access some dir as httpd 
user = nginx 
; RPM: Keep a group allowed to write in log dir. 
group = nginx
Configure PHP-FPM for Nginx

Configure PHP-FPM for Nginx

Then restart PHP-FPM and Nginx web server to effect the changes above:

# systemctl restart php-fpm.services
# systemctl restart nginx.services

After that, confirm that they are running be issuing the commands below:

# systemctl status php-fpm.services
# systemctl status nginx.services

Now you can test it all, using your favorite editor, create a file called info.php in your Nginx root directory as follows:

# vi /usr/share/nginx/html/info.php

Add the following lines in the file, save it and exit.

<?php
phpinfo()
?>

Then open your web browser and enter the following URL to verify the PHP information:

http://server-ip-address/info.php
Verify PHP Details

Verify PHP Details

At this point, you must have successfully installed and configured LEMP stack on your Fedora 24 server. In a few cases, some of you must have encountered errors or want more explanation concerning an issue of concern, you can leave a comment in the comment section below and we shall find solutions together.

If You Appreciate What We Do Here On TecMint, You Should Consider:

TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.

If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.

Support Us

We are thankful for your never ending support.

Aaron Kili

Aaron Kili is a Linux and F.O.S.S enthusiast, an upcoming Linux SysAdmin, web developer, and currently a content creator for TecMint who loves working with computers and strongly believes in sharing knowledge.

Your name can also be listed here. Got a tip? Submit it here to become an TecMint author.

RedHat RHCE and RHCSA Certification Book
Linux Foundation LFCS and LFCE Certification Preparation Guide

You may also like...

4 Responses

  1. Mozuffer Mohamed Hago says:

    Hi,
    really nice info but it’s not include how to link the Nginx with php-fpm and which configuration I need to do to get the service work probably as you knew the php-fpm is work as independent service

  2. Kimmono says:

    What if you want to use /home/username/www ?

    • Ravi Saive says:

      @kimmono,

      You mean Apache document root path? if yes, you can replace /var/www/html with /home/username/www in httpd.conf file.

Got something to say? Join the discussion.

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.