首先下载nginx,nginx下载地址:http://www.nginx.org/download/nginx-0.8.53.tar.gz
[root@winsyk ~]# mkdir -p /usr/src/nginx[root@winsyk ~]# cd /usr/src/nginx[root@winsyk ~]# wget -c #下载nginx[root@winsyk ~]# tar -zxvf nginx-0.8.53.tar.gz[root@winsyk ~]# cd nginx-0.8.53[root@winsyk ~]# useradd www #添加www nginx运行账户[root@winsyk ~]# usemod -s /sbin/nologin -g www www #将www加入www组并禁止www登录shell编译前编辑src/core/nginx.h找到#define nginx_version#define NGINX_VERSION #define NGINX_VER#define NGINX_VAR 将上边信息替换为你想替换的信息,便于隐藏nginx版本。编辑src/http/ngx_http_special_response.c找到static u_char ngx_http_error_full_tail[] =static u_char ngx_http_error_tail[] =替换出错信息为你想隐藏的版本。[root@winsyk ~]# ./configure --prefix=/usr/local/nginx --user=www --group=www --with-http_stub_status_module --without-http_rewrite_module --with-http_ssl_module --with-pcre && make && make install 注:运行编译,加入了--with-pcre参数便于nginx配置支持pcre正则库,编译完成,运行[root@winsyk ~]# /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf #启动nginx,nginx启动成功。二、安装php
然后下载php,php下载地址为:http://cn.php.net/get/php-5.3.3.tar.bz2/from/this/mirror
[root@winsyk ~]# mkdir -p /usr/src/nginx/php[root@winsyk ~]# wget -c [root@winsyk ~]# tar -jxvf php-5.3.3.tar.bz2 #解压文件[root@winsyk ~]# yum -y install libjpeg libjpeg-devel libpng libpng-devel freetype freetype-devel libxml2 libxml2-devel mysql pcre-devel #为了方面不编译这些文件,直接yum安装[root@winsyk ~]# ./configure --prefix=/usr/local/php --with-mysql --enable-fpm --with-freetype-dir --with-jpeg-dir --with-png-dir --with-zlib --with-libxml-dir --enable-xml --disable-debug --enable-safe-mode --enable-mbstring && make && make install#编译php,--enable-fpm支持fpm/fastcgi编译需要一段时间(根据机器的性能来说)
[root@winsyk ~]# cp -R ./sapi/fpm/php-fpm.conf /usr/local/php/etc/php-fpm.conf
#复制php-fpm文件到php安装目录
[root@winsyk ~]# cp -R ./sapi/fpm/php-fpm /etc/init.d/php-fpm #php-fpm启动[root@winsyk ~]# /etc/init.d/php-fpm运行启动后,出现Nov 20 17:54:03.891754 [ALERT] [pool www]pm.min_spare_servers(0) must be a positive value 启动错误。
编辑php-fpm.conf找到pm.min_spare_server ;pm.min_spare_servers = 5 去除;号也可使用sed -i 's/;pm.min_spare_servers/pm.min_spare_servers/g' /usr/local/php/etc/php-fpm.conf 进行替换再次运行php-fpm进行启动,提示错误:Nov 20 17:57:14.210553 [ALERT] [pool www] pm.max_spare_servers(0) must be a positive valuesed -i 's/;pm.max_spare_servers = 35/pm.max_spare_servers = 35/g' /usr/local/php/etc/php-fpm.conf再次运行php-fpm启动,提示错误:Nov 20 17:58:55.248268 [WARNING] [pool www] pm.start_servers is not set. It's been set to 20sed -i 's/;pm.start_servers = 20/pm.start_servers = 20/g' /usr/local/php/etc/php-fpm.conf再次运行php-fpm未提示错误,启动成功。#配置php
编译nginx.conf加入如下语句: location ~ \.php$ { root html; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME /usr/local/nginx/html$fastcgi_script_name; }echo "<?php phpinfo();?>" >/usr/local/nginx/html/index.php然后运行index.php测试安装成功。