源码编译安装Apache

编译安装Apache

系统环境:centos 7.2

前提:

提供开发工具及开发环境

  • 开发工具:make, gcc等

  • 开发环境:开发库,头文件

  • glibc:标准库

方式:

通过“包组”提供开发组件

centos 6
[root@centos6 ~]# yum groupinstall "Development Tools"
[root@centos6 ~]# yum groupinstall "Development tools"

centos 7 
[root@centos6 ~]# yum groupinstall "Development Tools"



1、首先在方法网站http://www.apache.org/下载源码包

下载路径:http://apache.fayea.com/httpd/httpd-2.2.31.tar.gz

2、我们将下载好的文件放置在/root目录下

3、我们可以看到源码包的格式为.tar.gz 所有这里我们要将源码包进行解压缩和拆包

[root@centos7 ~]# tar xvzf httpd-2.2.31.tar.gz

4、执行完上述操作后,在当前目录即(/root)目录下,我们可以看到httpd-2.2.31目录,进入该目录

[root@centos7 ~]# cd httpd-2.2.31/

5、在该目录下,有众多的文件,我们首先关注的是 README 文件和 INSTALL 文件

README 文件主要简单的介绍了

[root@centos7 httpd-2.2.31]# less README

what is it? 
The latest version  
documentation   
installation    
licensing
Cryptographic Software Notice
Contacts
Acknowledgments

通过以上的说明可以使我们对Apache有一个简单的了解



INSTALL 文件主要说明了安装的方法

[root@centos7 httpd-2.2.31]# less INSTALL

$ ./configure --prefix=PREFIX
$ make
$ make install
$ PREFIX/bin/apachectl start

6、通过查看以上文件,下面我们可以进行Apache的编译安装

首先我们来介绍下configure脚本的参数说明

[root@centos7 httpd-2.2.31]# ./configure --help


Installation directories:指定默认的安装位置
  --prefix=PREFIX         install architecture-independent files in PREFIX
                          [/usr/local/apache2]


Fine tuning of the installation directories:默认文件安装位置
  --bindir=DIR            user executables [EPREFIX/bin]
  --sbindir=DIR           system admin executables [EPREFIX/sbin]
  --sysconfdir=DIR        read-only single-machine data [PREFIX/etc]
  ......
  ......


System types:交叉编译选项
  --build=BUILD     configure for building on BUILD [guessed]
  --host=HOST       cross-compile to build programs to run on HOST [BUILD]
  --target=TARGET   configure for building compilers for TARGET [HOST]


Optional Features:可选特性
  --disable-option-checking  ignore unrecognized --enable/--with options
  --disable-FEATURE       do not include FEATURE (same as --enable-FEATURE=no)
  --enable-FEATURE[=ARG]  include FEATURE [ARG=yes]
  --enable-v4-mapped      Allow IPv6 sockets to handle IPv4 connections
  ......
  ......


Optional Packages:可选包
  --with-PACKAGE[=ARG]    use PACKAGE [ARG=yes]
  --without-PACKAGE       do not use PACKAGE (same as --with-PACKAGE=no)
  --with-included-apr     Use bundled copies of APR/APR-Util

6(1)这里我们指定几个简单的选项即可:

[root@centos7 httpd-2.2.31]# ./configure --prefix=/usr/local/http2 --sysconfdir=/etc/http2

//该步骤执行完毕后,会结合 Makefile.in 文件,在当前目录下生成 Makefile 文件
//出现error等信息,说明配置失败

6(2)执行make和make install命令(上一步执行成功后) 注意:要始终处于当前目录下,不要离开该目录

[root@centos7 httpd-2.2.31]# make
[root@centos7 httpd-2.2.31]# make install

7、启动

[root@centos7 httpd-2.2.31]# cd /usr/local/http2/bin
[root@centos7 bin]# ./apachectl start
[root@centos7 bin]# netstat -tapn | grep "80"
tcp6       0      0 :::80                   :::*                    LISTEN      14611/http

8、测试

centos 6.8系统下测试

[root@centos6 ~]# links 10.1.249.146
//10.1.249.146 为以上编译安装Apache软件的centos 7系统 的IP

源码编译安装Apache

在Windows系统下测试

任意一款浏览器下输入:http://10.1.249.146/

源码编译安装Apache

注意:如果启动成功但是却始终访问不了,则可能的原因是centos 7 的防火墙没有关闭,所以建议关闭防火墙后在做测试

