Centos5: nginx+php 安装

本文档详细介绍了在CentOS5系统中,如何通过YUM安装Nginx、PHP和MySQL,以及配置Nginx以支持FastCGI,并通过php_cgi启动脚本来运行PHP-CGI。最后,通过修改nginx配置文件并创建info.php文件进行测试,确保Nginx+PHP-FastCGI环境搭建成功。
摘要由CSDN通过智能技术生成
一、利用CentOS Linux系统自带的yum命令安装、升级所需的程序库
  1. LANG=C
  2. yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpnglibpng-devel freetype freetype-devel libxml2 libxml2-devel zlibzlib-devel glibc glibc-devel glib2 glib2-devel bzip2 bzip2-develncurses ncurses-devel curl curl-devel e2fsprogs e2fsprogs-devel krb5krb5-devel libidn libidn-devel openssl openssl-devel openldapopenldap-devel nss_ldap openldap-clients openldap-servers

二、安装php和mysql

  1. yum -y install php mysql mysql-server mysql-devel php-mysql php-cgi php-mbstring php-gd php-fastcgi

三、安装nginx
由于centos没有默认的nginx软件包,需要启用REHL的附件包

  1. rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-3.noarch.rpm
  2. yum -y install nginx

设置开机启动

  1. chkconfig nginx on
这时查看http://localhost, 可以看到如下的页面。


笔者在安装的时候,遇到了一点问题,出不来上面的页面。查看error.log,如下

在网络上搜索一下,发现是由于采用yum安装时, 它会自动的加上with-file-aio的选项。 但是我系统没有安装aio,所以重新下载了nginx的源代码包,重新安装就可以了。


四、安装spawn-fcgi来运行php-cgi

  1. yum install spawn-fcgi

五、下载spawn-fcgi 的启动脚本

  1. wget http://bash.cyberciti.biz/dl/419.sh.zip
  2. unzip 419.sh.zip
  3. mv 419.sh /etc/init.d/php_cgi
  4. chmod +x /etc/init.d/php_cgi

启动php_cgi

  1. /etc/init.d/php_cgi start

查看进程

  1. netstat -tulpn | grep :9000

若出现如下代表一切正常

  1. tcp 0 0 127.0.0.1:9000 0.0.0.0:* LISTEN 4352/php-cgi


六、修改nginx配置文件,添加fastcgi支持
1. 配置 nginx支持php-fastcgi

    [...]
        server {
            listen       80;
            server_name  _;
            #charset koi8-r;
            #access_log  logs/host.access.log  main;
            location / {
                root   /usr/share/nginx/html;
                index  index.php index.html index.htm;
            }
            error_page  404              /404.html;
            location = /404.html {
                root   /usr/share/nginx/html;
            }
            # redirect server error pages to the static page /50x.html
            #
            error_page   500 502 503 504  /50x.html;
            location = /50x.html {
                root   /usr/share/nginx/html;
            }
            # proxy the PHP scripts to Apache listening on 127.0.0.1:80
            #
            #location ~ \.php$ {
            #    proxy_pass   http://127.0.0.1;
            #}
     
            # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
            #
            location ~ \.php$ {
                root           /usr/share/nginx/html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /usr/share/nginx/html$fastcgi_script_name;
                include        fastcgi_params;
            }
            # deny access to .htaccess files, if Apache's document root
            # concurs with nginx's one
            #
            location ~ /\.ht {
                deny  all;
            }
        }
    [...]

2、重启nginx

  1. /etc/init.d/nginx restart

3、建立info.php文件

  1. vi /usr/share/nginx/html/info.php

 

添加如下代码:

  1. <?php
  2. phpinfo();
  3. ?>

在浏览器打开测试是否正常,如http://10.64.70.64:90/info.php。(笔者使用了iptables来进行内外的转换,具体见(centos(4) iptables 构建局域网环境)


到此,  nginx 加php  fastcgi的安装就完成了。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值