CentOS 7 最小安装搭建lamp系列之(二),源码编译安装httpd-2.4.29

在之前的基础上,我们继续安装apache(httpd)。

上一篇:CentOS 7 最小安装搭建lamp系列之(一),二进制源码安装mariadb-10.2.13

准备工作:

    1、httpd-2.4.29所依赖的包:apr,apr-util,pcre,gcc

    2、编译apr-util所依赖的包:expat-devel

    3、下载工具wget

    注:arp,arp-util,pcre编译安装,gcc,expat-devel通过yum工具安装。

第一步:安装wget、解决依赖关系:

         cd /file  ##这个目录用于存放下载的文件 

   1、yum install gcc expat-devel wget      ##

   2、wget http://mirror.bit.edu.cn/apache//apr/apr-1.6.3.tar.gz      ##下载apr-1.6.3.tar.gz

        tar zxvf apr-1.6.3.tar.gz      ##

        cd apr-1.6.3      ##

        ./configure --prefix=/usr/local/apr      ##安装在/usr/local/apr目录下

        make -j && make install      ##-j 表示启用多线程,加快安装速度

        cd /file      ##

    3、wget https://archive.apache.org/dist/apr/apr-util-1.5.4.tar.gz      ##值得注意的是,这里我选择apr-util-1.5.4,因为apr-util最新版编译httpd的时候会出错

        tar zxvf apr-util-1.5.4.tar.gz      ##

        cd apr-util-1.5.4      ##

        ./configure --prefix=/usr/local/apr-util --with-apr=/usr/local/apr/      ##安装在/usr/local/apr-util目录下,记得加上--with-apr

        make -j && make install      ##

    4、cd ../      ##

        wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.40.tar.gz      ##下载pcre-8.40

        tar zxvf pcre-8.40.tar.gz      ##

        cd pcre-8.40      ##

        ./configure --prefix=/usr/local/pcre      ##proc安装在/usr/local/pcre目录下

        make -j && make install      ##


第二步:下载、安装httpd-2.4.29:

        cd /file      ##

    1、wget http://mirrors.hust.edu.cn/apache//httpd/httpd-2.4.29.tar.gz      ##下载httpd-2.4.29

    2、tar zxvf httpd-2.4.29.tar.gz      ##

    3、cd httpd-2.4.29      ##

    4、./configure -h      ##查看编译配置的help说明,选择性地安装需要的功能

   5、./configure --prefix=/usr/local/apache24 --sysconfdir=/etc/httpd24 --enable-so --enable-cgi --with-z --with-apr=/usr/local/apr --with-apr-util=/usr/local/apr-util --with-pcre=/usr/local/pcre --enable-mpms-shared=all --with-mpm=prefork      ##作下简单说明:

##--prefix:设置httpd安装目录

##--sysconfdir:设置htttpd配置文件目录

##--with-apr,--with-apr-util,--with-pcre:编译安装的依赖包所在路径

##--enable-mpms-shared=all:把httpd的三种工作模式(mpm机制)prefork、worker、event构建成动态模块,在使用时可以通过LoadModule的方式实现内核模块动态装卸载。

##--with-mpm:选择默认的mpm

    6、make -j && make install      ##要等好一会儿~先喝杯茶。

    安装完毕。

第三步:基本配置:

    1、cp /usr/local/apache24/bin/apachectl  /etc/init.d/httpd      ##把apachectl拷贝到/etc/init.d/下重命名为httpd

    2、vim /etc/profile.d/httpd.sh      ##把httpd的bin文件路径加到PATH环境变量中


        . /etc/profile.d/httpd.sh      ##重载这个文件

    3、systemctl daemon-reload     ##

    4、systemctl start httpd      ##启动httpd,systemctl status httpd查看运行状态,显示正在运行


用ip addr查看自己的ip地址(或者直接http://localhost/也ok),在浏览器打开    


显示连接超时,问题不大,用命令:systemctl stop firewalld      ##关闭防火墙,重新打开


显示it works!,httpd基本配置完毕!



其它配置:

    一、输出httpd的man手册至man命令的查找路径:vim /etc/man_db.conf      ##添加MANDATORY_MANPATH                       /usr/local/apache24/man


二、开机重启,可以参照链接:编译安装httpd 加入开机启动

三、修改Apache的运行用户(为apache):

        groupadd -r apache        ##

        useradd -g apache -r apache        ##

        vim /etc/httpd24/httpd.conf        ##修改运行的用户和组


    


    以上,希望对大家有帮助,若有不当请指出。

    下一篇:CentOS 7 最小安装搭建lamp系列之(三),源码编译安装php-7.0.28

    本文为原创文章,转载请标明出处。        

猜你喜欢

转载自blog.csdn.net/zoushichao_/article/details/79554568