CentOS下安装Apache及依赖组件配置指南
当前CentOS系统采用Basic Server版本进行部署。在执行Apache安装操作前,需预先处理多项缺失的基础组件。以下列出本次安装过程中涉及的关键依赖项。
主要涉及的组件包括apache及其关联的apr、apr-util,以及perl中的pcre模块。
前往Apache官方网站获取安装包,具体下载入口为:http://httpd.apache.org/download.cgi
选取稳定版本httpd-2.4.9.tar.gz,将其上传至服务器的/usr/packages目录中备用。
执行Apache的编译安装流程。
# tar -xvzf httpd-2.4.9.tar.gz
# cd httpd-2.4.9
# ./configure --prefix=/usr/local/apache --enable-module=so --enable-module=rewrite
在检查编译环境阶段出现错误提示。
checking for APR... no
configure: error: APR not found . Please read the documentation.
该错误源于缺少APR(Apache Portable Runtime)支持,因此需要额外下载并安装apr与apr-util软件包。
APR组件的官方下载地址为:http://apr.apache.org/download.cgi
分别下载apr-1.5.1.tar.gz与apr-util-1.5.3.tar.gz两个压缩包。
开始对apr组件进行安装配置。
# tar -xvzf apr-1.5.1.tar.gz
# cd apr-1.5.1
# .configure
# make
# make install
接着安装apr-util组件。
# tar -xvzf apr-util-1.5.3.tar.gz
# cd apr-util-1.5.3
# .configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
# make
# make install
再次运行编译环境检查命令,依然出现报错信息。
系统提示:configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/,表明缺少PCRE库支持。
PCRE库的下载地址为:http://sourceforge.net/projects/pcre/
执行pcre组件的安装步骤。
# unzip -o pcre-8.35
# cd pcre-8.35
# ./configure --prefix=/usr/local/pcre
# make
# make install
在重新检查编译环境时,需添加特定参数以指定各依赖库的路径。
具体参数配置为:--with-apr=/usr/local/apr/ --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre
此时编译环境检查未再返回任何错误信息。
# make
# make install
依赖问题解决,安装工作顺利完成。
鉴于这是首次安装,由于未提前梳理组件间的关联关系导致过程曲折。后续安装时建议优先安装所有依赖组件,最后再安装Apache,以提升效率。
启动Apache服务。
# cp /usr/local/apache/bin/apachectl /sbin/
# apachectl start
配置系统在启动时自动加载Apache服务。
编辑配置文件:# vi /etc/rc.d/rc.local
在文件末尾追加一行:/sbin/apachectl start
调整Apache默认的站点根目录路径。
打开并编辑配置文件/usr/local/apache/conf/httpd.conf。

将相关路径指令修改为新的目标目录。

执行重启命令使配置生效 # apachectl restart
关于Apache配置文件的进一步说明待续。