How to Install Nginx With PHP-FPM And MySQL On Fedora 16 “Verne”

ADVERTISEMENT

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 how to install Nginx on an Fedora 16  with PHP5 support (through PHP-FPM) and MySQL 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 login as root. You can login as root in Fedora by typing in the terminal:

[raj@geeksite~/]$ sudo su

Installing MySQL 5:

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

ADVERTISEMENT
Article will continue after the ad
[root@geesksite~/]# yum install mysql mysql-server php-mysql

Start MySQL server.

[root@geesksite~/]# systemctl start mysqld.service

Step 3: To make the MySQL to start during the every boot, Type the following on terminal and hit Enter.

[root@geesksite~/]# systemctl enable mysqld.service

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

This program enables you to improve the security of your MySQL installation in the following ways:

  • You can set a password for root accounts.
  • You can remove root accounts that are accessible from outside the local host.
  • You can remove anonymous-user accounts.
  • You can remove the test database (which by default can be accessed by all users, even anonymous users), and privileges that permit anyone to access databases with names that start with test_.

[root@geeksite~/]# mysql_secure_installation

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!

In order to log into MySQL to secure it, we’ll need the current
password for the root user.  If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): <– ENTER
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] <– ENTER
New password: <– yourrootsqlpassword
Re-enter new password: <– yourrootsqlpassword
Password updated successfully!
Reloading privilege tables..
 … Success!

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] <– ENTER
 … Success!

Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] <– ENTER
 … Success!

By default, MySQL comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] <– ENTER
 – Dropping test database…
 … Success!
 – Removing privileges on test database…
 … Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] <– ENTER
 … Success!

Cleaning up…

All done!  If you’ve completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!

Installing Nginx:

Nginx is already available in the Fedora Package, so issue the following command to install Nginx.

[root@geeksite~/]# yum install nginx

Start the Nginx after the installation.

[root@geekssite~/]# systemctl start nginx.service

Test Your Nginx installation by opening your web browser and Navigate to http://127.0.0.1. You will get the following web page saying “Welcome to Nginx on Fedora!“.

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

Auto-Start the Nginx.

[root@geeksite~/]# systemctl enable nginx.service

Installing PHP5-FPM:

Next is to install PHP5  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.

[root@geeksite~/]# yum install php-fpm php

Start or restart the PHP-FPM service.

[root@geeksite~/]# systemctl restart php-fpm.service

Rrestart the Nginx server.

[root@geeksite~/]#  systemctl restart nginx.service

Enabling and Testing PHP-FPM Support on Virtual Host:

Lets create one name based virtual host on Nginx server.

Server Name       :    geeksite.local

Document Root :   /usr/share/nginx/html/geeksite.local

Edit /etc/nginx/conf.d/virtual.conf.

[root@geeksite~/]# vi /etc/nginx/conf.d/virtual.conf

Add the following content at the end of the file

server {
server_name geeksite.local;
root /usr/share/nginx/html/geeksite.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/geeksite.local$fastcgi_script_name;
}
}

Create host entry for geeksite.local domain in /etc/hosts file.

[root@geeksite~/]# vi /etc/hosts

add the entry for geeksite.local, the line should look like below.

127.0.0.1               localhost.localdomain localhost geeeksite.local

Create the document root directory

[root@geeksite~/]# mkdir /usr/share/nginx/html/geeksite.local

For testing the PHP, Place one PHP file on to the document root of the created virtual host.

Restart Nginx and PHP-FPM services.

[root@geeksite~/]# systemctl restart nginx.service
[root@geeksite~/]# systemctl restart php-fpm.service

In the terminal copy/paste the following line:

[root@geeksite~/]# vi /usr/share/nginx/html/geeksite.local/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.

Now open you’re web browser and type the following into the web address:

http://geeksite.local

The page look like below:

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

Scroll down the browser and look for the MySQL support information.

You will find the MySQL modules list that are not listed before the installation of support package.

That’s all!

ADVERTISEMENT

POSTS YOU MAY LIKE -:)

Share This Post

Shares