1、安装apache之前先确认Linux的基本编译环境是否正常安装,如果没有使用管理用户执行以下命令:

yum install -y gcc*
yum install -y glib*
yum install -y libtool
否则在安装过程中会报错:
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring APR library
Platform: x86_64-unknown-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.5.2
checking for chosen layout... apr
checking for gcc... no
checking for cc... no

2、以上编译环境安装好后,开始安装apache必须要的apr库。不同的apache版本有需要匹配不同的版本的apr安装包。先将下载好的apr安装包拷贝到服务目录下,我使用的apr-1.5.2.tar.gz

然后解压安装包文件tar -zxf apr-1.5.2.tar.gz

[

root@ensemble1 app]# tar -zxf apr-1.5.2.tar.gz
然后进入安装目录apr-1.5.2执行以下命令
[root@ensemble1 apr-1.5.2]# ./configure --prefix=/usr/local/apr
安装成功后开始进行编译安装,执行以下命令:
[root@ensemble1 apr-1.5.2]# make && make install
3、安装apache之前先确认apr是不是安装了,如果没有安装先安装apr-util
[root@ensemble1 app]# tar -zxf apr-util-1.5.4.tar.gz
[root@ensemble1 app]# cd apr-util-1.5.4
然后进行编译安装:
[root@ensemble1 apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config
[root@ensemble1 apr-util-1.5.4]# make && make instal
4、安装pcre,使用的是pcre-8.10版本,将安装包上传到服务器进行解压
[root@ensemble1 app]# unzip pcre-8.10.zip
[root@ensemble1 app]# cd pcre-8.10
编译安装
[root@ensemble1 pcre-8.10]# ./configure --prefix=/usr/local/pcre
[root@ensemble1 pcre-8.10]# make && make install
5、安装apache
使用的是httpd-2.4.46安装包,将安装包解压到/app/app目录下
在httpd-2.4.46安装目录下执行
[root@ensemble1 httpd-2.4.46]tar -zxf httpd-2.4.46.tar.gz
[root@ensemble1 httpd-2.4.46]cd httpd-2.4.46
[root@ensemble1 httpd-2.4.46]# ./configure --prefix=/app/app/apache24 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre  --enable-so --enable-rewrite
注意:此处安装的Apache是没有启用SSL模块的,也可以直接修改这个命令直接加载SSL库,这样就不用执行第6步,我实现安装未配置SSL模块然后再增加SSL卸载。命令如下:
[root@ensemble1 httpd-2.4.46]# ./configure --prefix=/app/app/apache24 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre  --with-ssl =/usr/local/openssl --enable-so --enable-rewrite --enable-ssl

然后开始安装:

[root@ensemble1 httpd-2.4.46]# make && make instal
安装完成后启动时候报一下错误:
[root@ensemble1 bin]# ./apachectl configtest
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::f816:3eff:feb8:c6e7. Set the 'ServerName' directive globally to suppress this message
Syntax OK
[root@ensemble1 bin]# ./apachectl start
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::f816:3eff:feb8:c6e7. Set the 'ServerName' directive globally to suppress this message
原因:
http.conf 文件中没有配置ServerName localhost
处理方案:修改http.conf文件的配置,增加ServerName localhost
#ServerName www.example.com:80
ServerName localhost

6、配置SSL卸载的so库,及配置文件

第一步,检查安装的apache是否安装了SSL的,上面安装的httpd是不带SSL模块的,需要手动加载SSL的so库。

第二步,把apache源码包里的modules/md文件夹中的所有文件复制到/usr/include/目录

[root@ensemble1 bin]$ cp /app/tools/httpd-2.4.46/modules/md/* /usr/include/
第三步,执行以下代码,安装SSL模块
[root@ensemble1 bin]$ cd /app/tools/httpd-2.4.46
[root@ensemble1 httpd-2.4.46]$ /app/app/apache24/bin/apxs -a -i -DHAVE_OPENSSL=1 -I/usr/include/openssl -L/usr/lib64/openssl -c /app/tools/httpd-2.4.46/modules/ssl/*.c -lcrypto -lssl –ldl

注意:apxs 命令是 apache编译安装模块的命令

             -I  安装

             -a激活模块(向httpd.conf添加LoadModule ssl_module modules/mod_ssl.so指令)

             -c编译指定的模块

执行以上步骤时,必须确保linux系统安装了openssl ,如果没有先使用root用户执行以下命令

yum install -y openssl openssl-devel

7、在安装完成的apache配置对应的SSL站点服务器证书到服务器的目录,然后修改配置文件,增加SSL卸载配置

证书目录:/app/app/apache24/crt

配置文件:

Listen 8855
<VirtualHost *:8855>
            DocumentRoot "/app/app/shared"
            ServerName www.xxxx.com
            ServerAlias www.xxxx.com
            ErrorLog "logs/8899/error-xxxx.log"
            CustomLog "logs/8899/access-xxxx.log" common
            SSLEngine on
            SSLProtocol -all +TLSv1.2 +TLSv1.1 +TLSv1
SSLCipherSuite DHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4
            SSLCertificateFile "/app/app/apache24/crt/server.crt"
            SSLCertificateKeyFile "/app/app/apache24/crt/server.key"
            SSLCertificateChainFile "/app/app/apache24/crt/cfca.crt"
</VirtualHost>

然后到/app/app/apache24/bin目录下增加执行 ./apachectl restart  重启apache,在浏览器中输入https://www.xxxx.com:8855/aaaa  ,此时证书加载成功