/ 中存储网

CentOS系统使用yum安装Nginx+PHP环境

2014-02-15 08:09:02 来源:中存储网

1、安装环境CentOs 5.1

[[email protected] html]# uname -a

Linux nginx-freetds 2.6.18-53.el5 #1 SMP Mon Nov 12 02:22:48 EST 2007 i686 i686 i386 GNU/Linux

2、系统安装时定制安装mysql了。当然也可以采用yum install的方式安装。同时。安装了一些开发工具。呵呵,如果使用yum install的方式。亦可不在安装系统时安装。

开始安装:

1、启用CENTOS的额加包。如果不安装,可能会出现不能安装NGINX的问题。

[[email protected] ~]# rpm -Uvh http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm

Retrieving http://download.fedora.redhat.com/pub/epel/5/i386/epel-release-5-2.noarch.rpm

warning: /var/tmp/rpm-xfer.4hD87B: Header V3 DSA signature: NOKEY, key ID 217521f6

Preparing...                ########################################### [100%]

1:epel-release           ########################################### [100%]

[[email protected] ~]#

2、安装NGINX

[[email protected] ~]#  yum install -y nginx

Loading "installonlyn" plugin

Setting up Install Process

Setting up repositories

epel                      100% |=========================| 1.1 kB    00:00    

Reading repository metadata in from local files

primary.xml.gz            100% |=========================| 513 kB    00:04    

################################################## 1595/1595

Parsing package install arguments

Resolving Dependencies

--> Populating transaction set with selected packages. Please wait.

---> Downloading header for nginx to pack into transaction set.

nginx-0.5.33-2.el5.i386.r 100% |=========================| 8.3 kB    00:00    

---> Package nginx.i386 0:0.5.33-2.el5 set to be updated

--> Running transaction check

Dependencies Resolved

=============================================================================

Package                 Arch       Version          Repository        Size

=============================================================================

Installing:

nginx                   i386       0.5.33-2.el5     epel              286 k

Transaction Summary

=============================================================================

Install      1 Package(s)        

Update       0 Package(s)        

Remove       0 Package(s)        

Total download size: 286 k

Downloading Packages:

(1/1): nginx-0.5.33-2.el5 100% |=========================| 286 kB    00:02    

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID 217521f6

Importing GPG key 0x217521F6 "Fedora EPEL <[email protected]>" from /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing: nginx                        ######################### [1/1]

Installed: nginx.i386 0:0.5.33-2.el5

Complete!

[[email protected] ~]#

3、安装后,NGINX的配置文件位于:

[[email protected] ~]# ll /etc/nginx/

total 28

-rw-r--r-- 1 root root 2837 Nov 12 16:11 koi-utf

-rw-r--r-- 1 root root 2223 Nov 12 16:11 koi-win

-rw-r--r-- 1 root root 2991 Nov 12 16:11 mime.types

-rw-r--r-- 1 root root 2991 Nov 12 16:11 mime.types.default

-rw-r--r-- 1 root root 2753 Nov 12 16:11 nginx.conf

-rw-r--r-- 1 root root 2753 Nov 12 16:11 nginx.conf.default

-rw-r--r-- 1 root root 3610 Nov 12 16:11 win-utf

安装后,NGINX的网站目录位于:

[[email protected] ~]#

4、配置Nginx的PHP FastCGI

请将以下内容保存为fastcgi.conf文件,保存于/usr/share/nginx下,它为我们的FastCGI模块设置了基本的环境变量:

[[email protected] ~]# ll /usr/share/nginx/

total 4

drwxr-xr-x 2 root root 4096 Jan 20 19:58 html

[[email protected] ~]# vi /usr/share/nginx/fastcgi.conf

输入:

fastcgi_param GATEWAY_INTERFACE CGI/1.1;

fastcgi_param SERVER_SOFTWARE nginx;

fastcgi_param QUERY_STRING $query_string;

fastcgi_param REQUEST_METHOD $request_method;

fastcgi_param CONTENT_TYPE $content_type;

fastcgi_param CONTENT_LENGTH $content_length;

fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;

fastcgi_param SCRIPT_NAME $fastcgi_script_name;

fastcgi_param REQUEST_URI $request_uri;

fastcgi_param DOCUMENT_URI $document_uri;

fastcgi_param DOCUMENT_ROOT $document_root;

fastcgi_param SERVER_PROTOCOL $server_protocol;

fastcgi_param REMOTE_ADDR $remote_addr;

fastcgi_param REMOTE_PORT $remote_port;

fastcgi_param SERVER_ADDR $server_addr;

fastcgi_param SERVER_PORT $server_port;

fastcgi_param SERVER_NAME $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect

fastcgi_param REDIRECT_STATUS 200;

为什么会是在这个下面。这是我经过多次失败之后的总结,当然也可以改在其它的位置。只需在第10步中更改include 后的路径便可:

[[email protected] ~]# service nginx restart

Stopping nginx: [FAILED]

Starting nginx: 2008/01/20 00:05:32 [emerg] 15038#0: glob() "/usr/share/nginx/./fastcgi.conf" failed (2: No such file or directory) in /etc/nginx/nginx.conf:123

[FAILED]

5、接下来安装PHP,加上php-cli 以便在/usr/bin/ 生成php-cgi。这个很重要。还需要使用到它。

[[email protected] ~]# yum install -y php php-cli

Loading "installonlyn" plugin

Setting up Install Process

Setting up repositories

base                      100% |=========================| 1.1 kB    00:00    

updates                   100% |=========================|  951 B    00:00    

