- 下载apache
wget https://dlcdn.apache.org//httpd/httpd-2.4.51.tar.gz --no-check-certificate
- 下载依赖
wget https://dlcdn.apache.org//apr/apr-1.7.0.tar.gz --no-check-certificate
wget https://dlcdn.apache.org//apr/apr-util-1.6.1.tar.gz --no-check-certificate
- 安装依赖
tar -zxvf apr-1.7.0.tar.gz
cd apr-1.7.0
./configure --prefix=/usr/local/apr
make && make install
yum install expat-devel
tar -zxvf apr-util-1.6.1.tar.gz
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
make && make install
- 安装apache
tar -zxvf httpd-2.4.51.tar.gz
cd httpd-2.4.51
##./configure --prefix=/usr/local/apache --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-so --enable-mods-shared=most
##./configure --prefix=/usr/local/apache --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-modules=most --enable-mods-shared=most --enable-mpms-shared=all --with-mpm=prefork --with-zlib --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
./configure --prefix=/usr/local/apache --enable-mods-shared=most --enable-headers --enable-mime-magic --enable-proxy --enable-so --enable-rewrite --enable-ssl --with-ssl --enable-deflate --with-pcre --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --enable-mpms-shared=all --enable-remoteip
make && make install
编译说明:
–prefix 指明程序安装目录 --enable-so 表示启用模块的动态装卸载功能
--enable-ssl 表示启用ssl功能,此项可能需要先安装openssl-devel包
--enable-cgi 表示启用支持cgi机制的功能 --enable-rewrite 表示支持url重写功能
--enable-modules=most 表示启用的http模块有哪些,most表示启动大多数
--enable-mpms-shared=all 表示以共享方式启用哪些MPM模块(prefork、worker、event), all表示所有的,此项为httpd2.4独有的选项,因为只有2.4才支持MPM的动态装卸载,2.2的MPM为静态的,只有编译进去,才能使用
--with-mpm=prefork 表示默认启动的MPM是哪种
--with-zlib 表示依赖zlib,用于支持压缩功能 没用=等号指明zlib的路径,则系统会自动到被依赖的文件的默认的路径去寻找, 如果被依赖的文件不是rpm安装,或不放在默认路径下,则需要手动利用=等号指明路径
--with-pcre 表示依赖的pcre,用于支持url重写时支持正则表达式 --with-apr 依赖的apr
--with-apr-util 依赖的apr-util
#复制服务
cp /usr/local/apache/bin/apachectl /etc/init.d/httpd
#配置支持chkconfig
vi /etc/init.d/httpd
#在!/bin/sh后面添加如下代码
#chkconfig:345 85 15
#
#description:Start and stop the Apache HTTP Server
#添加服务启动项
chkconfig --add httpd
#自启
chkconfig httpd on
#检查
chkconfig --list httpd
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
httpd 0:关 1:关 2:开 3:开 4:开 5:开 6:关
- 修改apache监听端口为88(避免和nginx商品冲突)
vi /usr/local/apache/conf/httpd.conf
#开放88端口
firewall-cmd --zone=public --add-port=88/tcp --permanent
firewall-cmd --reload
firewall-cmd --query-port=88/tcp
- 启动apache
service httpd start
备注:如果service httpd start报如下错
AH00558: httpd: Could not reliably determine the server’s fully qualified domain name, using ::1. Set the ‘ServerName’ directive globally to suppress this message
打开vi /usr/local/apache/conf/httpd.conf
修改#ServerName www.example.com:80为ServerName localhost:88
重启httpd即可