【CentOS】配置 Apache 服务

sh 复制代码
yum install httpd -y

# 查看是否安装成功
httpd -v
# 出现版本号表示成功

# 启动服务
systemctl start httpd

# 查看状态
systemctl status httpd
# running 即可成功
● httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Tue 2023-12-05 16:23:38 CST; 5s ago
     Docs: man:httpd.service(8)
 Main PID: 2595 (httpd)
   Status: "Started, listening on: port 80"
    Tasks: 213 (limit: 4636)
   Memory: 35.9M
   CGroup: /system.slice/httpd.service
           ├─2595 /usr/sbin/httpd -DFOREGROUND
           ├─2596 /usr/sbin/httpd -DFOREGROUND
           ├─2597 /usr/sbin/httpd -DFOREGROUND
           ├─2598 /usr/sbin/httpd -DFOREGROUND
           └─2599 /usr/sbin/httpd -DFOREGROUND

12月 05 16:23:37 yuanxin.linux.com systemd[1]: Starting The Apache HTTP Server...
12月 05 16:23:38 yuanxin.linux.com systemd[1]: Started The Apache HTTP Server.
12月 05 16:23:38 yuanxin.linux.com httpd[2595]: Server configured, listening on: port 80

# 将服务设置为开机启动
systemctl enable httpd

# 将出现
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.

# 查看内容地址
ip addr

# 将出现---ens160 中的 192.168.212.129 就是我们的内网地址
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 00:0c:29:5a:78:f6 brd ff:ff:ff:ff:ff:ff
    inet 192.168.212.129/24 brd 192.168.212.255 scope global noprefixroute ens160
       valid_lft forever preferred_lft forever
    inet6 fe80::20c:29ff:fe5a:78f6/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever
3: virbr0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc noqueue state DOWN group default qlen 1000
    link/ether 52:54:00:46:03:15 brd ff:ff:ff:ff:ff:ff
    inet 192.168.122.1/24 brd 192.168.122.255 scope global virbr0
       valid_lft forever preferred_lft forever
4: virbr0-nic: <BROADCAST,MULTICAST> mtu 1500 qdisc fq_codel master virbr0 state DOWN group default qlen 1000
    link/ether 52:54:00:46:03:15 brd ff:ff:ff:ff:ff:ff

# 访问内网地址时,如果显示无法访问,可以尝试关闭 centos 的防火墙
systemctl stop firewalld.service

# 禁止自启动
systemctl disable firewalld.service

# 查看防火墙状态
systemctl status firewalld.service

# 如果是关闭状态就算完成了
● firewalld.service - firewalld - dynamic firewall daemon
   Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; vendor preset: enabled)
   Active: inactive (dead)
     Docs: man:firewalld(1)

在主机中访问我们的内容地址:

相关推荐
Lonely 净土1 天前
Linux 运维文件写入操作
linux·运维·服务器·文件管理
吠品1 天前
Wine 在 Linux 上运行 Windows 软件完整指南
java·linux·服务器
深念Y1 天前
从 Windows 迁移到 Linux 开发环境的记录
linux·windows·链接·bun·ram·imdisk
深维AI随笔1 天前
《构建之法》| 第二章个人技术和流程:单元测试不是“可选“,而是“必需“
单元测试·log4j·apache
知无不研1 天前
Linux I/O复用之epoll
linux·服务器·epoll·socket编程
fb_123451 天前
Linux运维封神|SELinux详解+CentOS7启动原理+Root密码重置+开机故障排查实战
linux·运维·服务器
苏宸啊1 天前
linux网络编程udp服务器和客户端代码编写(echo版本和字典版本)
linux·网络
~|Bernard|1 天前
Linux 定时任务(Cron)完整教程
linux·运维·服务器
小雪崩1 天前
嵌入式学习 day25:哈希表及排序与查找
linux·c语言·数据结构·学习·排序算法
深念Y1 天前
linux桌面快捷方式开关脚本编写中的几个常见坑
linux·运维·服务器·快捷方式·桌面·kde