【CentOS基础篇】之编译安装httpd

程序包编译安装

在linux中,程序的安装分为rpm安装、yum安装和编译安装,rpm包和yum包在制作过程中已经规划好了安装的路径,相对普通用户来说,这种方式相对于便捷,但是只能用在匹配的系统版本上,定义不同的安装方式。很多软件使用源码发布,以便于应用在不同的平台上。用户在编译源码的时候,生成适用于当前操作系统的二进制程序。linux有现成的编译工具,可以批量的,自动的帮我们把成千上万的源代码按规则生成二进制。这个工具叫做make(项目管理器),针对于c语言和c++。

本文章所用系统为CentOS 7,httpd源码为httpd-2.4.27.tar.bz2

准备工作:安装开发包组

在程序的编译安装之前,先安装好开发包组,执行命令yum groupinstall "Development tools"(安装过程过长,截取部分展示)

[root@centos7 /usr/local/src/httpd-2.4.27]#yum groupinstall "Development tools"
Loaded plugins: fastestmirror, langpacks
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
base                                                                                    | 3.6 kB  00:00:00     
epel/x86_64/metalink                                                                    | 6.6 kB  00:00:00     
epel                                                                                    | 4.3 kB  00:00:00     
extras                                                                                  | 3.4 kB  00:00:00     
updates                                                                                 | 3.4 kB  00:00:00     
webtatic                                                                                | 3.6 kB  00:00:00     
(1/2): epel/x86_64/updateinfo                                                           | 806 kB  00:00:02     
(2/2): epel/x86_64/primary_db                                                           | 4.8 MB  00:00:14     
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * epel: ftp.jaist.ac.jp
 * extras: mirrors.btte.net
 * updates: mirrors.aliyun.com
 * webtatic: sp.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package autoconf.noarch 0:2.69-11.el7 will be installed
--> Processing Dependency: m4 >= 1.4.14 for package: autoconf-2.69-11.el7.noarch
---> Package automake.noarch 0:1.13.4-3.el7 will be installed
--> Processing Dependency: perl(Thread::Queue) for package: automake-1.13.4-3.el7.noarch
--> Processing Dependency: perl(TAP::Parser) for package: automake-1.13.4-3.el7.noarch
......

准备工作:安装Apache

因为安装httpd必须用到apache,在这里提前按住Apache,执行命令yum install apr-util-devel

[root@centos7 /usr/local/src/httpd-2.4.27]#yum install apr-util-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * epel: repo.ugm.ac.id
 * extras: mirrors.btte.net
 * updates: mirrors.aliyun.com
 * webtatic: sp.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package apr-util-devel.x86_64 0:1.5.2-6.el7 will be installed
--> Processing Dependency: pkgconfig(apr-1) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: openldap-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: libdb-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: expat-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Processing Dependency: apr-devel(x86-64) for package: apr-util-devel-1.5.2-6.el7.x86_64
--> Running transaction check
......

准备工作:安装pcre

pcre是通用的正则表达式引擎,在很多软件中都可以使用,是必要安装的组件之一,执行命令yum install pcre-devel

[root@centos7 /usr/local/src/httpd-2.4.27]#yum install pcre-devel
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.btte.net
 * epel: mirror.premi.st
 * extras: mirrors.btte.net
 * updates: mirrors.aliyun.com
 * webtatic: sp.repo.webtatic.com
Resolving Dependencies
--> Running transaction check
---> Package pcre-devel.x86_64 0:8.32-15.el7_2.1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved
......

下载httpd源码并上传至centos虚拟机并解压

首先下载我们所需要的httpd源码,这里推荐下载网址http://apache.fayea.com/httpd/


在这里我们需要用一个工具WinSCP,把我们已经下载的httpd-2.4.27.tar.bz2上传至CentOS 7虚拟机里。
使用XShell/CRT远程连接时,直接使用rz命令向Centos系统上传文件
第一步:配置WinSCP客户端,连接到CentOS 7

第二步:找到你下载在windows系统下的源码包,复制进CentOS 7系统里,在linux中,有一个专门放置源码包的目录 /usr/local/src/,推荐源码包统一放置在此文件夹

第三步:在CentOS 7中检查是否上传完成

