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
Apache服务器安装SSL证书
Apache服务器安装SSL证书
10 0
|
3月前
|
开发框架 安全 .NET
【网络安全】web源码详解及拓展
【网络安全】web源码详解及拓展
86 0
|
1月前
|
SQL 存储 数据库
基于Web技术的在线考试系统的设计与实现(论文+源码)_kaic
基于Web技术的在线考试系统的设计与实现(论文+源码)_kaic
|
1月前
|
Java 关系型数据库 MySQL
基于Web的影院信息管理系统设计与实现(论文+源码)_kaic
基于Web的影院信息管理系统设计与实现(论文+源码)_kaic
|
25天前
|
存储 缓存 负载均衡
【Apache ShenYu源码】如何实现负载均衡模块设计
整个模块为ShenYu提供了什么功能。我们可以看下上文我们提到的工厂对象。/***/核心方法很清晰,我们传入Upsteam列表,通过这个模块的负载均衡算法,负载均衡地返回其中一个对象。这也就是这个模块提供的功能。
17 1
|
27天前
|
Java API Apache
【Apache ShenYu源码】看看贡献者如何实现支持提醒通知设计
在阅读中,还发现了有个html文件忘记加了开源协议,我们提下PR修复下,又收获了一次开源贡献!!PR提交戳这。
22 1
【Apache ShenYu源码】看看贡献者如何实现支持提醒通知设计
|
1月前
|
安全 搜索推荐 前端开发
如何在本地安装Flask并将其web界面发布到公网上远程访问协同开发
如何在本地安装Flask并将其web界面发布到公网上远程访问协同开发
|
1月前
|
存储 测试技术 数据库
基于WEB的院校课程管理系统设计与实现(论文+源码)_kaic
基于WEB的院校课程管理系统设计与实现(论文+源码)_kaic
|
1月前
|
前端开发 Java 测试技术
基于Web的一站式养老院的设计与实现(论文+源码)_kaic
基于Web的一站式养老院的设计与实现(论文+源码)_kaic
|
1月前
|
Java 关系型数据库 MySQL
基于Web的停车场管理系统的设计与实现(论文+源码)_kaic
基于Web的停车场管理系统的设计与实现(论文+源码)_kaic

推荐镜像

更多