Linux 安装配置 Apache

Apache是世界使用排名第一的Web服务器软件。它可以运行在几乎所有广泛使用的计算机平台上,由于其跨平台和安全性被广泛使用,是最流行的Web服务器端软件。同时Apache音译为阿帕奇。

本文以在系统Red Hat Enterprise Linux Server release 7.1 (Maipo)上安装apache_2.4.16为例进行基本的安装配置说明。
官网地址:http://httpd.apache.org/
本文使用的apache下载地址:http://apache.fayea.com//httpd/httpd-2.4.16.tar.gz

一、开始安装

mkdir /app
cd /app
wget http://apache.fayea.com//httpd/httpd-2.4.16.tar.gz
tar -zxvf httpd-2.4.16.tar.gz
cd httpd-2.4.16/
./configure --prefix=/usr/local/apache2 --enable-so --enable-rewrite
--prefix=/usr/local/apach2 是设置编译安装到的系统目录,
--enable-s  参数是使httpd服务能够动态加载模块功能,
--enable-rewrite  是使httpd服务具有网页地址重写功能。

make
make install

如果出现错误:

checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
configure: 
configure: Configuring Apache Portable Runtime library...
configure: 
checking for APR... no
configure: error: APR not found.  Please read the documentation.
是因为缺少apache依赖包:apr、apr-util、pcre 导致。到地址 http://apr.apache.org/download.cgi  和 http://jaist.dl.sourceforge.net/project/pcre/pcre/ 下载安装。


安装apr:

tar -zxf apr-1.5.2.tar.gz  
cd apr-1.5.2
./configure --prefix=/usr/local/apr

如果出现错误:

checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
checking target system type... x86_64-unknown-linux-gnu
Configuring APR library
Platform: x86_64-unknown-linux-gnu
checking for working mkdir -p... yes
APR Version: 1.5.2
checking for chosen layout... apr
checking for gcc... gcc
checking whether the C compiler works... no
configure: error: in `/app/apr-1.5.2':
configure: error: C compiler cannot create executables
See `config.log' for more details
解决方法:

yum install -y gcc* 

yum install -y glib*

然后重新 ./configure --prefix=/usr/local/apr 后再 make && make install


安装apr-util:

cd apr-util-1.5.4

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

make && make install


安装pcre:

cd pcre-8.37/

./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


现在接着开始安装apache ……(命令:./configure --prefix=/usr/local/apache2 --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-so --enable-rewrite

成功编译完成!


二、启动和停止

启动apache

/usr/local/apache2/bin/apachectl start

停止apache

/usr/local/apache2/bin/apachectl stop

在启动apache的时候出现错误“AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message”

解决方法:这个时候编辑 /usr/local/apache2/conf/httpd.conf 配置文件,将其中 #ServerName www.example.com:80 前面的注释去掉即可,或者我们修改为 ServerName localhost:80,然后即可正常启动apache。

访问 http://localhost:80 会看到 It Works!


三、添加服务

将apache添加到系统服务,用service来控制apache的停止和启动。

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

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

2、使用vi编辑/etc/init.d/apache,在文件开头加入下面的行,使之支持chkconfig命令

#!/bin/sh
#chkconfig: 2345 85 15     
#description: Apache is a World Wide Web server.

3、执行下面的命令增加apache服务控制脚本的执行权限

chmod +x /etc/init.d/apache

4、执行下面的命令将apache加入到系统服务并打开随系统开机启动

chkconfig --add apache

chkconfig apache on

5、执行下面命令检查apache服务是否已经生效

chkconfig --list apache

命令输出如下结果:

apache         0:关 1:关 2:开 3:开 4:开 5:开 6:关

表明apache服务已经生效,在2、3、4、5运行级别随系统启动而自动启动。

以后可以使用service(在rhel7中使用systemctl)命令控制Apache的启动和停止

5、启动和停止apache服务

systemctl start apache(rhel7以下使用:service apache start)

systemctl stop apache(rhel7以下使用:service apache stop)

6、使用如下命令关闭apache服务开机自动启动

chkconfig apache off


安装好 apache 后,需要开放对外端口,可以参考配置防火墙(RHEL 7)的帖子:

http://blog.csdn.net/catoop/article/details/47861583

-------------------------------------

下篇文章:Apache服务器的图像处理模块 mod_gfx 的配置使用。





评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

catoop

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值