What is PHP-FPM
PHP-FPM is a PHP FastCGI manager, which is only used for PHP,
PHP-FPM is actually a patch of the PHP source code, designed to integrate FastCGI process management into the PHP package. It must be patched into your PHP source code, and it can be used after compiling and installing PHP.
Now we can download the branch that directly integrates PHP-FPM in the source tree of the latest PHP 5.3.2. It is said that the next version will be integrated into the main branch of PHP. Compared with Spawn-FCGI, PHP-FPM has better CPU and memory control, and the former crashes easily and must be monitored with crontab, while PHP-FPM does not have such troubles.
PHP5.3.3 has integrated php-fpm and is no longer a third-party package. PHP-FPM provides a better PHP process management method, which can effectively control memory and processes, and can smoothly reload PHP configuration. It has more advantages than spawn-fcgi, so it is officially included in PHP. PHP-FPM can be turned on by passing the –enable-fpm parameter in ./configure.
The above is excerpted from: What are CGI, FastCGI, PHP-CGI, PHP-FPM, Spawn-FCGI?
What is Nginx
Nginx ("engine x") is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server.
Install and configure Nginx/PHP-FPM on Fedora17/16/15/14, CentOS6.2/6.1/6/5.8 and Red Hat (RHEL)6.2/6.1/6/5.8
Let’s get started
STEP1. Switch to root user
[plain]
su -
## OR ##
sudo -i
STEP2. Install necessary software sources
2-1. Install Remi source under Fedora 17/16/15/14
[plain]
## Remi Dependency on Fedora 17, 16, 15
rpm -Uvh http://download1.rpmfusion.org/free/fedora/rpmfusion-free-release-stable.noarch.rpm
rpm -Uvh http://download1.rpmfusion.org/nonfree/fedora/rpmfusion-nonfree-release-stable.noarch.rpm
## Fedora 17 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-17.rpm
## Fedora 16 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-16.rpm
## Fedora 15 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-15.rpm
## Fedora 14 ##
rpm -Uvh http://rpms.famillecollet.com/remi-release-14.rpm
2-1. Install Remi source under CentOS 6.2/6.1/6/5.8 and Red Hat (RHEL) 6.2/6.1//6/5.8
[plain]
## Remi Dependency on CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-7.noarch.rpm
## CentOS 6 and Red Hat (RHEL) 6 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-6.rpm
## Remi Dependency on CentOS 5 and Red Hat (RHEL) 5 ##
rpm -Uvh http://dl.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm
## CentOS 5 and Red Hat (RHEL) 5 ##
rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-5.rpm
2-2. Under CentOS 6.2/6.1/6/5.8 and Red Hat (RHEL) 6.2/6.1/6/5.8, Nginx source must also be configured
Create /etc/yum.repos.d/nginx.repo file and write the following content
CentOS
[plain]
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/centos/$releasever/$basearch/
gpgcheck=0
enabled=1
RedHat(RHEL)
[plain]
[nginx]
name=nginx repo
baseurl=http://nginx.org/packages/rhel/$releasever/$basearch/
gpgcheck=0
enabled=1
STEP3. Install Nginx,PHP5.4.4&PHP-FPM
3-1. Fedora 17/16/15/14
[plain]
yum --enablerepo=remi install nginx php php-fpm php-common
3-1. Under CentOS 6.2/5.8 and Red Hat (RHEL) 6.2/5.8
[plain]
yum --enablerepo=remi,remi-test install nginx php php-fpm php-common
STEP4. Install PHP5.4.4 module extension
APC (php-pecl-apc) – APC cache optimization middleware
CLI (php-cli) – PHP command line plugin
PEAR (php-pear) – Official PHP extension
PDO (php-pdo) – Database PDO extension
MySQL (php-mysql) –MYSQL driver
PostgreSQL (php-pgsql) – PostgreSQL driver
MongoDB (php-pecl-mongo) – PHP MongoDB driver
SQLite (php-sqlite) – SQLite V2 engine and driver
Memcache (php-pecl-memcache) – Memcache driver
Memcached (php-pecl-memcached) – Memcached driver
GD (php-gd) – GD image library extension
XML (php-xml) –XML extension
MBString (php-mbstring) – Multi-byte string processing extension
MCrypt (php-mcrypt) – MCrypt library extension
4-1. Use the command under Fedora 17/16/15/14:
[plain]
yum --enablerepo=remi install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php-gd php- mbstring php-mcrypt php-xml
4-1. Commands used under CentOS 6.2/5.8 and Red Hat (RHEL) 6.2/5.8:
[plain]
yum --enablerepo=remi,remi-test install php-pecl-apc php-cli php-pear php-pdo php-mysql php-pgsql php-pecl-mongo php-sqlite php-pecl-memcache php-pecl-memcached php -gd php-mbstring php-mcrypt php-xml
STEP5. Stop the httpd (Apache) server and start the Nginx HTTP service and PHP-FPM
5-1. Stop httpd
[plain]
/etc/init.d/httpd stop
## OR ##
service httpd stop
5-2. Start Nginx
[plain]
/etc/init.d/nginx start
## OR ##
service nginx start
5-3. Start PHP_FPM
[plain]
/etc/init.d/php-fpm start
## OR ##
service php-fpm start
【Translator's Note】
At this point, follow step 9 to configure the firewall to open port 80. Open the browser and enter http://localhost to see the nginx default page.
STEP6. Set Nginx&PHP-FPM to start automatically at boot (disable Httpd from starting automatically)
6-1. Disable Httpd from starting
[plain]
chkconfig httpd off
5-2 Set Nginx&PHP-FPM to start automatically at boot
[html]
chkconfig --add nginx
chkconfig --levels 235 nginx on
chkconfig --add php-fpm
chkconfig --levels 235 php-fpm on
STEP7. Configure Nginx&PHP-FPM
7-1. Create website directory
Here I use testsite.local as the site directory. In practical applications, we often use the corresponding domain name as the site directory, such as www.csdn.com
[plain] view plaincopy
##Create public_html directory and logs log directory
mkdir -p /srv/www/testsite.local/public_html
mkdir /srv/www/testsite.local/logs
##Change the owner of the above directory to nginx
chown -R nginx:nginx /srv/www/testsite.local
Configure the log directory
[plain]
mkdir -p /srv/www/testsite.local/public_html
mkdir -p /var/log/nginx/testsite.local
chown -R nginx:nginx /srv/www/testsite.local
chown -R nginx:nginx /var/log/nginx
7-2. Create and configure nginx virtual host directory
[plain]
mkdir /etc/nginx/sites-available
mkdir /etc/nginx/sites-enabled
Open the /etc/nginx/nginx.conf file and add the following code after the include /etc/nginx/conf.d/*.conf" line (within the http block)
[plain]
include /etc/nginx/sites-enabled/*;
7-3. Configure nginx virtual host for the site testsite.local
Add the testsite.local file in the /etc/nginx/sites-available/ directory with the following content.
[plain]
server {
Server_name testsite.local;
access_log /srv/www/testsite.local/logs/access.log;
error_log /srv/www/testsite.local/logs/error.log;
Root /srv/www/testsite.local/public_html;
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 /srv/www/testsite.local/public_html$fastcgi_script_name;
}
}
Link testsite.local to /etc/nginx/sites-enabled
[plain]
cd /etc/nginx/sites-enabled/
ln -s /etc/nginx/sites-available/testsite.local
service nginx restart
Add the "domain name" testsite.local to /etc/hosts
Modify the /etc/hosts file
[plain]
cd /etc/nginx/sites-enabled/
127.0.0.1 localhost.localdomain localhost testsite.local
STEP8. Test
Create the index.php file under /srv/www/testsite.local/public_html/ with the following content
[plain]
cd /etc/nginx/sites-enabled/
phpinfo();
?>
Open your browser and visit http://testsite.local/
STEP9. Firewall iptables configuration
Open port 80 for Nginx Web Server, modify the /etc/sysconfig/iptables file and add the following content
[plain]
cd /etc/nginx/sites-enabled/
-A INPUT -m state --state NEW -m tcp -p tcp --dport 80 -j ACCEPT
Restart iptables firewall
[plain]
cd /etc/nginx/sites-enabled/
service iptables restart
## OR ##
/etc/init.d/iptables restart
Author: uuleaf