CentOS7 Apache 服务器的配置【已修复】
Linux Apache 服务器的配置
--- 转载文章,有所修改!原文地址在文末
Linux版本:centos8【不要用centos8,不要折磨自己好吧!】
赶紧换成centos7
Apache的特点是简单、速度快、性能稳定。Apache提供了丰富的功能,包括目录索引、目录别名、虚拟主机、HTTP日志报告、CGI程序的SetUID执行及联机手册man等。
安装
cat /etc/redhat-release 查看linux版本
uname -a 查看Linux位数
yum install httpd 安装命令
安装完成后的提示
[root@192 ~]# cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
[root@192 ~]# uname -a
Linux 192.168.134.130 3.10.0-1160.el7.x86_64 #1 SMP Mon Oct 19 16:18:59 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[root@192 ~]# yum install httpd
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
* base: mirrors.tuna.tsinghua.edu.cn
* extras: mirrors.163.com
* updates: mirrors.163.com
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-97.el7.centos.4 will be installed
--> Processing Dependency: httpd-tools = 2.4.6-97.el7.centos.4 for package: httpd-2.4.6-97.el7.centos.4.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-97.el7.centos.4.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-97.el7.centos.4.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-97.el7.centos.4.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-7.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-97.el7.centos.4 will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
======================================================================================
Package Arch Version Repository Size
======================================================================================
Installing:
httpd x86_64 2.4.6-97.el7.centos.4 updates 2.7 M
Installing for dependencies:
apr x86_64 1.4.8-7.el7 base 104 k
apr-util x86_64 1.5.2-6.el7 base 92 k
httpd-tools x86_64 2.4.6-97.el7.centos.4 updates 94 k
mailcap noarch 2.1.41-2.el7 base 31 k
Transaction Summary
======================================================================================
Install 1 Package (+4 Dependent packages)
Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]: Y
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/mailcap-2.1.41-2.el7.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for mailcap-2.1.41-2.el7.noarch.rpm is not installed
(1/5): mailcap-2.1.41-2.el7.noarch.rpm | 31 kB 00:00:00
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm | 92 kB 00:00:00
Public key for httpd-tools-2.4.6-97.el7.centos.4.x86_64.rpm is not installed
(3/5): httpd-tools-2.4.6-97.el7.centos.4.x86_64.rpm | 94 kB 00:00:00
(4/5): apr-1.4.8-7.el7.x86_64.rpm | 104 kB 00:00:00
(5/5): httpd-2.4.6-97.el7.centos.4.x86_64.rpm | 2.7 MB 00:00:01
--------------------------------------------------------------------------------------
Total 1.8 MB/s | 3.0 MB 00:01
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-9.2009.0.el7.centos.x86_64 (@anaconda)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Is this ok [y/N]: Y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : apr-1.4.8-7.el7.x86_64 1/5
Installing : apr-util-1.5.2-6.el7.x86_64 2/5
Installing : httpd-tools-2.4.6-97.el7.centos.4.x86_64 3/5
Installing : mailcap-2.1.41-2.el7.noarch 4/5
Installing : httpd-2.4.6-97.el7.centos.4.x86_64 5/5
Verifying : httpd-tools-2.4.6-97.el7.centos.4.x86_64 1/5
Verifying : apr-1.4.8-7.el7.x86_64 2/5
Verifying : mailcap-2.1.41-2.el7.noarch 3/5
Verifying : httpd-2.4.6-97.el7.centos.4.x86_64 4/5
Verifying : apr-util-1.5.2-6.el7.x86_64 5/5
Installed:
httpd.x86_64 0:2.4.6-97.el7.centos.4
Dependency Installed:
apr.x86_64 0:1.4.8-7.el7 apr-util.x86_64 0:1.5.2-6.el7
httpd-tools.x86_64 0:2.4.6-97.el7.centos.4 mailcap.noarch 0:2.1.41-2.el7
Complete!
[root@192 ~]#
设置httpd服务开机启动
[root@192 ~]# systemctl enable httpd
Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.
启动Apache
systemctl start httpd
查看Apache的状态
systemctl status httpd
[root@192 ~]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Sun 2022-03-20 09:43:48 PDT; 34s ago
Docs: man:httpd(8)
man:apachectl(8)
Main PID: 64420 (httpd)
Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec"
Tasks: 6
CGroup: /system.slice/httpd.service
├─64420 /usr/sbin/httpd -DFOREGROUND
├─64421 /usr/sbin/httpd -DFOREGROUND
├─64422 /usr/sbin/httpd -DFOREGROUND
├─64423 /usr/sbin/httpd -DFOREGROUND
├─64424 /usr/sbin/httpd -DFOREGROUND
└─64425 /usr/sbin/httpd -DFOREGROUND
Mar 20 09:43:48 192.168.134.130 systemd[1]: Starting The Apache HTTP Server...
Mar 20 09:43:48 192.168.134.130 systemd[1]: Started The Apache HTTP Server.
确认80端口的状态
netstat -tulp
查看Apache的版本
httpd -v
验证安装
用浏览器打开服务器的IP地址用ifconfig看一下本机的IP就行了!
,将看到默认的Apache欢迎页面表示成功
这个地方其实没什么,但是要注意的地方是要在你的Linux图形界面上打开才能看到效果偶!
Apache命令
停止Apache服务
systemctl stop httpd
启动Apache服务
systemctl start httpd
重启Apache服务
systemctl restart httpd
禁用Apache开机自启动
systemctl disable httpd
Apache开机自启动
systemctl enable httpd
更改配置后重新加载Apache服务
systemctl reload httpd
Apache的主配置文件:/etc/httpd/conf/httpd.conf
安装完后就可以到Apache的默认目录/var/www/html 添加一个简单的index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<h1>Hello World!</h1>
<h1>Hello lvhanghmm!</h1>
</body>
</html>
再次在浏览器输入ip地址就会显示以下界面【也可以直接刷新页面】
原文地址
本文来自博客园,作者:{lvhanghmm},转载请注明原文链接:https://www.cnblogs.com/lvhanghmm/p/16017429.html