2月 212013
安装编译工具
[root@localhost ~]# yum install gcc make
添加用以执行nginx的用户
[root@localhost conf]# groupadd nginx [root@localhost conf]# useradd -g nginx nginx -s /sbin/nologin
安装PHP依赖
[root@localhost php-5.2.17]# yum install libxml2-devel
CentOS 6.3最小化安装环境已包含libxml2未包含libxml2-devel
libxml2-devel的安装依赖包关系
Installing: libxml2-devel i686 2.7.6-12.el6_4.1 updates 1.1 M Installing for dependencies: pkgconfig i686 1:0.23-9.1.el6 base 67 k zlib-devel i686 1.2.3-29.el6 base 44 k Updating for dependencies: libxml2 i686 2.7.6-12.el6_4.1 updates 800 k zlib i686 1.2.3-29.el6 base 73 k
编译安装PHP环境
[root@localhost php-5.2.17]# ./configure --prefix=/usr/local/php --enable-fastcgi [root@localhost php-5.2.17]# make [root@localhost php-5.2.17]# make install
将路径加入系统环境变量
[root@localhost ~]# vi /etc/profile export PATH=/usr/local/php/bin:$PATH [root@localhost ~]# source /etc/profile
[root@localhost php-5.2.17]# cp php.ini-dist /usr/local/php/lib/php.ini
启动php-cgi模式,监听端口9000,并使用指定的php.ini配置,后台运行
[root@localhost ~]# php-cgi -b 9000 -c /usr/local/php/lib/php.ini &
查看php-cgi监听端口
[root@localhost ~]# netstat -ltun |grep 9000 tcp 0 0 0.0.0.0:9000 0.0.0.0:* LISTEN [root@localhost ~]#
安装nginx编译过程中所需要的依赖软件包
[root@localhost nginx-1.4.0]# yum install gcc-c++ perl
编译安装nginx 1.4.0版本
[root@localhost nginx-1.4.0]# ./configure --prefix=/usr/local/nginx \ > --with-http_stub_status_module --with-http_ssl_module \ > --with-pcre=../pcre-8.32/ --with-zlib=../zlib-1.2.8 \ > --with-openssl=../openssl-1.0.1e [root@localhost nginx-1.4.0]# make [root@localhost nginx-1.4.0]# make install
将nginx加入系统环境变量
export PATH=/usr/local/nginx/sbin:$PATH
查看nginx版本
[root@localhost ~]# nginx -v nginx version: nginx/1.4.0 [root@localhost ~]#
默认示例配置文件部分
# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #}
启用FastCGI并修改配置
location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html/$fastcgi_script_name; include fastcgi_params; }
建立PHP测试页面文件
[root@localhost ~]# cd /usr/local/nginx/html/ [root@localhost html]# vi hello.php <?php phpinfo(); ?>
启动nginx并查看端口监听状态
[root@localhost ~]# netstat -ltu |grep http tcp 0 0 *:http *:* LISTEN [root@localhost ~]#
访问默认首页
访问PHP测试页面
相关下载:
(1) nginx 1.4.0 (2)(3)