CentOS 5 web server由apche切換為nginx

來源:互聯網
上載者:User

之前已經有安裝好並且可以正常使用的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 - $basearchbaseurl=http://centos.alt.ru/repository/centos/5/$basearch/enabled=1gpgcheck=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.rpmfor x86_64rpm -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


相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.