当前位置:web 服务器 > Nginx >>

在CentOS/RHEL6.2/5.8,Fedora17/16上安装Nginx/PHP-FPM环境

什么是PHP-FPM
  PHP-FPM是一个PHP FastCGI管理器,是只用于PHP的,
  PHP-FPM其实是PHP源代码的一个补丁,旨在将FastCGI进程管理整合进PHP包中。必须将它patch到你的PHP源代码中,在编译安装PHP后才可以使用。
  现在我们可以在最新的PHP 5.3.2的源码树里下载得到直接整合了PHP-FPM的分支,据说下个版本会融合进PHP的主分支去。相对Spawn-FCGI,PHP-FPM在CPU和内存方面的控制都更胜一筹,而且前者很容易崩溃,必须用crontab进行监控,而PHP-FPM则没有这种烦恼。
  PHP5.3.3已经集成php-fpm了,不再是第三方的包了。PHP-FPM提供了更好的PHP进程管理方式,可以有效控制内存和进程、可以平滑重载PHP配置,比spawn-fcgi具有更多有点,所以被PHP官方收录了。在./configure的时候带 –enable-fpm参数即可开启PHP-FPM。
  以上摘自:什么是CGI、FastCGI、PHP-CGI、PHP-FPM、Spawn-FCGI?
什么是Nginx
  Nginx ("engine x") 是一个高性能的 HTTP 和 反向代理 服务器,也是一个 IMAP/POP3/SMTP 代理服务器。
在Fedora17/16/15/14,CentOS6.2/6.1/6/5.8及Red Hat(RHEL)6.2/6.1/6/5.8上安装配置Nginx/PHP-FPM
让我们开始行动起来吧

STEP1.切换到root用户
[plain]
su - 
## OR ## 
sudo -i 


STEP2.安装必要的软件源
2-1.  Fedora 17/16/15/14 下安装Remi源
[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 及 Red Hat (RHEL) 6.2/6.1//6/5.8下安装Remi源
[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 及 Red Hat (RHEL) 6.2/6.1/6/5.8 下还要配置Nginx 源
创建/etc/yum.repos.d/nginx.repo文件并写入以下内容
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.安装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 及 Red Hat (RHEL) 6.2/5.8下
[plain] 
yum --enablerepo=remi,remi-test install nginx php php-fpm php-common 


STEP4.安装PHP5.4.4模块扩展
APC (php-pecl-apc) – APC缓存优化中间件
CLI (php-cli) – PHP命令行插件
PEAR (php-pear) – PHP官方扩展
PDO (php-pdo) – 数据库PDO扩展
MySQL (php-mysql) –MYSQL驱动
PostgreSQL (php-pgsql) – PostgreSQL驱动
MongoDB (php-pecl-mongo) – PHP MongoDB驱动
SQLite (php-sqlite) – SQLite V2引擎及驱动
Memcache (php-pecl-memcache) – Memcache 驱动
Memcached (php-pecl-memcached) – Memcached 驱动
GD (php-gd) – GD图片类库扩展
XML (php-xml) –XML扩展
MBString (php-mbstring) –多字节字符串处理扩展
MCrypt (php-mcrypt) – MCrypt类库扩展

4-1.  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下使用命令:
[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.停止httpd(Apache)服务器,启动Nginx HTTP服务及PHP-FPM
5-1.  停止httpd
[plain]
/etc/init.d/httpd stop 
## OR ## 
service httpd stop 

5-2.  启动Nginx
[plain]  
/etc/init.d/nginx start 
## OR ## 
service nginx start 
5-3.  启动PHP_FPM
[plain]
/etc/init.d/php-fpm start 
## OR ## 
service php-fpm start 

【译者注】
到这一步,再按照步骤9配置一下防火墙开放80端口,打开浏览器输入http://localhost就可以看到nginx默认页面。

STEP6.设置Nginx&PHP-FPM开机自启动(同时禁止Httpd自启动)
6-1.  禁止Httpd自启动
[plain] 
chkconfig httpd off 

5-2  设置Nginx&PHP-FPM开机自启动
[html] 
chkconfig --add nginx 
chkconfig --levels 235 nginx on 
chkconfig --add php-fpm 
chkconfig --levels 235 php-fpm on 


STEP7. 配置Nginx&PHP-FPM
7-1. 创建网站目录
在这里我使用testsite.local作为站点目录,在实际应用用我们常常使用对应域名作为站点目录,如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 
配置一下日志目录
[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. 创建并配置nginx虚拟主机目录
[plain] 
mkdir /etc/nginx/sites-available 
mkdir /etc/nginx/sites-enabled 
打开 /etc/nginx/nginx.conf 文件,在include /etc/nginx/conf.d/*.conf”行后(在http block内)加入以下代码
[plain]
include /etc/nginx/sites-enabled/*; 
7-3. 为站点testsite.local配置nginx虚拟主机
在/etc/nginx/sites-available/目录下添加testsite.local文件,其内容如下。
[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; 
   &nbs

补充:Web开发 , php ,
Apache
IIS
Nginx
Tomcat
如果你遇到web 服务器难题:
请访问www.zzzyk.com 试试
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,