CentOS7下编译安装Apache

在Linux中通过编译源代码进行安装软件,需要GCC(GNU Compiler Collection,GNU编译器套件)的支持。
通过yum安装GCC

[root@localhost ~]# yum install gcc

C程序源码编译安装三个步骤:
第一步:./configure
  (1)通过选项传递参数,指定启用特性、安装路径等;执行时会参考用户的指定以及Makefile.in文件生成makefile;
   –help:获取其支持使用的选项
   选项分类:
    安装路径设定:
     –prefix=/PATH/TO/SOMEWHERE:指定默认安装位置;默认为/usr/local/
     –sysconfdir=/PATH/TO/SOMEWHERE:指定配置文件安装位置

    System types:交叉编译时,指定目标系统类型

    Optional Features: 可选特性
     –disable-FEATURE
     –enable-FEATURE[=ARG]

    Optional Packages: 可选包
     –with-PACKAGE[=ARG]
     –without-PACKAGE       
  (2)检查依赖到的外部环境
 第二步:make
  根据makefile文件,构建应用程序
 第三步:make install

在Apache官网下载源码包进行编译安装,下载地址:http://httpd.apache.org/download.cgi

[root@localhost ~]# wget http://mirrors.tuna.tsinghua.edu.cn/apache//httpd/httpd-2.4.23.tar.bz2
[root@localhost ~]# tar xf httpd-2.4.23.tar.bz2
[root@localhost ~]# cd httpd-2.4.23
[root@localhost httpd-2.4.23]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/usr/local/conf/apache2.conf
configure: error: APR not found.  Please read the documentation.

Apache在安装时需要依赖一些环境,这里报错提示需要安装APR(Apache Portable Runtime),下载地址:http://apr.apache.org/download.cgi

