_php tutorial on Installing the NGINX/PHP-FPM environment on CENTOS/RHEL6.2/5.8,FEDORA17/16

Source: Internet
Author: User
Tags apc mcrypt mongodb driver pear php mongodb what is nginx
What is PHP-FPM
PHP-FPM is a PHP fastcgi manager that is used only for PHP,
PHP-FPM is actually a patch of PHP source code designed to integrate FASTCGI process management into a PHP package. It must be patch into your PHP source code and can be used after compiling and installing PHP.
Now we can download in the latest PHP 5.3.2 source tree to directly integrate the PHP-FPM branch, it is said that the next version will be fused into the main branch of PHP. Relative SPAWN-FCGI,PHP-FPM in the CPU and memory control are better, and the former is easy to crash, must be monitored with crontab, and PHP-FPM does not have this annoyance.
PHP5.3.3 has integrated php-fpm, no longer a third-party package. PHP-FPM provides a better way to manage the PHP process, can effectively control the memory and process, can be smooth overloaded PHP configuration, more than spawn-fcgi have a bit more, so by the official PHP included. The PHP-FPM can be turned on with the –ENABLE-FPM parameter when the./configure.
Excerpt 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, also a IMAP/POP3/SMTP proxy server.
Install the configuration on fedora17/16/15/14,centos6.2/6.1/6/5.8 and Red Hat (RHEL) 6.2/6.1/6/5.8 nginx/php-fpm
Let's get moving.

STEP1. Switch to the root user
[Plain]
Su-
# # OR # #
Sudo-i


STEP2. Installing the necessary software sources
2-1. Installing 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. CentOS 6.2/6.1/6/5.8 and Red Hat (RHEL) 6.2/6.1//6/5.8 installation Remi Source
[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. CentOS 6.2/6.1/6/5.8 and Red Hat (RHEL) 6.2/6.1/6/5.8 also configure Nginx source
Create a/etc/yum.repos.d/nginx.repo file and write the following:
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. Installing 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. 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. Installing the PHP5.4.4 module extension
APC (PHP-PECL-APC) –APC cache optimization Middleware
CLI (PHP-CLI) –php command line plug-in
PEAR (php-pear) –php official extension
PDO (PHP-PDO) – Database PDO extension
MySQL (php-mysql) –mysql driver
PostgreSQL (Php-pgsql) – PostgreSQL Drive
MongoDB (Php-pecl-mongo) –php MongoDB Driver
SQLite (php-sqlite) –sqlite V2 engine and Driver
Memcache (php-pecl-memcache) –memcache Drive
Memcached (php-pecl-memcached) –memcached Drive
GD (PHP-GD) –GD Picture class Library extension
XML (Php-xml) – an XML extension
Mbstring (php-mbstring) – Multibyte string processing extension
MCrypt (php-mcrypt) –mcrypt class Library extension

4-1. Fedora 17/16/15/14 using the command:
[Plain]
Yum--enablerepo=remi install PHP-PECL-APC php-cli php-pear php-pdo php-mysql php-pgsql Php-pecl-mongo php-sqlite php-pec L-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 use the 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

STEP5. Stop httpd (Apache) server, 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"
To this step, then follow step 9 to configure the firewall open 80 port, open the browser input http://localhost can see the Nginx default page.

STEP6. Setting up NGINX&PHP-FPM boot from boot (also disables httpd self-booting)
6-1. Prohibit httpd from starting
[Plain]
Chkconfig httpd off

5-2 setting nginx&php-fpm boot from 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 a Site Directory
Here I use testsite.local as the site directory, in the actual application we often use the corresponding domain name as a site directory, such as www.csdn.com
[Plain] View plaincopy
# #创建public_html目录及logs日志目录
Mkdir-p/srv/www/testsite.local/public_html
Mkdir/srv/www/testsite.local/logs
# #将以上目录的所有者修改为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/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 site Testsite.local
Add the Testsite.local file under the/etc/nginx/sites-available/directory with the following contents.
[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 the testsite.local to the/etc/nginx/sites-enabled
[Plain]
cd/etc/nginx/sites-enabled/
Ln-s/etc/nginx/sites-available/testsite.local
Service Nginx Restart
Add the testsite.local "domain name" to the/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 contents
[Plain]
cd/etc/nginx/sites-enabled/
Phpinfo ();
?>
Open your browser and visit http://testsite.local/


STEP9. Firewall iptables Configuration
Open 80 port for Nginx WEB Server, modify the/etc/sysconfig/iptables file, 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

http://www.bkjia.com/PHPjc/478098.html www.bkjia.com true http://www.bkjia.com/PHPjc/478098.html techarticle What is php-fpm php-fpm is a PHP fastcgi manager, is only for PHP, PHP-FPM is actually a patch of PHP source code, designed to integrate FASTCGI process management into the PHP package. It must be ...

  • Related Article

    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.