install apache

1.下载apache
#网址
http://httpd.apache.org/download.cgi#apache24
2.解压
tar -zxvf httpd-2.4.28.tar.gz
3.查看帮助
#进入httpd-2.4.28
./configure --help
4.编译安装
源码的编译安装一般由3个步骤组成:
    配置(configure),通常依赖gcc编译器,binutils,glibc。
    配置软件特性,检查编译环境,生成 Makefile文件
    编译(make)
    安装(make install)

优势
    自定义软件功能
    优化编译参数,提高性能
    解决不必要的软件间依赖
    方便清理与卸载
5.配置
configure是一个可执行脚本,它有很多选项,在待安装的源码路径下使用命令./configure –-help输出详细的选项列表。
常用的选项
--prefix
    该选项是配置安装的路径,如果不配置该选项,安装后可执行文件默认放在/usr /local/bin,
    库文件默认放在/usr/local/lib,配置文件默认放在/usr/local/etc,其它的资源文件放在/usr /local/share

    如果配置--prefix,如: ./configure --prefix=/usr/local/test
    则可以把所有资源文件放在/usr/local/test的路径中,不会杂乱。
    用了—prefix选项的另一个好处是卸载软件或移植软件。
    当某个安装的软件不再需要时,只须简单的删除该安装目录,就可以把软件卸载得干干净净;
    移植软件只需拷贝整个目录到另外一个机器即可(相同的操作系统)。
    当然要卸载程序,也可以在原来的make目录下用一次make uninstall,但前提是make文件指定过uninstall。
6.依赖
#依赖apr,apr-util下载
http://apr.apache.org/download.cgi
#安装apr
---------------
./configure --prefix /usr/apache/apr
make
make install
---------------
#安装apr-utl
--------------
./configure --prefix /usr/apache/apr-util --with-apr=/usr/apache/apr
make
make install
--------------


#依赖pcre
pcre-devel
https://ubuntu.pkgs.org/
#ubuntu系统没有pcre-devel 可以用以下方案替代
sudo apt-get update 
sudo apt-get install libpcre3 libpcre3-dev 

#还需要安装openSSL
sudo apt-get install openssl libssl-dev
7.编译apache httpd
 # cd httpd-2.4.28
    # ./configure                           \
        --with-apr=/usr/apache/apr           \
        --with-apr-util=/usr/apache/apr-util \
        --prefix=/usr/apache \
        --sysconfdir=/etc/httpd24  \
        --enable-so                \
        --enable-ssl               \
        --enable-cgi               \
        --enable-rewrite           \
        --with-zlib                \
        --with-pcre                \
        --with-mpm=prefork         \
        --enable-modules=most      \
        --enable-mpms-shared=all   

    # make 
    # make install

    -------------------------
            几个主要的配置项
        --sysconfdir=/etc/httpd24  指定配置文件路径
        --enable-so  启动模块动态装卸载
        --enable-ssl 编译ssl模块
        --enable-cgi 支持cgi机制(能够让静态web服务器能够解析动态请求的一个协议)
        --enable-rewrite  支持url重写    
        --with-zlib  支持数据包压缩      
        --with-pcre  支持正则表达式
        --with-apr=/usr/local/apr  指明依赖的apr所在目录
        --with-apr-util=/usr/local/apr-util/  指明依赖的apr-util所在的目录
        --enable-modules=most      启用的模块
        --enable-mpms-shared=all   以共享方式编译的模块
        --with-mpm=prefork         指明httpd的工作方式为prefork
8.服务器启/停
在安装目录中进入bin
./apachectl start
##---启动出错
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using fe80::8d1f:fbd2:7e00:1a9f. Set the 'ServerName' directive globally to suppress this message
-----------
修改配置文件/etc/httpd24/httpd.conf
将ServerName examle:80 改为 localhost:80  正常启动

./apachectl restart 重启
./apachectl stop 停止
--------------
#可以通过lsof -i:80  或者netstat -nltp|grep 80查看端口是否正常启动
9.配置自启动文件
    可以通过复制2.2版本的启动文件,修改相关路径后将2.4版作为单独服务运行,如下
    注启动文件pid文件位置要配置成与/usr/local/apache/bin/apachectl -V看到的pid位置一致
        查看pid位置
        # /usr/local/apache/bin/apachectl -V|grep pid
         -D DEFAULT_PIDLOG="logs/httpd.pid"

        # cp /etc/init.d/httpd /etc/init.d/httpd24 
        # vi /etc/init.d/httpd24  
        # diff /etc/init.d/httpd /etc/init.d/httpd24 
            26,27c26,27
            < if [ -f /etc/sysconfig/httpd ]; then
            <         . /etc/sysconfig/httpd
            ---
            > if [ -f /etc/httpd24 ]; then
            >         . /etc/httpd24
            42,46c42,46
            < apachectl=/usr/sbin/apachectl
            < httpd=${HTTPD-/usr/sbin/httpd}
            < prog=httpd
            < pidfile=${PIDFILE-/var/run/httpd/httpd.pid}
            < lockfile=${LOCKFILE-/var/lock/subsys/httpd}
            ---
            > apachectl=/usr/local/apache/bin/apachectl
            > httpd=${HTTPD-/usr/local/apache/bin/httpd}
            > prog=httpd24
            > pidfile=${PIDFILE-/usr/local/apache/logs/httpd.pid}
            > lockfile=${LOCKFILE-/var/lock/subsys/httpd24}

        # service httpd24 start
        Starting httpd24:                          [  OK  ]
        # service httpd24 status
        httpd (pid  15641) is running...

        # netstat -nltp|grep 80
        tcp        0      0 :::80     :::*     LISTEN      15677/httpd   ###2.2版httpd       
        tcp        0      0 :::8080   :::*     LISTEN      15641/httpd   ###2.4版httpd

    可以通过复制apachectl文件生成服务脚本     
        # cp /usr/local/apache/bin/apachectl /etc/init.d/httpd249

        # service httpd249 start
        # service httpd249 status
        ELinks: Connection refused    ###该方式无法查看到状态     

        [root@orasrv1 bin]# netstat -nltp|grep 80
        tcp        0      0 :::8080     :::*     LISTEN      15999/httpd   

    最后将配置文件添加到服务,以下为http24为例
        # chkconfig --add httpd24
        # chkconfig httpd24 on
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值