[root@centos7 ~]#cd /usr/local/src/ 
[root@centos7 /usr/local/src]#ll  
total 6376  
-rw-r--r--. 1 root root 6527394 Jul 31 09:55 httpd-2.4.27.tar.bz2 

第四步:用tar命令解压已上传的httpd源码包,在这里已经可以看到解压后的httpd-2.4.27文件夹

[root@centos7 /usr/local/src]#tar xvf httpd-2.4.27.tar.bz2 
httpd-2.4.27/
httpd-2.4.27/.deps
httpd-2.4.27/.gdbinit
httpd-2.4.27/ABOUT_APACHE
httpd-2.4.27/acinclude.m4
httpd-2.4.27/ap.d
httpd-2.4.27/Apache-apr2.dsw
......
[root@centos7 /usr/local/src]#ll
total 6380
drwxr-xr-x. 11  501 games    4096 Jul  7 01:38 httpd-2.4.27
-rw-r--r--.  1 root root  6527394 Jul 31 09:55 httpd-2.4.27.tar.bz2

看说明

cat README 查看使用说明(由于文件过大,截取部分展示)

[root@centos7 /usr/local/src/httpd-2.4.27]#cat README

                          Apache HTTP Server

  What is it?
  -----------

  The Apache HTTP Server is a powerful and flexible HTTP/1.1 compliant
  web server.  Originally designed as a replacement for the NCSA HTTP
  Server, it has grown to be the most popular web server on the
  Internet.  As a project of the Apache Software Foundation, the
  developers aim to collaboratively develop and maintain a robust,
  commercial-grade, standards-based server with freely available
  source code.

  The Latest Version
  ------------------

  Details of the latest version can be found on the Apache HTTP
  server project page under http://httpd.apache.org/.

  Documentation
  -------------

  The documentation available as of the date of this release is
  included in HTML format in the docs/manual/ directory.  The most
  up-to-date documentation can be found at
  http://httpd.apache.org/docs/2.4/.
......

cat INSTALL 查看安装信息(由于文件过大,截取部分展示)

[root@centos7 /usr/local/src/httpd-2.4.27]#cat INSTALL 

 APACHE INSTALLATION OVERVIEW

 Quick Start - Unix
 ------------------

 For complete installation documentation, see [ht]docs/manual/install.html or
 http://httpd.apache.org/docs/2.4/install.html

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

    NOTES: * Replace PREFIX with the filesystem path under which 
             Apache should be installed.  A typical installation
             might use "/usr/local/apache2" for PREFIX (without the
             quotes).

           * Consider if you want to use a previously installed APR and
             APR-Util (such as those provided with many OSes) or if you
             need to use the APR and APR-Util from the apr.apache.org
             project. If the latter, download the latest versions and
             unpack them to ./srclib/apr and ./srclib/apr-util (no
             version numbers in the directory names) and use
             ./configure's --with-included-apr option. This is required
             if you don't have the compiler which the system APR was
             built with.  It can also be advantageous if you are a
             developer who will be linking your code with Apache or using
             a debugger to step through server code, as it removes the
             possibility of version or compile-option mismatches with APR
             and APR-Util code. As a convenience, prepackaged source-code
             bundles of APR and APR-Util are occasionally also provided
             as a httpd-2.X.X-deps.tar.gz download.
......

生成Makefile文件并安装

执行configure文件,定义安装位置为/app/httpd24,开启动态链接功能,开启ssl模块。执行命令./configure --prefix=/app/httpd24 --enable-so --with-ssl

[root@centos7 /usr/local/src/httpd-2.4.27]#./configure --prefix=/app/httpd24 --enable-so --with-ssl
checking for chosen layout... Apache
checking for working mkdir -p... yes
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking build system type... x86_64-pc-linux-gnu
checking host system type... x86_64-pc-linux-gnu
checking target system type... x86_64-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 "  -pthread"
  setting CPPFLAGS to " -DLINUX -D_REENTRANT -D_GNU_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... /usr/bin/pcre-config
configure: Using external PCRE library from /usr/bin/pcre-config
  setting PCRE_INCLUDES to ""
  setting PCRE_LIBS to "-lpcre"
configure: 
configure: Configuring Apache httpd...
......

执行make命令,编译二进制文件,这是一个漫长的过程,等待完成即可。接着执行make install安装

