安装前准备
yum -y install gcc
yum -y install openssl
yum -y install openssl-devel
yum -y install curl
yum -y install curl-devel
yum -y install bzip2
yum -y install bzip2-devel
下载apache安装包并解压
Download - The Apache HTTP Server Project
创建apache的待安装目录 /usr/local/
mkdir /usr/local/apache
下载依赖包apr-1.7.0.tar.gz apr-util-1.6.1.tar.gz
Download - The Apache Portable Runtime Project
安装apr-1.7.0
cd apr-1.7.0
./configure --prefix=/usr/local/apr
make
make install
安装apr-util-1.6.1
cd apr-util-1.6.1
./configure --prefix=/usr/local/apr-util-1.6.1 --with-apr=/usr/local/apr
make
make install
这里直接make编译的时候会报错,如果报错,就是少了一个expat库,需要编译前安装,错误信息如下:
xml/apr_xml.c:35:19: error: expat.h: No such file or directory
xml/apr_xml.c:66: error: expected specifier-qualifier-list before ‘XML_Parser’
xml/apr_xml.c: In function ‘cleanup_parser’:
xml/apr_xml.c:364: error: ‘apr_xml_parser’ has no member named ‘xp’
xml/apr_xml.c:365: error: ‘apr_xml_parser’ has no member named ‘xp’
yum安装expat-devel
yum install expat-devel
下载pcre-8.42.tar.gz 并解压,创建待安装目录
PCRE - Browse Files at SourceForge.net (注意别下载pcre2开头的)
安装pcre-8.42
cd pcre-8.42
./configure --prefix=/usr/local/pcre
make
make install
安装apache
cd httpd-2.4.51
./configure --prefix=/usr/local/apache --sysconfdir=/etc/httpd --enable-so --enable-rewirte --enable-ssl --enable-cgi --enable-cgid--enable-modules=most --enable-modules-shared=most --enable-mpms-shared=all --with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
make
make install
出现如下报错解决方法
make[2]: [htpasswd] 错误 1
make[2]: 离开目录“/usr/local/src/httpd-2.4.51/support”
make[1]: [all-recursive] 错误 1
make[1]: 离开目录“/usr/local/src/httpd-2.4.51/support”
make: *** [all-recursive] 错误 1
解决方法:
(1)在configure后加上 “--with-included-apr”。再重新编译, make, make install
(2)如果在添加上述语句后又再次报错,内容如下:
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.
解决方法:
将解压后的apr-1.7.0、apr-util-1.6.1、pcre-8.42这三个文件拷贝到/usr/local/httpd-2.4.51/srclib/下 :具体操作如下:
cp apr-1.7.0 /usr/local/httpd-2.4.51/srclib/apr
cp apr-util-1.6.1 /usr/local/httpd-2.4.51/srclib/apr-util
cp pcre-8.42 /usr/local/httpd-2.4.51/srclib/pcre
状态命令
启动:/usr/local/apache/bin/apachectl start
停止:/usr/local/apache/bin/apachectl stop
重启:/usr/local/apache/bin/apachectl restart