Web服务基础一之Apache源码和YUM安装

简介:

Apache HTTP Server(简称Apache)是Apache软件基金会的一个开放源代码的网页服务器,可以在大多数电脑操作系统中运行,由于其跨平台(可以用于UNIX/Linux系统,甚至还可以用于Windows系统)、安全性并且可通过简单的API扩充,PerlPython解释器编译到服务器中被广泛使用,是最流行的Web服务器端软件之一,但是默认只有256个并发连接,运行速度偏慢,效率较低。官方网站http://httpd.apache.org,Apache有两个版本分支:1.x和2.x,目前使用的都是2.x版本,最新版本为2.4.7,在系统中的进程名为httpd。


YUM安装Apache

1、查看系统是否安装Apache:

1
2
3
4
[root@justin ~] # rpm -qa|grep httpd
httpd-2.2.15-15.el6_2.1.i686
httpd-tools-2.2.15-15.el6_2.1.i686
[root@justin ~] #

系统默认安装了Apache,版本是2.2.15,发布号为15,el6表示在rhel6系列版本中发布,i686指32位PC架构

2、安装Apache:

1
2
3
4
5
6
7
8
9
[root@justin ~] # yum remove httpd* -y
Removed:
   httpd.i686 0:2.2.15-15.el6_2.1                                                                       
   httpd-tools.i686 0:2.2.15-15.el6_2.1
Dependency Removed:
   gnome-user-share.i686 0:2.28.2-3.el6                                                                 
Complete!
[root@justin ~] # rpm -qa|grep httpd
[root@justin ~] #

先卸载掉已经安装的

1
2
3
4
5
6
7
8
9
10
[root@justin src] # yum install httpd -y
Installed:
   httpd.i686 0:2.2.15-29.el6.centos                                                                    
Dependency Installed:
   httpd-tools.i686 0:2.2.15-29.el6.centos                                                              
Complete!
[root@justin src] # rpm -qa|grep httpd
httpd-2.2.15-29.el6.centos.i686
httpd-tools-2.2.15-29.el6.centos.i686
[root@justin src] #

3、启动Apache服务:

1
2
3
4
5
6
[root@justin ~] # chkconfig --level 35 httpd on 
[root@justin ~] # /etc/init.d/httpd start
正在启动 httpd:httpd: apr_sockaddr_info_get() failed  for  justin
httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1  for  ServerName
                                                            [确定]
[root@justin ~] #

备注:Apache启动之后会提示错误:
      正在启动 httpd:httpd: Could not reliably determine the server's fully qualif domain name, using ::1 for ServerName      
     解决办法:

1
2
[root@localhost libexec] # vi /etc/httpd/conf/httpd.conf 
276  #ServerName

4、查看Apache占用的端口:

1
2
3
[root@justin ~] # netstat -antp |grep httpd
tcp        0      0 :::80                       :::*                        LISTEN      4814 /httpd   
[root@justin ~] #

Apache使用的是80端口,Apache中默认设置了一个站点,此时直接在客户端IE里输入http://ServerIP就可以访问默认站点:http://10.15.72.38wKioL1LWMqCTl0yTAASL2zHPSF8174.jpg

Tips:如果无法访问确认防火墙和SeLinux状态


源码安装Apache

在生产环境中,大都是采用源码编译方式安装Apache,这样可灵活定制各种功能、及时获取软件的最新版本以及便于今后在不同的系统之间移植。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@justin src] # cd /usr/local/src/ && wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.7.tar.gz
[root@justin httpd-2.4.7] # tar zxvf httpd-2.4.7.tar.gz
[root@justin httpd-2.4.7] # cd httpd-2.4.7
[root@justin httpd-2.4.7] # mkdir -p /usr/local/apache
[root@justin httpd-2.4.7] # ./configure --prefix=/usr/local/apache/
checking  for  chosen layout... Apache
checking  for  working  mkdir  -p...  yes
checking  for  grep  that handles long lines and -e...  /bin/grep
checking  for  egrep ...  /bin/grep  -E
checking build system  type ... i686-pc-linux-gnu
checking host system  type ... i686-pc-linux-gnu
checking target system  type ... i686-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking  for  APR... no
configure: error: APR not found.  Please  read  the documentation.
[root@justin httpd-2.4.7] #

