Apache安装、配置、启动及添加服务

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

Apache安装、配置、启动及添加服务

1 安装

下载:

httpd-2.4.1.zip

apr-1.4.5.tar.gz

apr-util-1.3.12.tar.gz

pcre-8.10.zip

编译:

unzip httpd-2.4.1.zip

cd httpd-2.4.1

./configure --prefix=/usr/local/apache --enable-so

异常:

添加可执行权限:chmod +x *.sh

安装依赖软件包:yum -y install gcc;yum -y install gcc+ gcc-c++

(1)解决apr not found问题

tar -zxf apr-1.4.5.tar.gz

cd apr-1.4.5

./configure --prefix=/usr/local/apr

make && make install

(2)解决APR-util not found问题

tar -zxf apr-util-1.3.12.tar.gz

cd apr-util-1.3.12

./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/bin/apr-1-config

make && make install

(3)解决pcre问题

unzip pcre-8.10.zip

cd pcre-8.10

/configure --prefix=/usr/local/pcre

make && make install

再次编译Apache时加上:

--with-apr=/usr/local/apr

--with-apr-util=/usr/local/apr-util

--with-pcre=/usr/local/pcre

即:

./configure --prefix=/usr/local/apache --enable-so --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre

最后安装:make && make install

(4)遇到

usr/bin/ld: .libs/pcrecpp.o: relocation R_X86_64_32S against `.bss'can not be used when making a shared object; recompile with -fPIC

.libs/pcrecpp.o:could not read symbols: Bad value

collect2: ld returned 1 exit status

make[1]: *** [] 错误1

make[1]: Leaving directory `/usr/app/pcre-8.00'

make: *** [all] 错误2

解决办法:./configure --disable-shared --with-pic

再次安装:make && make install

2 启动

cd /usr/local/apache/bin

./apachectl start

异常:

(1)httpd: Could not reliably determine the server's fully qualified domain name

进入安装目:cd /usr/local/apache/conf,编辑httpd.conf文件,搜索“#ServerName”,添加ServerName localhost:80,再重新启动即可:/usr/local/apache/bin/apachectl restart;

(2)Address already in use: AH00072: make_sock: could not bind to address 0.0.0.0:80 netstat -lnp | grep 80,发现已经有进程占用80端口,kill掉,再启动Apache;

3 验证

在IE中打开localhost IP。

此刻显示的网页是对应Apache安装目录/usr/local/apache/htdocs下的index.html页面,此页面可以自定义编辑;

4 为Apache添加service

以apachectl脚本为模板生成Apache服务控制脚本:

grep -v "#" /usr/local/apache/bin/apachectl > /etc/init.d/apache

编辑Apache服务控制脚本/etc/init.d/apache:vi /etc/init.d/apache

在文件最前面插入下面的行,使其支持chkconfig命令:

#!/bin/sh

# chkconfig: 2345 85 15

# description: Apache is a World Wide Web server.

保存后退出vi编辑器,执行下面的命令增加Apache服务控制脚本执行权限:chmod +x /etc/init.d/apache

执行下面的命令将Apache服务加入到系统服务:

chkconfig --add apache

执行下面的命令检查Apache服务是否已经生效:

chkconfig --list apache

命令输出类似下面的结果:

apache 0:off 1:off 2:on 3:on 4:on 5:on 6:off

相关文档
最新文档