zoukankan      html  css  js  c++  java
  • Centos7 Apache 2.4.18编译安装

    安装环境:CentOS Linux release 7.0.1406 (Core)

    0x01

    到官网http://httpd.apache.org/download.cgi#apache24下载apache http最新版

    tar zxf httpd-2.4.18.tar.gz

    [root@localhost httpd-2.4.18]# rpm -qa | grep apr          查看当前主机上是否安装apr/apr-util,这个库为apache提供跨平台的支持

    [root@localhost httpd-2.4.18]# yum install apr apr-util   这两个包在光盘镜像都有,配置和yum源即可

     使用yum安装的apr位置信息

    [root@localhost httpd-2.4.18]# rpm -ql apr
    /usr/lib64/libapr-1.so.0
    /usr/lib64/libapr-1.so.0.4.8
    /usr/share/doc/apr-1.4.8
    /usr/share/doc/apr-1.4.8/CHANGES
    /usr/share/doc/apr-1.4.8/LICENSE
    /usr/share/doc/apr-1.4.8/NOTICE
    [root@localhost httpd-2.4.18]# rpm -ql apr-util
    /usr/lib64/apr-util-1
    /usr/lib64/libaprutil-1.so.0
    /usr/lib64/libaprutil-1.so.0.5.2
    /usr/share/doc/apr-util-1.5.2
    /usr/share/doc/apr-util-1.5.2/CHANGES
    /usr/share/doc/apr-util-1.5.2/LICENSE
    /usr/share/doc/apr-util-1.5.2/NOTICE

    0x02 Apache编译选项

    --prefix=/usr/local/apache 
    --sysconfdir=/etc/httpd 
    --with-apr=/usr/local/apr
    --with-apr-util=/usr/local/apr-util 

    --enable-so             //打开 so 模块,so 模块是用来提 DSO 支持的,提供动态共享模块与php协作
    --enable-ssl             //https使用
    --enable-cgi            //为非线程方式工作的mpm使用
    --enable-rewrite     //支持 URL 重写
    --enable-zlib          //通用压缩机制
    --with-pcre            //支持pcre
    --enable-module=most      //启用大多数常用的模块
    --enable-mpms-shared=most        //启用MPM支持的模式,启用哪种mpm(prefork,worker,event),使用worker或event时要另外一种方式编译
    php(编译时使用了–enable-maintainer-zts选项)
    --with-mpm=MPM          //指定默认的mpm

    --enable-deflate       //传输压缩机制,节约带宽
    --enable-cgid         //以线程工作(worker/event)的mpm使用

    更多的选项可以通过./configure --help 了解

    官方的编译选项文档http://httpd.apache.org/docs/current/programs/configure.html

     

    0x03 安装

    [root@localhost httpd-2.4.18]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-zlib --enable-module=most --enable-mpms-shared=most --with-mpm=event

    使用以上编译选项进行编译,编译的时候发现报错,难道使用yum安装的apr就不行了吗?还是因为版本问题导致的。其实这里说明apr-config文件,但是apr的rpm包并未包含,所以应该安装apr-devel的rpm包。这里用源码安装解决

    checking for APR... configure: error: the --with-apr parameter is incorrect. It must specify an install prefix, a build directory, or an apr-config file.

    1、到官网下载apr和apr-util源码安装。

    [root@localhost httpd-2.4.18]# tar zxf /mymnt/mnt/apr-1.5.2.tar.gz -C /usr/local/src/
    [root@localhost httpd-2.4.18]# tar zxf /mymnt/mnt/apr-util-1.5.4.tar.gz -C /usr/local/src/

     

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

    [root@localhost httpd-2.4.18]# ./configure --prefix=/usr/local/apache2 --sysconfdir=/etc/httpd --enable-so --enable-ssl --enable-cgi --enable-rewrite --enable-zlib --enable-module=most --enable-mpms-shared=most --with-mpm=event --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util

    2、安装完apr后还需要安装pcre,打算到官网下载的,很简洁的网页,但是下载页面打不开。在yum源中找到了

    configure: error: pcre-config for libpcre not found. PCRE is required and available from http://pcre.org/

    [root@localhost httpd-2.4.18]# yum install pcre-devel 

    3、继续执行checking whether to enable mod_ssl... configure: error: mod_ssl has been requested but can not be built due to prerequisite failures,这是因为缺少openssl

    [root@localhost httpd-2.4.18]# yum install openssl-devel

    4、最后出现的一个报错是configure: error: MPM most does not support dynamic loading.

    从字面上可以了解,此时将--enbale-mpm-shared改为all即可 

    make && make install

    0x04  如何启动

    没有做任何设置尝试启动时 [root@localhost apache2]# bin/apachectl start

    AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

    更改下主机名即可或者直接忽略

    Apache 没有带服务脚本,所以需要自己编写一个用来实现开机启动。当然这里临时使用的就略过了

    附:编译安装后一般设置

    1、导出头文件;以目录链接的形式来实现

    [root@localhost]# ln -sv /usr/local/apache2/include/ /usr/include/httpd


    2、输出二进制程序

    [root@localhost]# vim /etc/profile.d/httpd24.sh

    export PATH=/usr/local/apache2/bin:$PATH

    [root@localhost]#. /etc/profile.d/httpd24.sh


    3、导出man文件

    [root@localhost]# vim /etc/man.config

    MANPATH /usr/local/apache2/man

    [root@localhost]# man -M /usr/local/apache2/man httpd

    4、导出库文件

     把lib目录路径输出到/etc/ld.so.conf.d

    [root@localhost]#echo “/usr/local/apache2/lib” > /etc/ld.so.conf.d/httpd

    5、服务脚本

    写个启动脚本放置在/etc/init.d/目录即可用service启动

     

  • 相关阅读:
    Linux常用指令
    maven报错 java.lang.RuntimeException: com.google.inject.CreationException: Unable to create injector, see the following errors
    Idea 项目jdk环境配置
    Idea 设置maven配置文件settings.xml的位置
    IntelliJ IDEA常用快捷键总结
    Idea 一个窗口打开多个项目
    Git 下拉项目
    Git 删除本地保存的账号和密码
    mysql 查询奇偶数
    redis 短信验证码
  • 原文地址:https://www.cnblogs.com/otherside/p/5240242.html
Copyright © 2011-2022 走看看