配置报错configure: error: APR not found.  Please readthe documentation.未发现APR,这个是Apache关联软件,安装和apache版本相符版本,版本过早后面也会提示类似:configure: error: APR version x.x.x or later is required的错误

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
[root@justin httpd-2.4.7] # wget http://archive.apache.org/dist/apr/apr-1.5.0.tar.gz -P /usr/local/src/
[root@justin httpd-2.4.7] # cd ..
[root@justin src] # tar zxvf apr-1.5.0.tar.gz
[root@justin src] # cd apr-1.5.0
[root@justin apr-1.5.0] # mkdir -p /usr/local/apr
[root@justin apr-1.5.0] # ./configure --prefix=/usr/local/apr/
checking build system  type ... i686-pc-linux-gnu
checking host system  type ... i686-pc-linux-gnu
checking target system  type ... i686-pc-linux-gnu
Configuring APR library
Platform: i686-pc-linux-gnu
checking  for  working  mkdir  -p...  yes
APR Version: 1.5.0
checking  for  chosen layout... apr
checking  for  gcc... no
checking  for  cc... no
checking  for  cl.exe... no
configure: error:  in  ` /usr/local/src/apr-1 .5.0':
configure: error: no acceptable C compiler found  in  $PATH
See `config.log'  for  more  details
[root@justin apr-1.5.0] #

又出现了错误configure: error: no acceptable C compiler found in$PATH,从字面意思大致意思是没有发现可接受的C编辑器,因此需要安装下gcc套件

1
[root@justin apr-1.5.0] # yum install gcc -y

再次配置、编译、安装

1
2
3
[root@justin apr-1.5.0] # ./configure --prefix=/usr/local/apr/
[root@justin apr-1.5.0] # make
[root@justin apr-1.5.0] # make install

apr安装好了再来安装apache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@justin src] # cd httpd-2.4.7
[root@justin httpd-2.4.7] # ./configure --prefix=/usr/local/apache/
checking  for  chosen layout... Apache
checking  for  working  mkdir  -p...  yes
checking  for  grep  that handles long lines and -e...  /bin/grep
checking  for  egrep ...  /bin/grep  -E
checking build system  type ... i686-pc-linux-gnu
checking host system  type ... i686-pc-linux-gnu
checking target system  type ... i686-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking  for  APR...  yes
   setting CC to  "gcc"
   setting CPP to  "gcc -E"
   setting CFLAGS to  " -g -O2 -pthread"
   setting CPPFLAGS to  " -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE"
   setting LDFLAGS to  " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking  for  APR-util... no
configure: error: APR-util not found.  Please  read  the documentation.
[root@justin httpd-2.4.7] #

再次出错configure: error: APR-util not found.  Please readthe documentation.没有找到APR-util,下载APR-util

1
2
3
4
5
6
7
8
9
[root@justin httpd-2.4.7] # wget http://archive.apache.org/dist/apr/apr-util-1.5.3.tar.gz -P /usr/local/src/
[root@justin httpd-2.4.7] # cd ..
[root@justin src] # tar zxvf apr-util-1.5.3.tar.gz
[root@justin src] # cd apr-util-1.5.3
[root@justin apr-util-1.5.3] # mkdir -p /usr/local/apr-util
[root@justin apr-util-1.5.3] # ./configure --prefix=/usr/local/apr
apr/      apr-util/
[root@justin apr-util-1.5.3] # ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/bin/apr-1-config
[root@justin apr-util-1.5.3] # make && make install

再次回到安装apache

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
[root@justin apr-util-1.5.3] # cd ../httpd-2.4.7
[root@justin httpd-2.4.7] # ./configure --prefix=/usr/local/apache/
checking  for  chosen layout... Apache
checking  for  working  mkdir  -p...  yes
checking  for  grep  that handles long lines and -e...  /bin/grep
checking  for  egrep ...  /bin/grep  -E
checking build system  type ... i686-pc-linux-gnu
checking host system  type ... i686-pc-linux-gnu
checking target system  type ... i686-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking  for  APR...  yes
   setting CC to  "gcc"
   setting CPP to  "gcc -E"
   setting CFLAGS to  " -g -O2 -pthread"
   setting CPPFLAGS to  " -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE"
   setting LDFLAGS to  " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking  for  APR-util... no
configure: error: APR-util not found.  Please  read  the documentation.
[root@justin httpd-2.4.7] #

