5 月 062013
 

编译安装apache

[root@localhost ~]# yum install perl gcc make
[root@localhost ~]# groupadd -r apache
[root@localhost ~]# useradd -r -M -g apache apache
[root@localhost ~]# tar xzf httpd-2.2.24.tar.gz
[root@localhost ~]# cd httpd-2.2.24
[root@localhost httpd-2.2.24]# ./configure --prefix=/usr/local/apache \
 > --enable-so --enable-rewrite
[root@localhost httpd-2.2.24]# make
[root@localhost httpd-2.2.24]# make install

编译安装php

[root@localhost ~]# tar xzf php-5.2.17.tar.gz
[root@localhost ~]# cd php-5.2.17
[root@localhost php-5.2.17]# yum install libxml2-devel
[root@localhost php-5.2.17]# yum install gd-devel libpng-devel libjpeg-devel
[root@localhost php-5.2.17]# ./configure --prefix=/usr/local/php \
 > --with-apxs2=/usr/local/apache/bin/apxs \
 > --enable-fastcgi --enable-mbstring \
 > --with-gd=/usr/ --with-png-dir=/usr/ --with-jpeg-dir=/usr/
[root@localhost php-5.2.17]# make
[root@localhost php-5.2.17]# make install
[root@localhost php-5.2.17]# cp php.ini-dist /usr/local/php/lib/php.ini

编译安装nginx

[root@localhost ~]# tar xzf nginx-1.4.0.tar.gz
[root@localhost ~]# tar xzf openssl-1.0.1e.tar.gz
[root@localhost ~]# tar xzf zlib-1.2.8.tar.gz
[root@localhost ~]# tar xzf pcre-8.32.tar.gz
[root@localhost nginx-1.4.0]# cd nginx-1.4.0
[root@localhost nginx-1.4.0]# yum install gcc-c++
[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配置文件

#location ~ \.php$ {
 #    proxy_pass   http://127.0.0.1;
 #}
location ~ \.php$ {
 proxy_pass   http://127.0.0.1:8080;
 }

修改apache配置文件

[root@localhost ~]# vi /usr/local/apache/conf/httpd.conf
 Listen 8080
User apache
Group apache
ServerName 127.0.0.1:8080
<IfModule dir_module>
 DirectoryIndex index.php
</IfModule>
AddType application/x-httpd-php .php
#DocumentRoot "/usr/local/apache/htdocs"
DocumentRoot "/usr/local/nginx/html"
#<Directory "/usr/local/apache/htdocs">
#    Options Indexes FollowSymLinks
#    AllowOverride None
#    Order allow,deny
#    Allow from all
#</Directory>
<Directory "/usr/local/nginx/html">
 Options Indexes FollowSymLinks
 AllowOverride None
 Order allow,deny
 Allow from all
</Directory>

启动apache并查看监听

[root@localhost ~]# /usr/local/apache/bin/apachectl start
[root@localhost ~]# netstat -lutn |grep 8080
 tcp        0      0 :::8080                     :::*                        LISTEN
[root@localhost ~]#

启动nginx并查看监听

[root@localhost ~]# /usr/local/nginx/sbin/nginx
[root@localhost ~]# netstat -lut |grep http
 tcp        0      0 *:http                      *:*                         LISTEN
[root@localhost ~]#

创建php测试文件

[root@localhost ~]# vi /usr/local/nginx/html/hello.php
 <?php phpinfo(); ?>

nginx-apache-0201

访问http://192.168.244.135/index.html后的nginx日志记录

[root@localhost ~]# cat /usr/local/nginx/logs/access.log
192.168.244.1 - - [06/May/2013:16:53:22 +0800] "GET / HTTP/1.1" 200 612 "-"
 "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0"

nginx-apache-0202

访问http://192.168.244.135/hello.php后的apache日志记录

[root@localhost ~]# cat /usr/local/apache/logs/access_log
 127.0.0.1 - - [06/May/2013:19:09:00 +0800] "GET /hello.php HTTP/1.0" 200 43026
 127.0.0.1 - - [06/May/2013:19:09:00 +0800] "GET
 /hello.php?=PHPE9568F34-D428-11d2-A769-00AA001ACF42 HTTP/1.0" 200 2524
 127.0.0.1 - - [06/May/2013:19:09:00 +0800] "GET
 /hello.php?=PHPE9568F35-D428-11d2-A769-00AA001ACF42 HTTP/1.0" 200 2146
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 ~]#