[root@centos7 /usr/local/src/httpd-2.4.27]#make install
Making install in srclib
make[1]: Entering directory `/usr/local/src/httpd-2.4.27/srclib'
make[2]: Entering directory `/usr/local/src/httpd-2.4.27/srclib'
make[2]: Leaving directory `/usr/local/src/httpd-2.4.27/srclib'
make[1]: Leaving directory `/usr/local/src/httpd-2.4.27/srclib'
Making install in os
make[1]: Entering directory `/usr/local/src/httpd-2.4.27/os'
Making install in unix
make[2]: Entering directory `/usr/local/src/httpd-2.4.27/os/unix'
make[3]: Entering directory `/usr/local/src/httpd-2.4.27/os/unix'
make[3]: Leaving directory `/usr/local/src/httpd-2.4.27/os/unix'
make[2]: Leaving directory `/usr/local/src/httpd-2.4.27/os/unix'
make[2]: Entering directory `/usr/local/src/httpd-2.4.27/os'
make[2]: Leaving directory `/usr/local/src/httpd-2.4.27/os'
make[1]: Leaving directory `/usr/local/src/httpd-2.4.27/os'
Making install in server
make[1]: Entering directory `/usr/local/src/httpd-2.4.27/server'
Making install in mpm
make[2]: Entering directory `/usr/local/src/httpd-2.4.27/server/mpm'
Making install in worker
......

更改系统配置

更改配置文件,永久关闭selinux
[root@centos7 /app/httpd24]#vim /etc/selinux/config

修改文件SELINUX=permission

# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
#     enforcing - SELinux security policy is enforced.
#     permissive - SELinux prints warnings instead of enforcing.
#     disabled - No SELinux policy is loaded.
SELINUX=permission
# SELINUXTYPE= can take one of three two values:
#     targeted - Targeted processes are protected,
#     minimum - Modification of targeted policy. Only selected processes are protected. 
#     mls - Multi Level Security protection.
SELINUXTYPE=targeted

systemctl stop firewalld 暂停防火墙
systemctl disable firewalld 取消防火墙开机自启动

[root@centos7 /app/httpd24]#systemctl stop firewalld
[root@centos7 /app/httpd24]#systemctl disable firewalld

配置path变量

进入安装目录
[root@centos7 /usr/local/src/httpd-2.4.27]#cd /app/httpd24/
设置变量脚本
[root@centos7 /app/httpd24]#echo 'export PATH=/app/httpd22/bin:$PATH' > /etc/profile.d/httpd24.sh
检查脚本生成
[root@centos7 /app/httpd24]#cat /etc/profile.d/httpd24.sh 
export PATH=/app/httpd22/bin:$PATH
运行脚本
[root@centos7 /app/httpd24]#. /etc/profile.d/httpd24.sh 
查看变量
[root@centos7 /app/httpd24]#echo $PATH
/app/httpd22/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/root/bin
启动apache
[root@centos7 /app/httpd24]#apachectl
检查端口开放情况,80端口开启即为正常
[root@centos7 /app/httpd24]#ss -ntl
State       Recv-Q Send-Q          Local Address:Port                         Peer Address:Port              
LISTEN      0      50                          *:3306                                    *:*                  
LISTEN      0      128                         *:111                                     *:*                  
LISTEN      0      5               192.168.122.1:53                                      *:*                  
LISTEN      0      128                         *:22                                      *:*                  
LISTEN      0      128                 127.0.0.1:631                                     *:*                  
LISTEN      0      100                 127.0.0.1:25                                      *:*                  
LISTEN      0      128                        :::111                                    :::*                  
LISTEN      0      128                        :::80                                     :::*                  
LISTEN      0      128                        :::22                                     :::*                  
LISTEN      0      128                       ::1:631                                    :::*                  
LISTEN      0      100                       ::1:25                                     :::*          

在浏览器中输入本机ip,即可进入主机网页

安装流程结束

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 202,607评论 5 476
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 85,047评论 2 379
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 149,496评论 0 335
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,405评论 1 273
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,400评论 5 364
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,479评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,883评论 3 395
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,535评论 0 256
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,743评论 1 295
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,544评论 2 319
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,612评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,309评论 4 318
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,881评论 3 306
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,891评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,136评论 1 259
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,783评论 2 349
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,316评论 2 342

推荐阅读更多精彩内容