编译安装
安装前先执行:
# yum install -y gcc gcc-c++
# yum install -y expat expat-devel openssl-devel
下载apache httpd 2.4,安装包中不包含APR 、APR-Util 和 Perl-Compatible Regular Expressions Library (PCRE),如系统中没有安装过,需下载安装。
注意:apr和apr-util要使用1.5.x版本,pcre使用pcre-8.x。
下载安装包后解压,进入根目录,分别执行以下命令:
安装apr
# ./configure --prefix=/usr/local/apr
# make
# make install
安装apr-util
# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install
安装pcre
# ./configure --prefix=/usr/local/pcre
# make
# make install
安装httpd
# ./configure --prefix=/usr/local/apache2.4 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-mods-shared=most --enable-ssl
# make
# make install
启动httpd
$ /usr/local/apache2.4/bin/apachectl start
若启动后报错: Failed to lookup provider 'shm' for 'slotmem': is mod_slotmem_shm loaded?
修改httpd.conf配置文件,放开该模块即可。
在RHEL 7上使用YUM安装
RHEL默认的 repository中提供的httpd一般不是最新版本,要安装新版本可以使用CodeIT repositoriy(提供最新版本的Apache和Nginx)。
先安装EPEL
# rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm
安装CodeIT repositoriy
cd /etc/yum.repos.d && wget https://repo.codeit.guru/codeit.el7.repo
安装httpd
# yum install httpd
附:
httpd.conf生产环境安全配置
ServerTokens Prod
Header always set Strict-Transport-Security "max-age=8640000; includeSubDomains; preload"
使用YUM安装PHP 7.2
# rpm -Uvh http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
# yum --enablerepo=remi-php72 install php
How to Install The Latest Apache Server (httpd) on Centos 7
How to Install PHP 7.2, Apache 2.4, MySQL 5.6 on CentOS/RHEL 7.4 & 6.9