一、编译环境准备
apt-get install gcc apt-get install make apt-get install gcc-c++ apt-get install make automake apt-get install cmake apt-get install libpcre3 libpcre3-dev apt-get install libtool apt-get install openssl apt-get install libxml2 libxml2-dev apt-get install libmhash-dev apt-get install libmcrypt-dev apt-get install mcrypt apt-get install curl apt-get install libbz2-dev apt-get install libssl-dev libsslcommon2-dev
上面就是一些编译工具外加一些可以借用的第三方软件,例如pcre和openssl mcrypt 等,这些第三方软件其实是为了给apache和php调用的,这样就能增加其功能。
二、编译安装apache
编译安装zlib
tar -zxpf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./configure --prefix=${SOFT_DIR};make -j2 && make install
编译安装apr
tar -zxpf apr-1.5.2_change.tar.gz cd apr-1.5.2 ./configure --prefix=${SOFT_DIR}/apr;make -j2 && make install
编译安装apr-util
tar -zxpf apr-util-1.5.4.tar.gz cd apr-util-1.5.4 ./configure --prefix=${SOFT_DIR}/apr-util --with-apr=/usr/local/apr/bin/apr-1-config;make -j2 && make install
编译安装apache
tar -zxpf httpd-2.4.16.tar.gz cd httpd-2.4.16 ./configure --prefix=${APACHE_DIR} \ --with-mpm=prefork \ --enable-so \ --enable-rewrite \ --enable-mods-shared=most \ --with-apr=/usr/local/apr \ --with-apr-util=/usr/local/apr-util make -j2 && make install
备注:
1.${APACHE_DIR} 是apache的安装目录,具体直接写也可以
2.${SOFT_DIR} 是普通软件的安装目录,一般是/usr/local,这样方便使用,apr和apr-util之所以要特别写安装路径是因为apache编译的时候需要指定这2个软件的目录
3. 可参考下面设置
# tar xf httpd-2.4.9.tar.bz2
以下为几个主要的配置项
--sysconfdir=/etc/httpd24 指定配置文件路径
--enable-so 启动模块动态装卸载
--enable-ssl 编译ssl模块
--enable-cgi 支持cgi机制(能够让静态web服务器能够解析动态请求的一个协议)
--enable-rewrite 支持url重写 --Author : Leshami
--with-zlib 支持数据包压缩 --Blog : http://blog.youkuaiyun.com/leshami
--with-pcre 支持正则表达式
--with-apr=/usr/local/apr 指明依赖的apr所在目录
--with-apr-util=/usr/local/apr-util/ 指明依赖的apr-util所在的目录
--enable-modules=most 启用的模块
--enable-mpms-shared=all 以共享方式编译的模块
--with-mpm=prefork 指明httpd的工作方式为prefork
# cd httpd-2.4.9
# ./configure \
--with-apr=/usr/local/apr \
--with-apr-util=/usr/local/apr-util \
--prefix=/usr/local/apache \
--sysconfdir=/etc/httpd24 \
--enable-so \
--enable-ssl \
--enable-cgi \
--enable-rewrite \
--with-zlib \
--with-pcre \
--with-mpm=prefork \
--enable-modules=most \
--enable-mpms-shared=all
三、配置http2.4启动及停止
1、修改端口号
修改端口号使得与2.2版本使用不同的端口,可以同时运行,修改后如下
# cat /etc/httpd24/httpd.conf |grep Listen |grep -v ^#
Listen 8080
2、启动与停止
# /usr/
local
/apache/bin/apachectl start
# netstat -nltp|grep 80
tcp 0 0 :::8080 :::* LISTEN 17365/httpd
# /usr/
local
/apache/bin/apachectl status
Not
Found
The requested URL /server-status was
not
found
on
this server.
同是要确认httpd-info.conf 被引入否则修改下httpd.conf<Location /server-status> SetHandler server-status Order deny,allow #Deny from all Allow from all </Location> ExtendedStatus On <IFModule mod_info.c> <Location /server-info> SetHandler server-info Order deny,allow #Deny from all Allow from all </Location> </IFModule>
# Real-time info on requests and configuration Include conf/extra/httpd-info.conf
# /usr/
local
/apache/bin/apachectl restart
# /usr/
local
/apache/bin/apachectl status
Apache Server Status
for
localhost (via 127.0.0.1)
Server Version: Apache/2.4.9 (Unix)
Server MPM: prefork
..........
# /usr/
local
/apache/bin/apachectl stop
备注:出现 lynx: command not found 则做如下处理:apt-get install lynx -y
直接在extra/httpd-info.conf 增加以下内容
同是要确认httpd-info.conf 被引入否则修改下httpd.conf<Location /server-status> SetHandler server-status Order deny,allow #Deny from all Allow from all </Location> ExtendedStatus On <IFModule mod_info.c> <Location /server-info> SetHandler server-info Order deny,allow #Deny from all Allow from all </Location> </IFModule>
# Real-time info on requests and configuration Include conf/extra/httpd-info.conf