addons                    100% |=========================|  951 B    00:00    

extras                    100% |=========================| 1.1 kB    00:00    

Reading repository metadata in from local files

Parsing package install arguments

Resolving Dependencies

--> Populating transaction set with selected packages. Please wait.

---> Downloading header for php to pack into transaction set.

php-5.1.6-15.el5.i386.rpm 100% |=========================|  18 kB    00:00    

---> Package php.i386 0:5.1.6-15.el5 set to be updated

---> Downloading header for php-cli to pack into transaction set.

php-cli-5.1.6-15.el5.i386 100% |=========================|  17 kB    00:00    

---> Package php-cli.i386 0:5.1.6-15.el5 set to be updated

--> Running transaction check

Dependencies Resolved

=============================================================================

Package                 Arch       Version          Repository        Size

=============================================================================

Installing:

php                     i386       5.1.6-15.el5     base              1.2 M

php-cli                 i386       5.1.6-15.el5     base              2.3 M

Transaction Summary

=============================================================================

Install      2 Package(s)        

Update       0 Package(s)        

Remove       0 Package(s)        

Total download size: 3.5 M

Downloading Packages:

(1/2): php-5.1.6-15.el5.i 100% |=========================| 1.2 MB    00:04    

(2/2): php-cli-5.1.6-15.e 100% |=========================| 2.3 MB    00:06    

warning: rpmts_HdrFromFdno: Header V3 DSA signature: NOKEY, key ID e8562897

Importing GPG key 0xE8562897 "CentOS-5 Key (CentOS 5 Official Signing Key) <[email protected]>" from http://mirror.centos.org/centos/RPM-GPG-KEY-CentOS-5

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing: php-cli                      ######################### [1/2]

  Installing: php                          ######################### [2/2]

Installed: php.i386 0:5.1.6-15.el5 php-cli.i386 0:5.1.6-15.el5

Complete!

[[email protected] ~]#

查看下:

[[email protected] ~]# locate php-cgi

/usr/bin/php-cgi

呵呵,已生成php-cgi啦。

show 下安装后的php组件:

[[email protected] ~]# rpm -aq |grep php

php-5.1.6-15.el5

php-pdo-5.1.6-15.el5

php-common-5.1.6-15.el5

php-mysql-5.1.6-15.el5

php-cli-5.1.6-15.el5

6、接下来安装lighthttp以得到spawn-fcgi以此来控制php-cgi进程运行

[[email protected] ~]# yum install -y lighttpd-fastcgi

Loading "installonlyn" plugin

Setting up Install Process

Setting up repositories

epel                      100% |=========================| 1.1 kB    00:00    

Reading repository metadata in from local files

Parsing package install arguments

Resolving Dependencies

--> Populating transaction set with selected packages. Please wait.

---> Downloading header for lighttpd-fastcgi to pack into transaction set.

lighttpd-fastcgi-1.4.18-1 100% |=========================| 9.6 kB    00:00    

---> Package lighttpd-fastcgi.i386 0:1.4.18-1.el5 set to be updated

--> Running transaction check

--> Processing Dependency: lighttpd = 1.4.18 for package: lighttpd-fastcgi

--> Restarting Dependency Resolution with new changes.

--> Populating transaction set with selected packages. Please wait.

---> Downloading header for lighttpd to pack into transaction set.

lighttpd-1.4.18-1.el5.i38 100% |=========================|  21 kB    00:00    

---> Package lighttpd.i386 0:1.4.18-1.el5 set to be updated

--> Running transaction check

--> Processing Dependency: liblua-5.1.so for package: lighttpd

--> Restarting Dependency Resolution with new changes.

--> Populating transaction set with selected packages. Please wait.

---> Downloading header for lua to pack into transaction set.

lua-5.1.2-1.el5.i386.rpm  100% |=========================| 6.8 kB    00:00    

---> Package lua.i386 0:5.1.2-1.el5 set to be updated

--> Running transaction check

Dependencies Resolved

=============================================================================

Package                 Arch       Version          Repository        Size

=============================================================================

Installing:

lighttpd-fastcgi        i386       1.4.18-1.el5     epel               45 k

Installing for dependencies:

lighttpd                i386       1.4.18-1.el5     epel              373 k

lua                     i386       5.1.2-1.el5      epel              225 k

Transaction Summary

=============================================================================

Install      3 Package(s)        

Update       0 Package(s)        

Remove       0 Package(s)        

Total download size: 643 k

Downloading Packages:

(1/3): lighttpd-1.4.18-1. 100% |=========================| 373 kB    00:01    

(2/3): lighttpd-fastcgi-1 100% |=========================|  45 kB    00:00    

(3/3): lua-5.1.2-1.el5.i3 100% |=========================| 225 kB    00:01    

Running Transaction Test

Finished Transaction Test

Transaction Test Succeeded

Running Transaction

  Installing: lua                          ######################### [1/3]

  Installing: lighttpd                     ######################### [2/3]

  Installing: lighttpd-fastcgi             ######################### [3/3]

Installed: lighttpd-fastcgi.i386 0:1.4.18-1.el5

Dependency Installed: lighttpd.i386 0:1.4.18-1.el5 lua.i386 0:5.1.2-1.el5

Complete!

[[email protected] ~]# updatedb

[[email protected] ~]# locate spawn-fcgi

/usr/bin/spawn-fcgi

/usr/share/man/man1/spawn-fcgi.1.gz

[[email protected] ~]#

OK,spawn-fcgi被安装成命令行式了。成功。