下载apache

1
2
3
wget -P /usr/local/src http://apache.melbourneitmirror.net//httpd/httpd-2.4.33.tar.gz
wget -P /usr/local/src http://archive.apache.org/dist/apr/apr-1.6.2.tar.gz
wget -P /usr/local/src http://archive.apache.org/dist/apr/apr-util-1.6.0.tar.gz

安装依赖包

1
yum -y install  gcc-c++ openssl-devel zlib-devel pcre-devel

解压安装

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
for i in $(ls /usr/local/src/|grep 'gz'|xargs);do tar xf $i;done

cd /usr/local/src/apr-1.6.2

./configure --prefix=/usr/local/apr

make && make Install

cd /usr/local/src/apr-util-1.6.0

./configure --prefix=/usr/local/apr-util

make && make Install

cd /usr/local/src/http-2.4.33

./configure --prefix=/usr/local/httpd --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --enable-so --enable-deflate=shared --enable-expires=shared --enable-rewrite=shared --enable-ssl=shared --with-pcre --enable-mods-shared=most --enable-headers --enable-mime-magic --enable-proxy --with-ssl --enable-ssl --enable-deflate --enable-suexec --with-mpm=prefork --with-expat=builtin --enable-http2

make && make Install

修改配置文件

1
2
3
4
5
6
7
sed -i "392a AddType application/x-httpd-php .php" /usr/local/httpd/conf/httpd.conf
sed -i "s/$/ index.htm index.php" /usr/local/httpd/conf/httpd.conf
sed -i "s@#ServerName *80@ServerName 0.0.0.0:80@" /usr/local/httpd/conf/httpd.coonf
sed -i "s@User daemon@User www@" /usr/local/httpd/conf/http.conf
sed -i "s@Group daemon@Group www@" /usr/local/httpd/conf/http.conf
sed -i "393a PHPIniDir /usr/local/php/etc/php.ini" /usr/local/httpd/conf/httpd.conf
sed -i "491a Include /usr/local/httpd/conf.d/*.conf" /usr/local/httpd/conf/httpd.conf

添加虚拟主机配置目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
mkdir /usr/local/httpd/conf.d

cat << eof sudo tee /usr/local/http/conf.d/vhost.conf
<VirtualHost *:80>
Protocols h2c http/1.1
DocumentRoot "/webapps/zabbix"
ServerName www.server.com
#ServerAlias hx-www.server.com
#ErrorLog "/home/wwwlogs/www.server.com-error_log"
#CustomLog "/home/wwwlogs/www.server.com-access_log" combined
<Directory "/webapps/zabbix">
Options FollowSymLinks
Require all granted

DirectoryIndex index.php index.html
</Directory>
</VirtualHost>
eof

添加系统服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat <<eof sudo tee /usr/lib/systemd/system/httpd.service
[Unit]
Description=Apache
After=syslog.target network.target

[Service]
#User=apache
#Group=apache
Type=forking
ExecStart=/usr/local/httpd/bin/httpd
ExecReload=/usr/local/httpd/bin/httpd -k restart
ExecStop=/usr/local/httpd/bin/httpd -k stop

[Install]
WantedBy=multi-user.target
eof