cd /usr/local/src/wget http://mirrors.cnnic.cn/apache/httpd/httpd-2.4.34.tar.gzwget http://mirrors.cnnic.cn/apache/apr/apr-1.6.3.tar.gzwget http://mirrors.cnnic.cn/apache/apr/apr-util-1.6.1.tar.gz
说明:
apr和apr-util是一个通用的函数库,它让httpd可以不关心底层的操作系统平台,可以很方便的从linux移植到windos
2.解压安装包
tar zxvf ?httpd-2.4.34.tar.gztar zxvf apr-1.6.3.tar.gztar zxvf ?apr-util-1.6.1.tar.gz
3.编译安装 apr-1.6.3
cd apr-1.6.3./configure --prefix=/usr/local/apr
报错01:
[root@server-1 apr-1.6.3]# ./configure --prefix=/usr/local/aprchecking build system type... x86_64-pc-linux-gnuchecking host system type... x86_64-pc-linux-gnuchecking target system type... x86_64-pc-linux-gnuConfiguring APR libraryPlatform: x86_64-pc-linux-gnuchecking for working mkdir -p... yesAPR Version: 1.6.3checking for chosen layout... aprchecking for gcc... nochecking for cc... nochecking for cl.exe... noconfigure: error: in `/usr/local/apr-1.6.3‘:configure: error: no acceptable C compiler found in $PATHSee `config.log‘ for more details[root@server-1 apr-1.6.3]# echo $?1
解决办法:安装gcc
yum install gcc -y
再次config编译成功
[root@localhost apr-1.6.3]# ./configure --prefix=/usr/local/apr
[root@server-1 apr-1.6.3]#make && make install[root@server-1 apr-1.6.3]# echo $?0
4.编译安装apr-util-1.6.1
cd /usr/local/src/apr-util-1.6.1./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake && make install
编译安装报错
解决报错:安装expat库
yum install expat-devel -y
再次执行make && make install,报错解决
5.编译安装httpd-2.4.29
cd /usr/local/src/httpd-2.4.29./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr--with-apr-util=/usr/local/apr-util --enable-so \ ??##支持动态扩展模块,apache支持以一个动态模块存在,Apache本身就是一个进程服务--enable-mods-shared=most
编译报错01:configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/
解决办法:yum install pcre-devel -y
再次执行./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most返回如下界面,表示configure编译成功
注:如果在编译过程中出现,缺少某个依赖包,解决思路yum list |grep 包然后安装devel关键字的软件包yum install -y 软件包
make && make install 编译安装报错
说明:缺少了xml相关的库,需要安装libxml2-devel包。直接安装并不能解决问题,因为httpd调用的apr-util已经安装好了,但是apr-util并没有libxml2-devel包支持
解决办法:
参考https://blog.csdn.net/MrDing991124/article/details/78829184
重新安装libxml2-devel
yum install -y libxml2-devel
删除apr-util软件包
rm -rf /usr/local/src/apr-util-1.6.1cd /usr/local/src/
重新编译安装apr-util
tar zxvf apr-util-1.6.1.tar.gzcd apr-util-1.6.1/ ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/aprmake && make install
[root@localhost apr-util-1.6.1]# pwd/usr/local/src/apr-util-1.6.1[root@localhost apr-util-1.6.1]# cd ..[root@localhost src]#[root@localhost src]# cd httpd-2.4.34[root@localhost httpd-2.4.34]#[root@localhost httpd-2.4.34]# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most返回下面界面说明configure这步编译成功
make && make install返回下面界面说明make && make install 执行成功
root@server-1 httpd-2.4.29]# cd /usr/local/apache2.4/[root@server-1 apache2.4]# lsbin ?build ?cgi-bin ?conf ?error ?htdocs ?icons ?include ?logs ?man ?manual ?modules说明:bin目录:命令执行conf目录:配置文件所在目录htdocs目录:默认网站访问的内容就存在这个目录下logs日志目录:访问日志,服务报错日志modules目录:存放apache需要的模块[root@server-1 apache2.4]# ls ./modules/
[root@server-1 apache2.4]# ls ./htdocs/index.html[root@server-1 apache2.4]# ls ./bin/
[root@server-1 apache2.4]# ls ./logs/[root@server-1 apache2.4]# ls ./conf/extra ?httpd.conf ?magic ?mime.types ?original
查看apache服务状态,执行/usr/local/apache2.4/bin/apachectl命令后返回如下提示
[root@localhost apache2.4]# /usr/local/apache2.4/bin/apachectlAH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using localhost.localdomain. Set the ‘ServerName‘ directive globally to suppress this message
解决办法:
编译/usr/local/apache2.4/conf/httpd.conf文件,把参数 ServerName改为
ServerName localhost
注意:这里的localhost表示本机主机名,主机名可以自定义为其他
然后重启apache服务
[root@localhost src]# /usr/local/apache2.4/bin/apachectl restart[root@localhost src]# /usr/local/apache2.4/bin/apachectlhttpd (pid 71429) already running
查看apache加载的模块
/usr/local/apache2.4/bin/httpd -M
说明: apache会加载两种类型的模块static:静态模块shared:动态模块两者的区别在于,static模块是已经编译安装到/usr/local/apache2.4/bin/httpd配置文件中,而shared表示apache动态加载的模块
启动apache服务
/usr/local/apache2.4/bin/apachectl start
查看apache服务进程
[root@localhost ~]# ps aux |grep httpdroot ??????1463 ?3.0 ?0.2 253600 ?8828 ? ???????Ss ??04:19 ??0:00 /usr/local/apache2.4/bin/httpd -k startdaemon ????1464 ?2.0 ?0.2 540428 ?8916 ? ???????Sl ??04:19 ??0:00 /usr/local/apache2.4/bin/httpd -k startdaemon ????1465 ?2.0 ?0.2 540428 ?8916 ? ???????Sl ??04:19 ??0:00 /usr/local/apache2.4/bin/httpd -k startdaemon ????1470 ?1.0 ?0.2 540428 ?8912 ? ???????Sl ??04:19 ??0:00 /usr/local/apache2.4/bin/httpd -k startroot ??????1549 ?0.0 ?0.0 112704 ??972 pts/1 ???R+ ??04:19 ??0:00 grep --color=auto httpd
Apache二进制免编译安装和参数配置
原文地址:http://blog.51cto.com/liuleis/2170204