Install Nginx/PHP-FPM environment on CentOS/RHEL6.2/5.8, Fedora17/16

Source: Internet
Author: User
Tags apc mcrypt mongodb driver php mongodb what is nginx
What is PHP-FPMPHP-FPM is a PHPFastCGI manager, is only for PHP, PHP-FPM is actually a patch of PHP source code, designed to integrate FastCGI process management into PHP package. You must patch it to your PHP source code before it can be used after compiling and installing PHP .... SyntaxHig

What is PHP-FPM
PHP-FPM is a PHP FastCGI manager that is only used for PHP,
PHP-FPM is actually a patch of PHP source code, designed to integrate FastCGI process management into the PHP package. You must patch it to your PHP source code before using it after compiling and installing PHP.
Now we can download the source code tree in the latest PHP 5.3.2 to directly integrate the branch of the PHP-FPM, it is said that the next version will be integrated into the main branch of PHP. Compared with Spawn-FCGI, PHP-FPM has better control over CPU and memory, and the former is easy to crash and must be monitored with crontab, while PHP-FPM has no such troubles.
PHP5.3.3 has already integrated php-fpm and is no longer a third-party package. PHP-FPM provides a better way of PHP process management, can effectively control the memory and process, can smoothly load PHP configuration, than spawn-fcgi has more, so PHP officially included. You can enable PHP-fpm with The-enable-FPM parameter in./configure.
From above: What are CGI, FastCGI, PHP-CGI, PHP-FPM, and Spawn-FCGI?
What is Nginx?
Nginx ("engine x") is a high-performance HTTP and reverse proxy server and 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.

Step 1 switch to the root user
[Plain]
Su-
##Or ##
Sudo-I


Step 2 install necessary software sources
2-1. install Remi source in 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 the Remi source in 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. configure the Nginx source in CentOS 6.2/6.1/6/5.8 and Red Hat (RHEL) 6.2/6.1/6/5.8
Create the/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

 

Install Nginx, PHP5.4.4 & PHP-FPM
3-1. under Fedora 17/16/15/14
[Plain]
Yum -- enablerepo = remi install nginx php-fpm php-common


3-1. CentOS 6.2/5.8 and Red Hat (RHEL) 6.2/5.8
[Plain]
Yum -- enablerepo = remi, remi-test install nginx php-fpm php-common


Step 4. install PHP5.4.4 Module extension
APC (php-pecl-apc)-APC cache optimization middleware
CLI (php-cli)-PHP command line plug-in
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 class library extension

4-1. run the following 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. CentOS 6.2/5.8 and Red Hat (RHEL) 6.2/5.8 run the following command:
[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

 

Step 5. stop the httpd (Apache) server, start 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]
In this step, configure the firewall to open port 80 and enter http: // localhost in the browser to view the nginx default page.

STEP6. set Nginx & PHP-FPM boot auto-start (disable Httpd auto-start at the same time)
6-1. disable Httpd auto-start
[Plain]
Chkconfig httpd off

5-2 set Nginx & PHP-FPM boot auto start
[Html]
Chkconfig -- add nginx
Chkconfig -- levels 235 nginx on
Chkconfig -- add php-fpm
Chkconfig -- levels 235 php-fpm on


Step 7. Configure Nginx & PHP-FPM
7-1. create a website directory
Here I use testsite. local as the site directory. in actual applications, we often use the corresponding domain name as the site directory, such as www.csdn.com.
[Plain] view plaincopy
# Create the 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 preceding 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 the nginx virtual host Directory
[Plain]
Mkdir/etc/nginx/sites-available
Mkdir/etc/nginx/sites-enabled
Open the/etc/nginx. conf file and add the following code in the line include/etc/nginx/conf. d/*. conf (in the http block ):
[Plain]
Include/etc/nginx/sites-enabled /*;
7-3. configure the nginx virtual host for the site testsite. local
Add the testsite. local file in the/etc/nginx/sites-available/Directory. the content of the file is as follows.
[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

Step 8. test
Create the index. php file under/srv/www/testsite. local/public_html/. the content of the file is as follows:
[Plain]
Cd/etc/nginx/sites-enabled/
Phpinfo ();
?>
Open your browser and access 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.