1.首先需要四个安装包
1.1apache下载路径http://mirror.bit.edu.cn/apache/
1.2相关依赖下载路径http://apr.apache.org/download.cgi
rm -rf apr-1.6.3、rm -rf apr-util-1.6.1、rm -rf pcre-8.42、rm -rf httpd-2.4.33
- 1
2.liunx命令将其解压
tar -xjf apr-1.6.3.tar.bz2、tar -xjf pcre-8.42.tar.bz2、tar -xjf apr-util-1.6.1.tar.bz2、tar -zxvf httpd-2.4.33.tar.gz
- 1
3.切入到解压目录
3.1
cd apr-1.6.3
./configure --prefix=/usr/local/apr
注意:"apr"的路径需要自己创建目录,命令mkdir apr
make
make install
cd ..
- 1
- 2
- 3
- 4
- 5
- 6
3.2
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr 注意:"apr-util"的路径需要自己创建目录,命令mkdir apr-util make make install cd ..
- 1
- 2
- 3
- 4
- 5
- 6
3.3
cd pcre-8.42
./configure --prefix=/usr/local/pcre
注意:"pcre"的路径需要自己创建目录,命令mkdir pcre
make
make install
cd ..
- 1
- 2
- 3
- 4
- 5
- 6
如果出现:
报错xml/apr_xml.c:35:19: fatal error: expat.h: No such file or directory在网上查找说可能是少了expat库,yum install expat-devel安装该库,安装完再次编译,果然可以。
4.安装apache
版本是2.4.33
rpm -ivh expat-devel-2.0.1-11.el6_2.x86_64.rpm
- 1
tar安装包的apache安装命令,不同命令导入相关so文件不一样。
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --enable-module=so --enable-mods-shared=most --enable-module=rewirte --enable-cache --enable-file-cache --enable-mem-cache --enable-so --enable-track-vars --enable-disk-cache --disable-cgid --disable-cgi
- 1
tar安装包的apache安装命令
./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre --enable-module=so --enable-mods-shared=all --enable-module=rewirte --enable-cache --enable-file-cache --enable-mem-cache --enable-so --enable-track-vars --enable-disk-cache --disable-cgid --disable-cgi
- 1
- 2
- 3
- 4
- 5
tar安装包的apache安装命令
./configure --prefix=/usr/local/apache
--enable-mods-shared=most
--enable-deflate
--enable-speling
--enable-cache
--enable-file-cache --enable-disk-cache --enable-mem-cache --enable-rewrite --enable-so --enable-track-vars --enable-rewrite --with-z-dir=/usr/local/zlib --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-included-apr make && make install
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
版本2.2.31
./configure --prefix=/usr/local/apache
--enable-mods-shared=most
--enable-deflate
--enable-speling
--enable-cache
--enable-file-cache --enable-disk-cache --enable-mem-cache --enable-rewrite --enable-so --enable-track-vars --enable-rewrite --with-included-apr
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
5.启动apache
安装完成后,需要在Apache的配置文件中增加:
ServerName localhost:80
然后Apache便可以正常启动:
/usr/local/apache/bin/apachectl start
Apache便可以正常关闭命令:
/usr/local/apache/bin/apachectl stop
Apache便可以正常重启命令:
/usr/local/apache/bin/apachectl restart
6.如何添加例如mod_rewrite.so文件
重新编译mod_rewrite.so:
在apache的源码安装目录中寻找mod_rewrite.c文件
find / -name mod_rewrite.c
/home/springshine/LAMP/httpd-2.2.3/modules/mappers/mod_rewrite.c
编译:
cd /home/springshine/LAMP/httpd-2.2.3/modules/mappers/
/usr/local/apache2/bin/apxs -c mod_rewrite.c
/usr/local/apache2/bin/apxs -i -a -n mod_rewrite mod_rewrite.la
如果没出错,在/usr/local/apache2/modules/ 中就会有mod_rewrite.so了
7.如果启动服务的时候总是出现这个提示Redirecting to /bin/systemctl start httpd.service
/bin/systemctl start httpd.service 启动
8.Invalid command ‘ProxyPass’, perhaps misspelled or defined by a module …
看看配置文件httpd,问题出在 ProxyPass 这个环节:
ProxyPass /vict_service http://localhost:8080/vict_service
也就是要为 /vict_service 这个请求路径匹配一个实际可用的路径,既然提示ProxyPass命令无效,那么肯定是某个地方的设置问题。
解决的方法就在httpd这个配置文件里,找到以下两条:
#LoadModule proxy_module modules/mod_proxy.so
#LoadModule proxy_http_module modules/mod_proxy_http.so
- 1
- 2
前面有# 号,说明被注释掉了,不起作用,把#号去掉,就可以了。