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





目录
相关文章
|
9月前
|
Ubuntu Linux 网络安全
Linux服务器之Ubuntu的安装与配置
Ubuntu Desktop是目前最成功、最流行的图形界面的Linux发行版;而Ubuntu Server也在服务器端市场占据了较大的份额。今天为大家详细介绍了Ubuntu Server的安装与配置,希望对你能有所帮助。关于VMware、VirtualBox等虚拟化软件的使用,朱哥还会在后续的文章中为大家详细介绍,敬请关注!
|
7月前
|
存储 Linux 开发工具
Linux环境下使用Buildroot配置软件包
使用Buildroot可以大大简化嵌入式Linux系统的开发和维护工作,但它需要对Linux系统和交叉编译有深入的理解。通过上述步骤,可以有效地配置和定制软件包,为特定的嵌入式应用构建高效、稳定的系统。
806 11
|
安全 Linux 开发工具
【Linux】vim使用与配置教程
Vim是一款功能强大的文本编辑器,广泛应用于Linux环境,是开发者和系统管理员的必备工具。本文介绍了Vim的基本操作与简单配置,涵盖命令模式、插入模式和底行模式的使用方法,以及光标定位、复制粘贴、搜索替换等常用技巧。同时,文章还提供了实用的分屏操作和代码注释方法,并分享了通过`.vimrc`文件进行个性化配置(如显示行号、语法高亮、自动缩进等)的技巧,帮助用户提升文本编辑效率。掌握这些内容,能让Vim更好地服务于日常工作与开发需求。
1045 3
|
10月前
|
Kubernetes Linux 网络安全
Rocky Linux 8.9配置Kubernetes集群详解,适用于CentOS环境
初始化成功后,记录下显示的 `kubeadm join`命令。
682 0
|
12月前
|
关系型数据库 MySQL Java
安装和配置JDK、Tomcat、MySQL环境,以及如何在Linux下更改后端端口。
遵循这些步骤,你可以顺利完成JDK、Tomcat、MySQL环境的安装和配置,并在Linux下更改后端端口。祝你顺利!
634 11
|
10月前
|
存储 安全 Linux
Linux服务器上安装配置GitLab的步骤。
按照以上步骤,一个基础的GitLab服务应该运行并可以使用。记得定期检查GitLab官方文档,因为GitLab的安装和配置步骤可能随着新版本而变化。
927 0
|
关系型数据库 MySQL Linux
查看Linux、Apache、MySQL、PHP版本的技巧
以上就是查看Linux、Apache、MySQL、PHP版本信息的方法。希望这些信息能帮助你更好地理解和使用你的LAMP技术栈。
560 17
|
Java Linux 应用服务中间件
在Rocky Linux 9上安装JDK并配置环境变量!
本教程介绍在Rocky Linux 9上安装JDK并配置环境变量的完整步骤。首先更新系统,清理旧版本JDK相关包及残留文件,确保环境干净。接着搜索并安装所需版本的JDK(如OpenJDK 17),验证安装是否成功。然后查找JDK安装路径,配置全局环境变量`JAVA_HOME`和`PATH`,最后验证环境变量设置。按照此流程操作,可顺利完成Java开发环境搭建,支持多版本切换(如JDK 8/11/17)。生产环境请谨慎操作,避免影响现有服务。
1906 21
|
11月前
|
Linux 网络安全 开发工具
在Linux下配置gitee与Github的远程仓库
注意,git push后,是输入你的账号与密码。这个步骤可以通过特殊设置省去,但是一开始还是不要太省。
543 0
|
安全 Linux 网络安全
在Linux(CentOS和AWS)上安装更新的git2的方法并配置github-ssh
经过以上这些步骤,你现在就能在GitHub上顺利往返,如同海洋中的航海者自由驰骋。欢迎你加入码农的世界,享受这编程的乐趣吧!
533 10