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.
1. EPEL:
This command will download the package into your home directory:
Your installation now is aware of the EPEL repositories. Check this by typing:
Then remove the repository configuration package by typing:
2. REMI:
1. Install
2.Restart MySQL
3. Configuration of MySQL
MySQL will reload and implement the changes:
1. Install
2. Start Nginx:
Enable the REMI repository and install:
Open your php.ini file:
Find "cgi.fix_pathinfo=1" and change the 1 to 0.
Open up the default nginx config file:
Open default.conf:
Now open up the php-fpm configuration:
Replace the apache in the user and group with nginx:
Restart PHP-FPM:
Open your php.ini (/etc/php.ini) and set "session.save_path"
You need to create "session" dir (/var/lib/php/session). Then set chmod:
Restart PHP-FPM:
PHPMyAdmin Installation (manually):
Set up changes in "config.ing.php" (/var/www/html/sqladmin):
Create file server.conf (cd /etc/nginx/conf.d/):
Save this file and restart PHP-FPM.
Open http://pma.example.com (your domain). Enjoy!
Step 1 - Install the Required Repositories
1. EPEL:
wget http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm
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:
wget http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
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
/usr/bin/mysql_secure_installation
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.
cgi.fix_pathinfo=0
Step 6 - Configure Nginx
Open up the default nginx config file:
vi /etc/nginx/nginx.confRaise the number of worker processes to 4 then save and exit that file.
Open default.conf:
vi /etc/nginx/conf.d/default.confMy configuration (default.conf):
# # The default server # server { listen 80; server_name example.com; #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 127.0.0.1:9000 # location ~ \.php$ { root /usr/share/nginx/html; fastcgi_pass unix:/tmp/php5-fpm.sock; # fastcgi_pass 127.0.0.1:9000; 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 wget http://ufpr.dl.sourceforge.net/project/phpmyadmin/phpMyAdmin/4.0.8/phpMyAdmin-4.0.8-all-languages.zip unzip phpMyAdmin-4.0.8-all-languages.zip mv phpMyAdmin-4.0.8-all-languages sqladmin mv sqladmin /var/www/html/ cd /var/www/html/sqladmin mv config.sample.inc.php config.inc.php
Set up changes in "config.ing.php" (/var/www/html/sqladmin):
$cfg['Servers'][$i]['auth_type'] = 'cookie'; to $cfg['Servers'][$i]['auth_type'] = 'http';
Create file server.conf (cd /etc/nginx/conf.d/):
server { listen 80; access_log off; server_name pma.example.com; #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 http://pma.example.com (your domain). Enjoy!
Leave a comment: