zsyzhou 发表于 2018-11-23 09:06:32

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

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

  
  YUM安装Apache

  1、查看系统是否安装Apache:
# rpm -qa|grep httpd
httpd-2.2.15-15.el6_2.1.i686
httpd-tools-2.2.15-15.el6_2.1.i686
#  系统默认安装了Apache,版本是2.2.15,发布号为15,el6表示在rhel6系列版本中发布,i686指32位PC架构
  2、安装Apache:
# 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!
# rpm -qa|grep httpd
#  先卸载掉已经安装的
# 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!
# rpm -qa|grep httpd
httpd-2.2.15-29.el6.centos.i686
httpd-tools-2.2.15-29.el6.centos.i686
#  3、启动Apache服务:

  
# chkconfig --level 35 httpd on
# /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
                                                         [确定]
#  备注:Apache启动之后会提示错误:
      正在启动 httpd:httpd: Could not reliably determine the
server's fully qualif domain name, using ::1 for ServerName      

   解决办法:
# vi /etc/httpd/conf/httpd.conf
276 #ServerName  4、查看Apache占用的端口:

# netstat -antp |grep httpd
tcp      0      0 :::80                     :::*                        LISTEN      4814/httpd   
#  Apache使用的是80端口,Apache中默认设置了一个站点,此时直接在客户端IE里输入http://ServerIP就可以访问默认站点:http://10.15.72.38
  Tips:如果无法访问确认防火墙和SeLinux状态
  源码安装Apache
  在生产环境中,大都是采用源码编译方式安装Apache,这样可灵活定制各种功能、及时获取软件的最新版本以及便于今后在不同的系统之间移植。
  
  
# cd /usr/local/src/ && wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.7.tar.gz
# tar zxvf httpd-2.4.7.tar.gz
# cd httpd-2.4.7
# mkdir -p /usr/local/apache
# ./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.
#  
  配置报错configure: error: APR not found.Please readthe documentation.未发现APR,这个是Apache关联软件,安装和apache版本相符版本,版本过早后面也会提示类似:configure: error: APR version x.x.x or later is required的错误
  
# wget http://archive.apache.org/dist/apr/apr-1.5.0.tar.gz -P /usr/local/src/
# cd ..
# tar zxvf apr-1.5.0.tar.gz
# cd apr-1.5.0
# mkdir -p /usr/local/apr
# ./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
#  又出现了错误configure: error: no acceptable C compiler found in$PATH,从字面意思大致意思是没有发现可接受的C编辑器,因此需要安装下gcc套件
  
# yum install gcc -y  再次配置、编译、安装

  
# ./configure --prefix=/usr/local/apr/
# make
# make install  apr安装好了再来安装apache

  
# cd 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.
#  再次出错configure: error: APR-util not found.Please readthe documentation.没有找到APR-util,下载APR-util
  
  
# wget http://archive.apache.org/dist/apr/apr-util-1.5.3.tar.gz -P /usr/local/src/
# cd ..
# tar zxvf apr-util-1.5.3.tar.gz
# cd apr-util-1.5.3
# mkdir -p /usr/local/apr-util
# ./configure --prefix=/usr/local/apr
apr/      apr-util/
# ./configure --prefix=/usr/local/apr-util/ --with-apr=/usr/local/apr/bin/apr-1-config
# make && make install  再次回到安装apache

# cd ../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.
#  已经安装好了APR-util还是提示没安装,我们需要在配置是指定他位置
# ./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/
#  编译安装就是这么坑,你需要解决一系列的依赖关系,再次提示错误configure: error: pcre-config forlibpcre not found. PCRE is required and available from http://pcre.org/,同样我们需要先安装这个pcre
# wget http://jaist.dl.sourceforge.net/project/pcre/pcre/8.34/pcre-8.34.zip -P /usr/local/src/
# cd ..
# unzip -o pcre-8.34.zip
# cd pcre-8.34
# mkdir /usr/local/pcre
# ./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.
#  configure: error: You need a C++ compiler forC++ support.需要安装C++,前面安装gcc的时候可以一起安装了,免得这步又的安装
  
  
# yum install gcc-c++ -y  安装好再来安装pcre

  
# ./configure --prefix=/usr/local/pcre/
# make && make install  最后再回到安装Apache
  
# ./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
# make && make install
mkdir /usr/local/apache/man/man8
mkdir /usr/local/apache/manual
make: Leaving directory `/usr/local/src/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 是卸载,



页: [1]
查看完整版本: Web服务基础一之Apache源码和YUM安装