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.rpm
-
添加 ius 源:
rpm -Uvh https://mirrors.tuna.tsinghua.edu.cn/ius/ius-release-el7.rpm
ius 源搜索 httpd,可以看到在 ius 源上是叫作 httpd24u:
下载 httpd24u:
# 安装前卸载旧版本
yum remove httpd*
#安装 新版本
yum install httpd24u
查看查看和启动:
# /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.
Apache 配置
- 配置Apcahe(httpd)支持PHP
步骤1:
搜索ServerName
,把#ServerName www.example.com:80
前面的#
去掉。
然后找如下内容:
修改为:
修改它的目的是,允许所有请求,否则我们访问时回报403错误。
步骤2:
找到下面这行:
在这行下面添加以一行:
步骤3:
找到这一段:
修改为:
保存并退出。
Apache 命令
- 检验配置文件是否正确:
正确的则显示为 “Syntax OK”,否则继续检查修改httpd配置文件。
- 重新启动httpd: