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 的配置使用。





目录
相关文章
|
11天前
|
安全 Ubuntu Java
Linux配置使用篇
Linux配置使用篇
|
23天前
|
存储 负载均衡 索引
linux7安装elasticsearch-7.4.0集群配置
linux7安装elasticsearch-7.4.0集群配置
109 0
|
28天前
|
监控 Linux Shell
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
【Shell 命令集合 网络通讯 】Linux 配置和管理网络流量的形状 shapecfg命令 使用指南
38 0
|
28天前
|
网络协议 Shell Linux
【Shell 命令集合 网络通讯 】Linux 设置和配置PPP pppsetup命令 使用教程
【Shell 命令集合 网络通讯 】Linux 设置和配置PPP pppsetup命令 使用教程
36 0
|
28天前
|
缓存 网络协议 Linux
【Shell 命令集合 网络通讯 】Linux 配置DNS dnsconf 命令 使用教程
【Shell 命令集合 网络通讯 】Linux 配置DNS dnsconf 命令 使用教程
38 0
|
30天前
|
网络协议 Ubuntu Linux
Linux 动态/静态配置ip网卡信息
Linux 动态/静态配置ip网卡信息
36 0
|
28天前
|
域名解析 网络协议 Linux
【Shell 命令集合 网络通讯 】Linux 设置和管理网络接口配置信息 netconfig命令 使用指南
【Shell 命令集合 网络通讯 】Linux 设置和管理网络接口配置信息 netconfig命令 使用指南
49 1
|
28天前
|
存储 Shell Linux
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
【Shell 命令集合 系统管理 】Linux 修改用户的属性和配置 usermod命令 使用指南
30 1
|
10天前
|
网络协议 Linux
在Linux中,管理和配置网络接口
在Linux中管理网络接口涉及多个命令,如`ifconfig`(在新版本中被`ip`取代)、`ip`(用于网络设备配置)、`nmcli`(NetworkManager的CLI工具)、`nmtui`(文本界面配置)、`route/ip route`(处理路由表)、`netstat/ss`(显示网络状态)和`hostnamectl/systemctl`(主机名和服务管理)。这些命令帮助用户启动接口、设置IP地址、查看连接和路由信息。不同发行版可能有差异,建议参考相应文档。
19 4
|
16天前
|
Ubuntu Linux Apache
linux下apache2更换目录
linux下apache2更换目录