文章转自:https://blog.csdn.net/weixin_39212776/article/details/81192847
一、安装apache2
$ apt install apache2
二、开启apache服务
$ /etc/init.d/apache2 start
浏览器输入127.0.0.1看到以下apache默认网页即成功开启
也可以使用:
$ netstat -tunlp
查看apache服务是否开启
如下是已经开启apache并且占用了80端口
三、配置apache
配置文件在/etc/apache2/sites-enabled/000-default.conf
默认工作根目录/var/www/html
(修改DocumentRoot即修改工作根目录)
apache默认使用80端口,如果80端口被占用了,那么就修改默认端口;
配置文件在/etc/apache2/ports.conf
可以改成8080或者其他端口;然后输入127.0.0.1:8080 或者127.0.0.1:其他端口即可查看到默认页
四、测试
在/var/www/html下,修改index.html为:
<html>
<head>
<title>self-apache-index</title>
</head>
<body>
<h1>Welcome to apache!</h1>
</body>
</html>
重新打开浏览器,输入127.0.0.1即可看到 Welcome to apache字样。
PS:本地浏览器地址127.0.0.1 默认是80端口,即127.0.0.1 相当于127.0.0.1:80
如果你修改了ports.conf中的端口号,那么按照前面定义的端口输入对应的端口即可