歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> 關於Linux >> CentOS5webserver由apche切換為nginx

CentOS5webserver由apche切換為nginx

日期:2017/3/1 13:36:24   编辑:關於Linux

之前已經有安裝好並且可以正常使用的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

Copyright © Linux教程網 All Rights Reserved