centos系统编译apache-2.4.x常见错误总结

作者:袖梨 2022-11-14

系统:centos 5.x
需要的软件包:httpd-2.4.9.tar.gz
apr-1.5.0.tar.gz
apr-util-1.5.3.tar.gz
pcre-8.35.tar.gz
1.先把依赖包安装完

代码如下 复制代码
yum -y install gcc gcc-c++ libtool-libs autoconf
freetype-devel gd libjpeg-devel libpng-devel libxml2-devel
ncurses-devel zlib-devel zip unzip curl-devel wget crontabs
file bison cmake patch mlocate flex diffutils automake make
kernel-devel cpp readline-devel openssl-devel vim-minimal
glibc-devel glib2-devel bzip2-devel e2fsprogs-devel
libidn-devel gettext-devel expat-devel libcap-devel
libtool-ltdl-devel pam-devel pcre-devel libmcrypt-devel

2.编译apache-2.4.9

代码如下 复制代码

wget http://mirror.esocc.com/apache//httpd/httpd-2.4.9.tar.gz

tar zxf httpd-2.4.9.tar.gz && cd httpd-2.4.9
./configure --prefix=/usr/local/apache --enable-so
--enable-deflate=shared --enable-ssl=shared --enable-expires=shared
--enable-headers=shared --enable-rewrite=shared --enable-static-support --with-included-apr

这里出现了第一个错误:
configure: error: Bundled APR requested but not found at ./srclib/. Download and unpack the corresponding apr and apr-util packages to ./srclib/.

说是需要把apr和apr-util解压到apache的./srclib/目录里.
解决办法:

代码如下 复制代码

wget http://mirror.esocc.com/apache//apr/apr-1.5.0.tar.gz
wget http://mirror.esocc.com/apache//apr/apr-util-1.5.3.tar.gz

tar zxf apr-1.5.0.tar.gz && cp -fr apr-1.5.0 ./httpd-2.4.9/srclib/apr
tar zxf apr-util-1.5.3.tar.gz && cp -fr apr-util-1.5.3 ./httpd-2.4.9/srclib/apr-util

然后重新执行./configure --prefix=.....

在执行make的时候,报第2个错误:
error: 'PCRE_DUPNAMES' undeclared (first use in this function)

网上搜了下说是yum安装的pcre的版本太老了,不支持PCRE_DUPNAMES 和 PCRE_JAVASCRIPT_COMPAT 这样的PCRE特性.好吧,我去下个最新版的pcre来编译安装.

解决办法:

代码如下 复制代码
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.35.tar.gz
tar zxf pcre-8.35.tar.gz && cd pcre-8.35
./configure
make && make install

编译完成后,我们重新对httpd-2.4.9执行编译,这下就不会继续报错.

3.当编译完成LAMP环境后,我们要启动apache来检查是否有问题
由于还没有做软链和启动服务项,所以先暂时用这条命令来启动:
/usr/local/apache/bin/apachectl start

发现报错:
httpd: Syntax error on line 149 of /usr/local/apache/conf/httpd.conf: Cannot load modules/libphp5.so into server: /usr/local/apache/modules/libphp5.so: cannot restore segment prot after reloc: Permission denied

很明显的selinux的权限问题,解决办法:

代码如下 复制代码
chown -R apache:apache /usr/local/apache
setenforce 0
chcon -c -v -R -u system_u -r object_r -t textrel_shlib_t /usr/local/apache/modules/libphp5.so

最后启动apache:
/usr/local/apache/bin/apachectl start好了,没有问题了.

原文来自:blog.slogra.com

相关文章

精彩推荐