下载有相关的包 pcre-8.20.tar.bz2,apr-1.6.3.tar.gz,apr-util-1.6.1.tar.gz httpd-2.4.33.tar.gz
apache安装需要依赖于apr以及apr-util,apr-util安装要有pcre,已安装,可跳过,但是如果版本不对,会报xml找不到一些变量。
1.安装pcre
tar -xjf pcre-8.20.tar.bz2 -C /usr/local/pcre/
./configure
make
make install
pcre 编辑器要求 gcc ,没有要安装由于http协议以及gcc对时间有精确的要求,需要同步时间。
同步时间可以使用ntpdate命令或者date命令
make的时候报错,是少了gcc-c++
libtool: compile: Try `libtool --help' for more information.
make[1]: *** [pcrecpp.lo] Error 1
make[1]: Leaving directory `/usr/local/pcre'
make: *** [all] Error 2
执行下面的安装命令可解决
yum -y install gcc-c++
2.解压
httpd-2.4.33.tar.gz
mkdir /home/httpd/
tar -xzvf httpd-2.4.33.tar.gz -C /home/httpd/
3.解压apr和apr-util,移动到
tar -xzvf apr-1.6.3.tar.gz
tar -xzvf apr-util-1.6.1.tar.gz
mv apr-1.6.3 /home/httpd/srclib/apr
mv apr-util-1.6.1 /home/httpd/srclib/apr-util
注:srclib目录下的名称必须是apr和apr-util,要么在编译apache的时候会报错,找不到目录
4.编译apache
cd /home/httpd/
mkdir /home/apache2
./configure --prefix=/home/apache2 --with-included-apr --with-pcre=/usr/local/pcre/bin
在编译的时候遇到一个错误:
xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory
在网上查找说可能是少了expat库,yum install expat-devel 安装该库,安装完再次编译,果然可以。
然后make最后make install
如果make install 报错
例:libtool: install: error: cannot install `libaprutil-1.la' to a directory not ending in /usr/local/apache2/lib
就因为之前安装过,重新安装没有清理干净
make clean 就可以了
安装完成后测试一下/home/apache2/bin/apachectl start如果启动报错:
httpd: Could not reliably determine the server's fully qualified domain name
vim 打开 httpd.conf,将里面的 #ServerName localhost:80 注释去掉即可。启动完成后http://ip/
出现it works!页面说明安装成功
https://blog.csdn.net/hsd2012/article/details/51518383