How To Install Nginx+PHP-FPM+PHPMyAdmin on CentOS 6

Posted on Jan 27, 2014
Hey Everybody. This is a tutorial that teaches the Nginx+PHP-FPM+PHPMyAdmin installation.

Step 1 - Install the Required Repositories

1. EPEL:

This command will download the package into your home directory:
rpm -ivh epel-release*

Your installation now is aware of the EPEL repositories. Check this by typing:
yum repolist

Then remove the repository configuration package by typing:
rm epel-release*

2. REMI:
rpm -ivh remi-release*
yum repolist
rm remi-release*

Step 2 - Install MySQL

1. Install
yum install mysql mysql-server

2.Restart MySQL
/etc/init.d/mysqld restart

3. Configuration of MySQL

MySQL will reload and implement the changes:
Remove anonymous users? [Y/n] y   
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Step 3 - Install Nginx

1. Install
yum install nginx

2. Start Nginx:
/etc/init.d/nginx start

Step 4 - Install PHP (PHP-FPM)

Enable the REMI repository and install:
yum --enablerepo=remi install php-fpm php-mysql

Step 5 - PHP Configuration

Open your php.ini file:
vi /etc/php.ini

Find "cgi.fix_pathinfo=1" and change the 1 to 0.

Step 6 - Configure Nginx

Open up the default nginx config file:
vi /etc/nginx/nginx.conf
Raise the number of worker processes to 4 then save and exit that file.

Open default.conf:
vi /etc/nginx/conf.d/default.conf
My configuration (default.conf):
# The default server
server {
    listen       80;
    server_name;  #your domain
    location / {
        root   /usr/share/nginx/html;
        index index.php  index.html index.htm;

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;

    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;

    # pass the PHP scripts to FastCGI server listening on
    location ~ \.php$ {
        root           /usr/share/nginx/html;
        fastcgi_pass   unix:/tmp/php5-fpm.sock;
#       fastcgi_pass;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        include        fastcgi_params;


Now open up the php-fpm configuration:
vi /etc/php-fpm.d/www.conf

Replace the apache in the user and group with nginx:
; Unix user/group of processes
; Note: The user is mandatory. If the group is not set, the default user's group
;	will be used.
; 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

Restart PHP-FPM:
service php-fpm restart

Step 7 - Install PHPMyAdmin

Open your php.ini (/etc/php.ini) and set "session.save_path"
session.save_path = "/var/lib/php/session"

You need to create "session" dir (/var/lib/php/session). Then set chmod:
chmod -R 777 session

Restart PHP-FPM:
service php-fpm restart

PHPMyAdmin Installation (manually):
mkdir /root/temp
cd /root/temp
mv phpMyAdmin-4.0.8-all-languages sqladmin
mv sqladmin /var/www/html/
cd /var/www/html/sqladmin

Set up changes in "" (/var/www/html/sqladmin):
$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'http';

Create file server.conf (cd /etc/nginx/conf.d/):
server {
    listen 80;
    access_log off;
    server_name;  #your domain
    server_name_in_redirect off;
    root  /var/www/html;

        # access to sqladmin
        location / {
                alias   /var/www/html/sqladmin/;
                index  index.php index.html index.htm;

	# php-fpm configuration
        location ~ .php$ {
            root           /var/www/html/sqladmin;
            try_files $uri =404;
            fastcgi_pass   unix:/tmp/php5-fpm.sock;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
            include        fastcgi_params;
            fastcgi_buffer_size 128k;
            fastcgi_buffers 256 4k;
            fastcgi_busy_buffers_size 256k;
            fastcgi_temp_file_write_size 256k;

Save this file and restart PHP-FPM.
Open (your domain). Enjoy!

Leave a comment:

Thank you for your comment. After a while, our moderators will add it.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

© Twiwoo 2023 Cookie Policy