[root@centos7 ~]# iptables -F



9、最后的配置

我们知道一个程序主要由4类文件组成

  • 二进制文件

  • 配置文件

  • 库文件

  • 帮助文档

    [root@centos7 ~]# cd /usr/local/http2/
    [root@centos7 http2]# ls
    bin  build  cgi-bin  error  htdocs  icons  include  lib  logs  man  manual  modules

以上4类文件应该放置在系统特定的目录下 或者通过修改系统相关的配置文件

(1)二进制文件 bin目录 添加其路径到PATH环境变量即可

 [root@centos7 http2]# vim /etc/profile.d/http.sh
 export PATH=/usr/local/http2/bin:$PATH

[root@centos7 http2]# echo $PATH
/usr/local/http2/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin

(2)配置文件我们在编译安装时已经通过 –sysconfdir=/etc/http2 选项指定了

(3)库文件 lib目录

[root@sixijie http2]# vim /etc/ld.so.conf.d/http2.conf
/usr/local/http2/lib

让系统重新生成库文件路径缓存

[root@sixijie apache2]# ldconfig -v

缓存文件:/etc/ld.so.cache

(4)帮助文档 man

[root@centos7 lib]# vim /etc/man_db.conf (centos 7)
添加一行内容:MANDATORY_MANPATH           /usr/local/http2/man

(5)对于 include 头文件 采用软链接的方式(/usr/include为系统头文件位置)

[root@centos7 include]# ln -s /usr/local/http2/include/ /usr/include/http
[root@centos7 include]# ll -d /usr/include/http
lrwxrwxrwx. 1 root root 25 Aug 23 20:46 /usr/include/http -> /usr/local/http2/include/
[root@centos7 include]# ll /usr/include/http/

至此安装配置完成

原创文章,作者:sixijie,如若转载,请注明出处:http://www.178linux.com/39877

(0)
sixijiesixijie
上一篇 2016-08-24 21:21
下一篇 2016-08-24 21:21

相关推荐

  • N24_星空学习宣言

    学习是一种投资,既然投资了就不能亏损,努力学习,做一个学习界的巴菲特!

    Linux干货 2016-10-24
  • 系统管理之作业管理与计划任务

    作业管理: Linux的作业控制(job )     前台作业:通过终端启动,且启动后一直占据终端;     后台作业:可通过终端启动,但启动后即转入后台运行(释放终端) 如何让作业运行于后台?     (1) 运行中的…

    Linux干货 2016-09-13
  • 马哥linux课堂笔记

    0805课堂笔记 基本权限 读,写,执行   对于文件的读权限,能否查看文件内容.(文件内容需不需要看,如果是文本就需要看,如果是二进制就不需要看) 对于文件的写权限,能否修改文件内容,不能修改文件名,不能删除文件.(如果需要修改文件内容和文件名,必须在其父目录增加写权限和执行权限) 对于文件的执行权限,能否运行他.   对于目录的读权限…

    Linux干货 2016-08-15
  • CentOS Linux解决Device eth0 does not seem to be present

    CentOS Linux解决Device eth0 does not seem to be present 今天早上打开xshell链接虚拟机,突然链接不上。然后进入虚拟机执行 ifconfig 或者 ip addr list 命令发现eth0 不见。然后执行重启网卡命令发现  解决办法:   首先,打开/etc/udev/rules.d/70-p…

    Linux干货 2016-08-02
  • 实战自制Linux操作系统

    实战自制Linux操作系统 自制linux系统 步骤概述: 1、新建一个硬盘2、在该新硬盘上新建两个分区,一个当boot分区,一个当/分区3、格式化并且挂载两个分区4、安装grub至目标磁盘5、为grub提供配置文件6、复制内核文件和initrd文件7、创建目标主机根文件系统8、移植bash命令和其库文件到根文件系统9、装载模块,实现网络功能10、启动测试 …

    Linux干货 2016-09-19
  • 文件编辑之神器Sed

    pattern space   //  文本中每行内容都会进入到pattern space中, 如果匹配到了,就会进入到右分支, 如果没有匹配到,则进入左分支。 hold space  //  就是已经被模式匹配到, 并且编辑后保存的内容就是hold space 中. 默认情况下,当没有被匹配之后,没有匹配到…

    Linux干货 2016-08-15