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.
  • 添加 ius 源:

登录后复制

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

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

下载 httpd24u:

登录后复制

 # 安装前卸载旧版本
 yum remove httpd*
 
 #安装 新版本
 yum install httpd24u1.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.

Apache 配置

  • 配置Apcahe(httpd)支持PHP

步骤1:

登录后复制

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

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

登录后复制

<Directory />
    AllowOverride none
    Require all denied
</Directory>
1.2.3.4.

修改为:

登录后复制

<Directory />
    AllowOverride none
    Require all granted
</Directory>
1.2.3.4.

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

步骤2:

找到下面这行:

登录后复制

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

在这行下面添加以一行:

登录后复制

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

步骤3:

找到这一段:

登录后复制

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>
1.2.3.

修改为:

登录后复制

<IfModule dir_module>
    DirectoryIndex index.html index.php
</IfModule>
1.2.3.

保存并退出。

Apache 命令

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

登录后复制

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

正确的则显示为 “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.

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

LuckyTHP

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值