Centos 7 Apache编译安装

1.安装apache

./configure --prefix=/usr/local/apache2 --enable-rewrite --enable-so --enable-headers --enable-expires --with-mpm=worker --enable-modules=most --enable-deflate
说明:
--prefix=/usr/local/apache2表示指定apache的安装路径,默认安装路径为/usr/local/apache2
--enable-rewrite提供URL规则的重写更嫩那个,即根据已知的URL地址,转换为其它想要的URL地址
--enable-so激活apache服务的DSO(Dynamic Shared Objects动态共享目标),即在以后可以以DSO的方式编译安装共享模块,这个模块本身不能以DSO方式编译。
--enable-headers提供允许对HTTP请求头的控制。
--enable-expires激活荀彧通过配置文件控制HTTP的“Expires:”和“Cache-Control:”头内容,即对网站图片、js、css等内容,提供客户端浏览器缓存的设置。这个是apache调优的一个重要选项之一。
--with-mpm=worker选择apache mpm的模式为worker模式。为worker模式原理是更多的使用线程来处理请求,所以可以处理更多的并发请求。而系统 资源的开销小玉基于进程的MPM prefork。如果不指定此参数,默认的模式是prefork进程模式。这个是apache调优的一个重要选项之一。
--enable-deflate提供对内容的压缩传输编码支持,一般是html、js、css等内容的站点。使用此参数会打打提高传输速度,提升访问者访问的体验。在生产环境中,这是apache调优的一个重要选项之一。
 
报错:
apr not found
 

2.下载apr安装

tar –zxvf apr-1.5.2.tar.gz
 ./configure --prefix=/usr/local/apr
再次安装
报错:
APR-util not found
 

3.安装apr-util

[root@bogon apr-util-1.6.0]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr && make && make install
 

4.安装apr-util报错:

expat.h: No such file or directory
解决办法:
yum install expat-devel
 

5.再次安装apr-util

[root@bogon apr-util-1.6.0]# ./configure --prefix=/usr/local/apr-util -with-apr=/usr/local/apr && make && make install
成功
 

6.重新安装httpd:

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-rewrite --enable-so --enable-headers --enable-expires --with-mpm=worker --enable-modules=most --enable-deflate
 

7.出现报错:

error: mod_deflate has been requested but can not be built due to prerequisite failures
解决办法:
yum install zlib-devel -y
 

8.重新安装httpd:

./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-rewrite --enable-so --enable-headers --enable-expires --with-mpm=worker --enable-modules=most --enable-deflate
安装成功
 

9.测试Apache

apache的启动脚本链接到/etc/rc.d/init.d这个目录下
ln -s /usr/local/apache/bin/apachectl /etc/init.d/httpd
 

10.启动服务

/etc/init.d/httpd start
 

11.查看端口

[root@bogon bin]# netstat -lntp | grep 80
tcp 0 0 0.0.0.0:8080 0.0.0.0:* LISTEN 3057/nginx: master
tcp6 0 0 :::80 :::* LISTEN 40953/httpd
 

12.apache加入系统服务

为了让apache开机启动,我们可以把apachectl启动脚本加入rc.local文件中,如下:
echo "/usr/local/apache2/bin/apachectl start">>/etc/rc.local
在/etc/init.d/httpd文件中第二行添加
# chkconfig: 2345 10 90
# description: Activates/Deactivates Apache Web Server
使用chkconfig进行添加,如下:
chkconfig --add httpd
chkconfig --add httpd命令的作用是把/etc/init.d/httpd加入到/etc/rc.d/rc0.d到/etc/rc.d/rc6.d目录下
开启apache开机启动,使用如下命令:
chkconfig httpd on
chkconfig |grep httpd
原文地址:https://www.cnblogs.com/EWWE/p/7118729.html