安装环境:CentOS Linux release 7.0.1406 (Core)
0x01
到官网http://httpd.apache.org/download.cgi#apache24下载apache http最新版
tar zxf httpd-2.4.18.tar.gz
[[email protected] httpd-2.4.18]# rpm -qa | grep apr 查看当前主机上是否安装apr/apr-util,这个库为apache提供跨平台的支持
[[email protected] httpd-2.4.18]# yum install apr apr-util 这两个包在光盘镜像都有,配置和yum源即可
使用yum安装的apr位置信息
[[email protected] httpd-2.4.18]# rpm -ql apr
/usr/lib64/libapr-1.so.0
/usr/lib64/libapr-1.so.0.4.8
/usr/share/doc/apr-1.4.8
/usr/share/doc/apr-1.4.8/CHANGES
/usr/share/doc/apr-1.4.8/LICENSE
/usr/share/doc/apr-1.4.8/NOTICE
[[email protected] httpd-2.4.18]# rpm -ql apr-util
/usr/lib64/apr-util-1
/usr/lib64/libaprutil-1.so.0
/usr/lib64/libaprutil-1.so.0.5.2
/usr/share/doc/apr-util-1.5.2
/usr/share/doc/apr-util-1.5.2/CHANGES
/usr/share/doc/apr-util-1.5.2/LICENSE
/usr/share/doc/apr-util-1.5.2/NOTICE
0x02 Apache编译选项
--prefix=/usr/local/apache
--sysconfdir=/etc/httpd
--with-apr=/usr/local/apr
--with-apr-util=/usr/local/apr-util
--enable-so //打开 so 模块,so 模块是用来提 DSO 支持的,提供动态共享模块与php协作
--enable-ssl //https使用
--enable-cgi //为非线程方式工作的mpm使用
--enable-rewrite //支持 URL 重写
--enable-zlib //通用压缩机制
--with-pcre
--enable-module=most
--enable-mpms-shared=most //启用哪种mpm(prefork,worker,event),使用worker或event时要另外一种方式编译php(编译时使用了–enable-maintainer-zts选项)
--with-mpm=MPM //指定默认的mpm
--enable-deflate //传输压缩机制,节约带宽
--enable-cgid //以线程工作(worker/event)的mpm使用
更多的选项可以通过./configure --help 了解
官方的编译选项文档http://httpd.apache.org/docs/current/programs/configure.html
0x03 安装
[[email protected] httpd-2.4.18]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-zlib --enable-module=most --enable-mpms-shared=most --with-mpm=event
使用以上编译选项进行编译,编译的时候发现报错,难道使用yum安装的apr就不行了吗?还是因为版本问题导致的。其实这里说明apr-config文件,但是apr的rpm包并未包含,所以应该安装apr-devel的rpm包。这里用源码安装解决
checking for APR... configure: error: the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.
1、到官网下载apr和apr-util源码安装。
[[email protected] httpd-2.4.18]# tar zxf /mymnt/mnt/apr-1.5.2.tar.gz -C /usr/local/src/
[[email protected] httpd-2.4.18]# tar zxf /mymnt/mnt/apr-util-1.5.4.tar.gz -C /usr/local/src/
[[email protected] apr-1.5.2]# ./configure --prefix=/usr/local/apr
[[email protected] apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[[email protected] httpd-2.4.18]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-zlib --enable-module=most --enable-mpms-shared=most --with-mpm=event --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
2、安装完apr后还需要安装pcre,打算到官网下载的,很简洁的网页,但是下载页面打不开。在yum源中找到了
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
[[email protected] httpd-2.4.18]# yum install pcre-devel
3、继续执行checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures,这是因为缺少openssl
[[email protected] httpd-2.4.18]# yum install openssl-devel
4、最后出现的一个报错是configure: error: MPM most does not support dynamic loading.
从字面上可以了解,此时将--enbale-mpm-shared改为all即可
make && make install
0x04 如何启动
没有做任何设置尝试启动时 [[email protected] apache2]# bin/apachectl start
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName‘ directive globally to suppress this message
更改下主机名即可或者直接忽略
Apache 没有带服务脚本,所以需要自己编写一个用来实现开机启动。当然这里临时使用的就略过了