已经安装好了APR-util还是提示没安装,我们需要在配置是指定他位置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
[root@justin httpd-2.4.7] # ./configure --prefix=/usr/local/apache/ --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/
checking  for  chosen layout... Apache
checking  for  working  mkdir  -p...  yes
checking  for  grep  that handles long lines and -e...  /bin/grep
checking  for  egrep ...  /bin/grep  -E
checking build system  type ... i686-pc-linux-gnu
checking host system  type ... i686-pc-linux-gnu
checking target system  type ... i686-pc-linux-gnu
configure:
configure: Configuring Apache Portable Runtime library...
configure:
checking  for  APR...  yes
   setting CC to  "gcc"
   setting CPP to  "gcc -E"
   setting CFLAGS to  " -g -O2 -pthread"
   setting CPPFLAGS to  " -DLINUX -D_REENTRANT -D_GNU_SOURCE -D_LARGEFILE64_SOURCE"
   setting LDFLAGS to  " "
configure:
configure: Configuring Apache Portable Runtime Utility library...
configure:
checking  for  APR-util...  yes
checking  for  gcc... gcc
checking whether the C compiler works...  yes
checking  for  C compiler default output  file  name... a.out
checking  for  suffix of executables...
checking whether we are cross compiling... no
checking  for  suffix of object files... o
checking whether we are using the GNU C compiler...  yes
checking whether gcc accepts -g...  yes
checking  for  gcc option to accept ISO C89... none needed
checking how to run the C preprocessor... gcc -E
checking  for  gcc option to accept ISO C99... -std=gnu99
checking  for  pcre-config...  false
configure: error: pcre-config  for  libpcre not found. PCRE is required and available from http: //pcre .org/
[root@justin httpd-2.4.7] #

编译安装就是这么坑,你需要解决一系列的依赖关系,再次提示错误configure: error: pcre-config forlibpcre not found. PCRE is required and available from http://pcre.org/,同样我们需要先安装这个pcre

1
2
3
4
5
6
7
8
9
10
11
12
[root@justin src] # wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.34/pcre-8.34.zip -P /usr/local/src/
[root@justin httpd-2.4.7] # cd ..
[root@justin src] # unzip -o pcre-8.34.zip
[root@justin src] # cd pcre-8.34
[root@justin pcre-8.34] # mkdir /usr/local/pcre
[root@justin pcre-8.34] # ./configure --prefix=/usr/local/pcre/
checking  for  dirent.h...  yes
checking windows.h usability... no
checking windows.h presence... no
checking  for  windows.h... no
configure: error: You need a C++ compiler  for  C++ support.
[root@justin pcre-8.34] #

configure: error: You need a C++ compiler forC++ support.需要安装C++,前面安装gcc的时候可以一起安装了,免得这步又的安装

1
[root@justin pcre-8.34] # yum install gcc-c++ -y

安装好再来安装pcre

1
2
[root@justin pcre-8.34] # ./configure --prefix=/usr/local/pcre/
[root@justin pcre-8.34] # make && make install

最后再回到安装Apache

