• Apache最新版安装和配置


    Apache 安装

    当前官方 yum 源如 epel,base 的 Apache httpd 版本为 2.4.6-90,可以用 ius 这个第三方 yum 源,该源的特点是提供各类 rpm 包的最新版本。

    • ius 源依赖于 epel 源,如果已经有了可以跳过这一步:

    登录后复制

    rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm1.
    
    • 1
    • 添加 ius 源:

    登录后复制

    rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/ius/ius-release-el7.rpm1.
    
    • 1

    ius 源搜索 httpd,可以看到在 ius 源上是叫作 httpd24u:

    下载 httpd24u:

    登录后复制

     # 安装前卸载旧版本
     yum remove httpd*
     
     #安装 新版本
     yum install httpd24u1.2.3.4.5.
    
    • 1
    • 2
    • 3
    • 4
    • 5

    查看查看和启动:

    登录后复制

    # /sbin/httpd -v
    Server version: Apache/2.4.46 (IUS)
    Server built:   Sep 26 2020 06:55:54
    
    # systemctl start httpd
    # systemctl status httpd
    ● httpd.service - The Apache HTTP Server
       Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
       Active: active (running) since Mon 2021-05-24 18:42:19 CST; 1s ago
         Docs: man:httpd.service(8)
     Main PID: 2466 (httpd)
       Status: "Processing requests..."
       CGroup: /system.slice/httpd.service
               ├─2466 /usr/sbin/httpd -DFOREGROUND
               ├─2467 /usr/sbin/httpd -DFOREGROUND
               ├─2468 /usr/sbin/httpd -DFOREGROUND
               ├─2469 /usr/sbin/httpd -DFOREGROUND
               ├─2471 /usr/sbin/httpd -DFOREGROUND
               └─2478 /usr/sbin/httpd -DFOREGROUND
    May 24 18:42:19 app01 systemd[1]: Starting The Apache HTTP Server...
    May 24 18:42:19 app01 httpd[2466]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 10.10.10.162. Set the 'ServerName' directi... this message
    May 24 18:42:19 app01-call-test-bj2 systemd[1]: Started The Apache HTTP Server.
    Hint: Some lines were ellipsized, use -l to show in full.1.2.3.4.5.6.7.8.9.10.11.12.13.14.15.16.17.18.19.20.21.22.23.
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23

    Apache 配置

    • 配置Apcahe(httpd)支持PHP

    步骤1:

    登录后复制

    [root@zlinux ~]# vim /usr/local/apache2/conf/httpd.conf
    1.
    
    • 1
    • 2

    搜索ServerName,把#ServerName www.example.com:80前面的#去掉。
    然后找如下内容:

    登录后复制

    
        AllowOverride none
        Require all denied
    
    1.2.3.4.
    
    • 1
    • 2
    • 3
    • 4
    • 5

    修改为:

    登录后复制

    
        AllowOverride none
        Require all granted
    
    1.2.3.4.
    
    • 1
    • 2
    • 3
    • 4
    • 5

    修改它的目的是,允许所有请求,否则我们访问时回报403错误。

    步骤2:

    找到下面这行:

    登录后复制

    AddType application/x-gzip .gz .tgz
    1.
    
    • 1
    • 2

    在这行下面添加以一行:

    登录后复制

    AddType application/x-httpd-php .php
    1.
    
    • 1
    • 2

    步骤3:

    找到这一段:

    登录后复制

    
        DirectoryIndex index.html
    
    1.2.3.
    
    • 1
    • 2
    • 3
    • 4

    修改为:

    登录后复制

    
        DirectoryIndex index.html index.php
    
    1.2.3.
    
    • 1
    • 2
    • 3
    • 4

    保存并退出。

    Apache 命令

    • 检验配置文件是否正确:

    登录后复制

    [root@zlinux ~]# /usr/local/apache2/bin/apachectl -t
    Syntax OK
    1.2.
    
    • 1
    • 2
    • 3

    正确的则显示为 “Syntax OK”,否则继续检查修改httpd配置文件。

    • 重新启动httpd:

    登录后复制

    [root@zlinux ~]# /usr/local/apache2/bin/apachectl restart
    [root@zlinux ~]# netstat -lnp | grep httpd
    tcp6       0      0 :::80                   :::*                    LISTEN      5553/httpd     //显示这行说明已经启动httpd
    1.2.3.
    
    • 1
    • 2
    • 3
    • 4

    转至:https://blog.51cto.com/qiangsh/2807887

  • 相关阅读:
    c++的作用域 (局部域,类域,名字命名空间,文件域)
    开设自己的网站系类01购买服务器
    LaunchView/启动页 的实现
    使用Scrcpy投屏
    二进制安装k8s
    一起Talk Android吧(第四百二十四回:绘图知识总结)
    南大通用GBase8s 常用SQL语句(285)
    【python笔记】第六节 序列类型常用方法
    4_使用预训练模型 微调训练CIFAR10
    生物活性分子库
  • 原文地址:https://blog.csdn.net/asd54090/article/details/134410460