[root@localhost ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-1.5.2.tar.bz2
[root@localhost ~]# tar xf apr-1.5.2.tar.bz2
[root@localhost ~]# cd apr-1.5.2
[root@localhost apr-1.5.2]# ./configure --prefix=/usr/local/apr
[root@localhost apr-1.5.2]# make
[root@localhost apr-1.5.2]# make install
[root@localhost apr-1.5.2]# cd ../httpd-2.4.23/
[root@localhost httpd-2.4.23]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/usr/local/conf/apache2.conf
configure: error: APR not found.  Please read the documentation.

依旧报上面错误,这是因为编译安装自定义了APR的安装目录,所以需要通过–with-apr手动指定APR安装目录

[root@localhost httpd-2.4.23]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/usr/local/conf/apache2.conf --with-apr=/usr/local/apr
configure: error: APR-util not found.  Please read the documentation.

这次报错提示缺少APR-util环境,下载地址:http://apr.apache.org/download.cgi

[root@localhost ~]# wget http://mirror.bit.edu.cn/apache//apr/apr-util-1.5.4.tar.bz2
[root@localhost ~]# tar xf apr-util-1.5.4.tar.bz2
[root@localhost ~]# cd apr-util-1.5.4
[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util
configure: error: APR could not be located. Please use the --with-apr option.

报错提示编译APR-util需要指定APR路径

[root@localhost apr-util-1.5.4]# ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr
[root@localhost apr-util-1.5.4]# make
[root@localhost apr-util-1.5.4]# make install

有了以上经验,再次编译Apache时指定APR-util路径

[root@localhost httpd-2.4.23]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/usr/local/conf/apache2.conf --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util
configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

此处报错提示缺少PCRE环境,下载地址:https://sourceforge.net/projects/pcre/files/pcre
注意:此处应安装PCRE;如果安装PCRE2会报如下错误:

configure: error: Did not find pcre-config script at /usr/local/pcre.

[root@localhost ~]# wget https://sourceforge.net/projects/pcre/files/pcre/8.39/pcre-8.39.tar.bz2
[root@localhost ~]# tar xf pcre-8.39.tar.bz2
[root@localhost ~]# cd pcre-8.39
[root@localhost pcre-8.39]# ./configure --prefix=/usr/local/pcre
configure: error: You need a C++ compiler for C++ support.

此处报错提示需要C++编译器,通过yum安装gcc-c++

[root@localhost pcre-8.39]# yum install gcc-c++
[root@localhost pcre-8.39]# ./configure --prefix=/usr/local/pcre
[root@localhost pcre-8.39]# make
[root@localhost pcre-8.39]# make install

再次编译Apache,指定PCRE路径

[root@localhost httpd-2.4.23]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/usr/local/conf/apache2.conf --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre
[root@localhost httpd-2.4.23]# make
[root@localhost httpd-2.4.23]# make install

至此,Apache编译安装完成了,接下来进行安装后的配置:
(1)导出二进制程序目录至PATH环境变量中:
  编辑文件/etc/profile.d/apache.sh
   export PATH=$PATH:/usr/local/apache2/bin
(2)导出头文件:
  基于符号链接的方式实现:
   ln -sv /usr/local/apache2/include/ /usr/include/apache
(3)导出库文件路径:
  编辑文件/etc/ld.so.conf.d/NAME.conf,添加新的库文件所在目录至此文件中
   让系统重新生成缓存:ldconfig [-v]
(4)导出帮助手册:
  编辑/etc/man_db.conf文件,添加一个MANPATH(CentOS7下自动识别man手册)

启动Apache服务命令:apachectl start

使用ss -tnl命令查看系统是否监听于80端口,使用iptables -F命令临时清除防火墙规则,最后使用浏览器访问服务器ip,若出现

It works!

则表示Apache服务启动成功,安装到此结束。

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

(0)
萝卜萝卜
上一篇 2016-09-05 08:52
下一篇 2016-09-05 08:52

相关推荐

  • linux基础命令: tr

    基础命令:  tr   tr命令 功能:删除和转换字符 语法:tr  [OPTION]…. SET1  [SET2] 参数: -d : 删除所有属于第一字符集的字符(删除某些特殊字符) -s : 把连续重复的字符以单独一个字符表示(删除空行很有用) 举例: 1.把小写字母转换为大写字母; cat &nbsp…

    Linux干货 2016-08-03
  • 马哥教育网络班22期+第十二周课程练习

    1、请描述一次完整的http请求处理过程。    (1) 客户端与服务端通过TCP三次握手建立或处理连接:接收请求或拒绝请求    (2) 接收请求:接收来自于网络上的主机请求报文中对某特定资源的一次请求的过程    (3) 处理请求:对请求报文进行解析,获取客户端请求…

    Linux干货 2016-12-29
  • awk详解

    —————————— 课外练习 只处理用户ID为奇数的行,并打印用户名和ID号 [root@localhost ~]# awk -F: '{if($3%2!=0) {print&n…

    Linux干货 2016-09-25
  • Linux Sysadmin–part1

    一、创建一个10G分区,并格式为ext4文件系统; 1、要求其block大小为2048,预留空间百分比为2,卷标为MYDATA,默认挂载属性包含acl; 2、挂载至/data/mydata目录,要求挂载时禁止程序自动运行,且不更新文件的访问时间戳; ###创建10G分区 ~]# fdisk /dev/sdb Command (m for help): n P…

    2017-09-04
  • Linux man中文帮助安装

    虽然在CentOS操作系统中具有多语言包,但其man手册是英文的,对于新手来说能够使用中文man手册将加快学习速度

    CentOS系统安装中文man手册

    Linux干货 2017-11-26
  • linux 磁盘管理

    磁盘管理 Linux思想一切皆文件: open(),read(),write(),close() I/O 设备地址 设备类型: 块设备:block,存取单位“块”,磁盘 (随机访问) 字符设备:char,存取单位“字符”,键盘 (逻辑访问) 设备文件:关联至一个设备驱动程序,进而能够跟与之对应硬件设备进行通讯。 设备编号: ll /dev/sda* root…

    Linux干货 2016-08-29