1
2
3
4
5
6
7
8
9
10
[root@justin httpd-2.4.7] # ./configure --prefix=/usr/local/apache/ --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util/ --with-pcre=/usr/local/pcre/
config.status: creating build /pkg/pkginfo
config.status: creating build /config_vars .sh
config.status: creating include /ap_config_auto .h
config.status: executing default commands
[root@justin httpd-2.4.7] # make && make install
mkdir  /usr/local/apache/man/man8
mkdir  /usr/local/apache/manual
make [1]: Leaving directory ` /usr/local/src/httpd-2 .4.7'
[root@justin httpd-2.4.7] #

总算没有再报错,源码编译安装虽然灵活但是安装很复杂,需要解决一系列依赖关系问题,这里只是纯粹的安装Apache服务。仅能提供最基本的静态网站数据而已,想要实现动态网站的话,最好还是要PHP与MySQL的支持,


1、configure 这一步一般用来生成 Makefile,为下一步的编译做准备

2、make 这一步就是编译,大多数的源代码包都经过这一步进行编译(当然有些perl或python编写的软件需要调用perl或python来进行编译)。 如果 在 make 过程中出现 error ,你就要记下错误代码(注意不仅仅是最后一行),make 的作用是开始进行源代码编译,以及一些功能的提供,这些功能由他的 Makefile 设置文件提供相关的功能,make 是 Linux 开发套件里面自动化编译的一个控制程序,他通过借助 Makefile 里面编写的编译规范进行自动化的调用 gcc 、ld 以及运行某些需要的程序进行编译的程序。一般情况下,他所使用的 Makefile 控制代码,由 configure 这个设置脚本根据给定的参数和系统环境生成。

3、make install 这条命令来进行安装(当然有些软件需要先运行 make check 或 make test来进行一些测试),这一步一般需要你有 root 权限(因为要向系统写入文件),make install 一般表示进行安装,make uninstall 是卸载




本文转自 justin_peng 51CTO博客,原文链接:http://blog.51cto.com/ityunwei2017/1352138,如需转载请自行联系原作者

相关文章
|
6月前
|
存储 缓存 算法
分布式锁服务深度解析:以Apache Flink的Checkpointing机制为例
【10月更文挑战第7天】在分布式系统中,多个进程或节点可能需要同时访问和操作共享资源。为了确保数据的一致性和系统的稳定性,我们需要一种机制来协调这些进程或节点的访问,避免并发冲突和竞态条件。分布式锁服务正是为此而生的一种解决方案。它通过在网络环境中实现锁机制,确保同一时间只有一个进程或节点能够访问和操作共享资源。
224 3
|
6月前
|
Linux 网络安全 Apache
CentOS 7.2配置Apache服务httpd(上)
CentOS 7.2配置Apache服务httpd(上)
467 1
|
6月前
|
存储 分布式计算 druid
大数据-155 Apache Druid 架构与原理详解 数据存储 索引服务 压缩机制
大数据-155 Apache Druid 架构与原理详解 数据存储 索引服务 压缩机制
141 3
|
6月前
|
Ubuntu 网络安全 Apache
Ubuntu下安装Apache2.4.7遇到的问题及解决办法
Ubuntu下安装Apache2.4.7遇到的问题及解决办法
105 2
|
6月前
|
Linux PHP Apache
CentOS 7.2配置Apache服务httpd(下)
CentOS 7.2配置Apache服务httpd(下)
83 1
|
5月前
|
消息中间件 Ubuntu Java
Ubuntu系统上安装Apache Kafka
Ubuntu系统上安装Apache Kafka
|
7月前
|
缓存 前端开发 Java
打造未来兼容的Web应用:Apache Wicket引领响应式设计的热潮
【9月更文挑战第4天】在软件开发领域,构建响应式Web应用至关重要。Apache Wicket作为一个强大的Java框架,支持响应式设计,确保应用在不同设备上均有出色体验。本文通过示例代码介绍使用Wicket的最佳实践,涵盖页面与组件模型、CSS媒体查询及自定义标记处理器的应用。同时,文章强调了优化加载时间、增强交互性和提升可访问性的重要性,帮助开发者打造高性能且美观的Web应用。
93 3
|
7月前
|
Java API Apache
从零到英雄的蜕变:如何用Apache Wicket打造你的第一个Web应用——不仅是教程,更是编程之旅的启航
【9月更文挑战第4天】学习Apache Wicket这一开源Java Web应用框架是一段激动人心的旅程。本文将指导你通过Maven搭建环境,并创建首个“Hello, World!”应用。从配置`pom.xml`到实现`HelloWorldApplication`类,再到`web.xml`的设置,一步步教你构建与部署简单网页。适合初学者快速上手,体验其简洁API与强大组件化设计的魅力。
184 1
|
8月前
|
Java Spring Apache
Spring Boot邂逅Apache Wicket:一次意想不到的完美邂逅,竟让Web开发变得如此简单?
【8月更文挑战第31天】Apache Wicket与Spring Boot的集成提供了近乎无缝的开发体验。Wicket以其简洁的API和强大的组件化设计著称,而Spring Boot则以开箱即用的便捷性赢得开发者青睐。本文将指导你如何在Spring Boot项目中引入Wicket,通过简单的步骤完成集成配置。首先,创建一个新的Spring Boot项目并在`pom.xml`中添加Wicket相关依赖。
193 0
|
8月前
|
Apache 开发者 Java
Apache Wicket揭秘:如何巧妙利用模型与表单机制,实现Web应用高效开发?
【8月更文挑战第31天】本文深入探讨了Apache Wicket的模型与表单处理机制。Wicket作为一个组件化的Java Web框架,提供了多种模型实现,如CompoundPropertyModel等,充当组件与数据间的桥梁。文章通过示例介绍了模型创建及使用方法,并详细讲解了表单组件、提交处理及验证机制,帮助开发者更好地理解如何利用Wicket构建高效、易维护的Web应用程序。
104 0

推荐镜像

更多