访问默认首页

nginx-php-01

 

访问PHP测试页面

…… nginx-php-02

相关下载:
(1) nginx 1.4.0 (2)(3)

2 月 202013
 

下载最新版本nginx,pcre,openssl,zlib并解压缩

nginx-01-01

编译安装

 [root@localhost nginx-1.2.7]# ./configure --prefix=/usr/local/nginx \
 --with-pcre=../pcre-8.32/ --with-zlib=../zlib-1.2.7 \
 --with-openssl=../openssl-1.0.1e --with-http_ssl_module
[root@localhost nginx-1.2.7]#make
[root@localhost nginx-1.2.7]#make install

查看安装完成nginx的版本

[root@localhost sbin]# ./nginx -v
 nginx version: nginx/1.2.7

查看nginx命令参数

[root@localhost sbin]# ./nginx -h
nginx version: nginx/1.2.7
Usage: nginx [-?hvVtq] [-s signal] [-c filename] [-p prefix] [-g directives]
Options:
 -?,-h : this help
 -v : show version and exit
 -V : show version and configure options then exit
 -t : test configuration and exit
 -q : suppress non-error messages during configuration testing
 -s signal : send signal to a master process: stop, quit, reopen, reload
 -p prefix : set prefix path (default: /usr/local/nginx/)
 -c filename : set configuration file (default: conf/nginx.conf)
 -g directives : set global directives out of configuration file
[root@localhost sbin]#

启动

[root@localhost sbin]# ./nginx
 [root@localhost sbin]# netstat -lut |grep http
 tcp 0 0 *:http *:* LISTEN
 [root@localhost sbin]#

通过浏览器访问nginx服务器
nginx-01-02

错误分析1

./configure: error: the HTTP rewrite module requires the PCRE library.
 You can either disable the module by using --without-http_rewrite_module
 option, or install the PCRE library into the system, or build the PCRE library
 statically from the source with nginx by using --with-pcre=<path> option.

错误分析2

./configure: error: the HTTP gzip module requires the zlib library.
 You can either disable the module by using --without-http_gzip_module
 option, or install the zlib library into the system, or build the zlib library
 statically from the source with nginx by using --with-zlib=<path> option.

错误分析3

./configure: error: SSL modules require the OpenSSL library.
 You can either do not enable the modules, or install the OpenSSL library
 into the system, or build the OpenSSL library statically from the source
 with nginx by using --with-openssl=<path> option.

Nginx官方文档配置参数

--prefix=path
 --sbin-path=path
 --conf-path=path
 --pid-path=path
 --error-log-path=path
 --http-log-path=path
 --user=name
 --with-select_module
 --without-select_module
 --with-poll_module
 --without-poll_module
 --without-http_gzip_module
 --without-http_proxy_module
 --with-http_ssl_module
 --with-pcre=path
 --with-pcre-jit
 --with-zlib=path
--with-cc-opt=parameters
 --with-ld-opt=parameters

Nginx官方文档配置示例

./configure
 --sbin-path=/usr/local/nginx/nginx
 --conf-path=/usr/local/nginx/nginx.conf
 --pid-path=/usr/local/nginx/nginx.pid
 --with-http_ssl_module
 --with-pcre=../pcre-4.4
 --with-zlib=../zlib-1.1.3

相关下载:
(1)nginx 1.2.7 (2)openssl 1.0.1e (3)pcre 8.32 (4)zlib 1.2.7
内容引用:
(1)