设为首页 收藏本站
查看: 908|回复: 0

[经验分享] 源码编译安装Apache

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2016-8-24 10:54:18 | 显示全部楼层 |阅读模式

    编译安装Apache

系统环境:centos 7.2

前提:

提供开发工具及开发环境

    开发工具:make, gcc等

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

    glibc:标准库

方式:

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

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

centos 7
[iyunv@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 所有这里我们要将源码包进行解压缩和拆包

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

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

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

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

README 文件主要简单的介绍了

[iyunv@centos7 httpd-2.2.31]# less README

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

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



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

[iyunv@centos7 httpd-2.2.31]# less INSTALL

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

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

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

[iyunv@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)这里我们指定几个简单的选项即可:

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

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

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

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

7、启动

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

8、测试

centos 6.8系统下测试

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


ZOq3YW3.jpg
在Windows系统下测试

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

YOlk46U.jpg


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

[iyunv@centos7 ~]# iptables -F

9、最后的配置

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

    二进制文件

    配置文件

    库文件

    帮助文档

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

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

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

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

[iyunv@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目录

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

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

[iyunv@sixijie apache2]# ldconfig -v

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

(4)帮助文档 man

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

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

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

至此安装配置完成

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-262320-1-1.html 上篇帖子: 源码安装http2.2.29 下篇帖子: 源码编译安装httpd及其常见错误
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表