linux 安装apache源码

环境介绍:

    系统环境:CentOS7

 安装需要gcc库 yum install -y gcc gcc-c++

    所需软件包:apr-1.6.2.tar.gz、apr-util-1.6.0.tar.gz、httpd-2.4.27.tar.gz 、pcre-8.35

    注意:官方网站提示apr/arp-util版本要1.4(含)版本以上。

    依赖包:zlib-devel

    # yum install zlib-devel

    开发环境包组:Development Tools, Server Platform Development

    # yum groupinstall "Development Tools" "ServerPlatform Development" -y

1、查询旧版apache包名并卸载。

    rpm -q httpd  查询

    rpm -e --nodeps ttpd-2.2.15-59.el6.centos.x86_64  删除

    或使用如下shell脚本批量删除旧版apache软件包

    for name in `rpm -qa httpd*`;do rpm -e --nodeps $name;done

  进入htpd目录

  执行:   rpm -ivh httpd  安装


2、下载源码包

    wget https://mirrors.aliyun.com/apache/apr/apr-1.5.2.tar.gz

    wget https://mirrors.aliyun.com/apache/apr/apr-util-1.5.4.tar.gz

    wget https://mirrors.aliyun.com/apache/httpd/httpd-2.2.32.tar.gz

   

  http://archive.apache.org/dist/apr/apr-1.5.1.tar.gz
  http://archive.apache.org/dist/apr/apr-util-1.5.1.tar.gz 
  http://jaist.dl.sourceforge.NET/project/pcre/pcre/8.35/pcre-8.35.tar.gz

  

3、解压

    tar -xvf apr-1.5.2.tar.gz

    tar -xf apr-util-1.5.4.tar.gz

    tar -xvf httpd-2.2.32.tar.gz

4、编译安装apr-1.5.2

    cd apr-1.5.2

    ./configure --prefix=/usr/local/apr-httpd/

    make

    make install

5、编译安装apr-util-1.5.4

    cd apr-util-1.5.4

    ./configure --prefix=/usr/local/apr-util-httpd/ --with-apr=/usr/local/apr-httpd/

    make

    make install

6、编译安装httpd-2.2.32

    cd httpd-2.2.32

    ./configure --prefix=/usr/local/apache2 --sysconfdir=/usr/local/apache2/etc/httpd/ --enable-so --enable-deflate --enable-headers --enable-rewrite --with-mpm=prefork --with-apr=/usr/local/apr-httpd/ --with-apr-util=/usr/local/apr-util-httpd/ --with-pcre=/usr/local/pcre

    

    --prefix:安装路径;

    --sysconfdir:指定配置文件路径

    --enable-so:DSO兼容,DSO=Dynamic Shared Object,动态共享对象,可实现模块动态生效;

    --enable-deflate:支持压缩功能;需要zlib-devel包支持;

    --enable-headers:提供允许对HTTP请求头的控制;

    --enable-rewrite:提供基于URL规则的重写功能;

    --with-mpm:设置默认启用的MPM模式,{prefork|worker|event};

    --with-apr:apr安装路径;

    --with-apr-util:apr-util安装的路径;

    --with-pcre:pcre安装目录;

    make

    make install


    卸载源代码包:

    删除源代码所安装位置: rm -rf /usr/local/apache2

    重新安装:删除源代码解压文件然后在进行安装;

      


7、设置二进制命令PATH环境变量

    编辑文件/etc/profile.d/NAME.sh,输入export PATH=/PATH/TO/BIN:$PATH

        vim /etc/profile.d/httpd.sh

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

        . /etc/profile.d/httpd.sh 

    注意:bin路径的放在前面系统在读取配置文件的时候会按照自左向右的顺序读取


   PATH变量设置;

    1.。查看:export  或 echo $PATH;

    2.修改profile文件  所有用户可用 

      vi /etc/profile    

      export PATH="$PATH:安装目录"  

      让环境变量立即生效需要执行如下命令:  

      source /etc/profile

    3. 修改.bashrc文件:  

      # vi /root/.bashrc  

      在里面加入:  

      export PATH="$PATH:/opt/au1200_rm/build_tools/bin"


8、创建链接头文件

    ln -sv /usr/local/apache/include/ /usr/include/httpd

    "/usr/include/httpd" -> “/usr/local/apache/include/"

9、设置MANPATH

    在/etc/man.config文件中新增MANPATH指令,并指向新的命令手册路径;

        vim /etc/man.config

        MANPATH /usr/local/apache/man

10、启动httpd-2.2.32服务

    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 messag

    解决方法:vi /usr/local/apache2/etc/httpd/httpd.conf    

      修改:ServeRoot:localhost:80

11、查看80端口是否被监听

    ss -tnl

12、使用浏览器访问测试   一定要关闭firewall防火墙:(详见防火墙设置)


apache安装目录在:

cd /usr/local/apache2

网页目录;

cd /usr/local /apache2/htdocs


 设置开机启动:

echo "/usr/local/apache2/bin/apachectl start">>/etc/rc.local  假如启动文件rc.local;

cat /etc/rc.local  查看


加入系统服务:

  vi /etc/init.d/httpd

  #chkconfig 35 85 15  三个数分别代表运行级别、开机启动顺序、关机顺序

添加服务:

  chkconfig --add httpd

查看添加:

  chkconfig |grep httpd

开启apache开机启动

  chkconfig httpd on

[Power By XIAOWU]
原文地址:https://www.cnblogs.com/webmans/p/6885436.html