您好,欢迎访问一九零五行业门户网

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

什么是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; 
        fastcgi_param script_filename /srv/www/testsite.local/public_html$fastcgi_script_name; 
    } 

将testsite.local链接到/etc/nginx/sites-enabled下
[plain] 
cd /etc/nginx/sites-enabled/ 
ln -s /etc/nginx/sites-available/testsite.local 
service nginx restart 
把testsite.local这个域名加到/etc/hosts中
修改/etc/hosts文件
[plain] 
cd /etc/nginx/sites-enabled/ 
127.0.0.1               localhost.localdomain localhost testsite.local 
step8. 测试
在/srv/www/testsite.local/public_html/下创建index.php文件,其内容如下
[plain] 
cd /etc/nginx/sites-enabled/
打开你的浏览器,访问http://testsite.local/
step9. 防火墙iptables配置
为nginx web server开放80端口,修改/etc/sysconfig/iptables文件,加入如下内容
[plain] 
cd /etc/nginx/sites-enabled/ 
-a input -m state --state new -m tcp -p tcp --dport 80 -j accept 
重启iptables防火墙
[plain] 
cd /etc/nginx/sites-enabled/ 
service iptables restart 
## or ## 
/etc/init.d/iptables restart 
作者:uuleaf
http://www.bkjia.com/phpjc/478098.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/478098.htmltecharticle什么是php-fpm php-fpm是一个php fastcgi管理器,是只用于php的, php-fpm其实是php源代码的一个补丁,旨在将fastcgi进程管理整合进php包中。必须将它...
其它类似信息

推荐信息