CentOS5webserver由apche切换为nginx


之前已经有安装好并且可以正常使用的apache+mysql+php。
先到nginx官方网站http://nginx.org下载当前适用于CentOS的Pre-BuiltPackages for Stable version(http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm)
执行如下命令:
wget http://nginx.org/packages/centos/5/noarch/RPMS/nginx-release-centos-5-0.el5.ngx.noarch.rpm
安装rpm: rpm –ivh nginx-release-centos-5-0.el5.ngx.noarch.rpm
安装nginx: yum install nginx
启动nginx: service nginx start
默认情况下nginx会安装到/usr/sbin/nginx,
配置文件为/etc/nginx/conf.d/default.conf/etc/nginx/nginx.conf
要让nginx支持php,需要安装php-fpm。由于之前的php版本为5.1.6,在网上搜了很久,都没有找到有相对应的php-fpm。最后找到了一个比较全的已编译好的可以用于centos的rpm资源 CentALThttp://centos.alt.ru/pub/repository/centos/, 其中的php-fpm版本为5.2.17,这个版本和5.1.6差别应该不大,于是决定采用这个。

按照CentALT的提示:

先在/etc/yum.repo.d/目录下创建centos.alt.ru.repo文件,内容如下:

[CentALT]
name=CentALT Packages for Enterprise Linux 5 - $basearch
baseurl=http://centos.alt.ru/repository/centos/5/$basearch/
enabled=1
gpgcheck=0
然后enable EPEL 仓库:(可以用getconf LONG_BIT或者uname -a等命令查看系统是32位还是64位)
for i386 
rpm -ihv http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm

for x86_64
rpm -ihv http://download.fedora.redhat.com/pub/epel/5/x86_64/epel-release-5-3.noarch.rpm
最后就可以用 yum install php-fpm进行安装了。

安装成功之后,可以启动php-fpm: service php-fpm start。
ps:使用nginx+php经常出现的502 bad gateway很多都是因为没有安装php-fpm,或者虽然安装了php-fpm,但是并没有启动导致的。

之后停掉apache并启动nginx即可,分别运行如下命令:
service httpd stop
service nginx start

相关内容