一.XAMPP的下载
官网地址:https://www.apachefriends.org/zh_cn/index.html
![](https://img.haomeiwen.com/i13713347/b4832e6457f0af0c.png)
下面演示的
Windows
系统下XAMPP的安装与使用。![](https://img.haomeiwen.com/i13713347/f3ddc8e850bcaefa.png)
![](https://img.haomeiwen.com/i13713347/5577a76a9dea0da1.png)
![](https://img.haomeiwen.com/i13713347/3d64f351fef4b6cc.png)
之后也是一直Next
直至最后Finish
...
![](https://img.haomeiwen.com/i13713347/02a9260d881dab18.png)
启动软件并开启服务,这里我们只需点击
Apache
所在行对应的Start
即可。![](https://img.haomeiwen.com/i13713347/13316f44862846e4.png)
二.意料之外的情况
20:00:34 [Apache] Status change detected: stopped
20:00:34 [Apache] Error: Apache shutdown unexpectedly.
20:00:34 [Apache] This may be due to a blocked port, missing dependencies,
20:00:34 [Apache] improper privileges, a crash, or a shutdown by another method.
20:00:34 [Apache] Press the Logs button to view error logs and check
20:00:34 [Apache] the Windows Event Viewer for more clues
20:00:34 [Apache] If you need more help, copy and post this
20:00:34 [Apache] entire log window on the forums
也许你也会遇到和我一样遇到上面的情况,出现这样的情况有可能是80, 443
端口被占用,我们在配置中改一下端口,如果你成功running,请跳到下一步:“三”。
修改端口
![](https://img.haomeiwen.com/i13713347/73e6b569a306f537.png)
在
httpd.conf
中找到 Listen
所在行,修改默认的80(我这里改成了800)![](https://img.haomeiwen.com/i13713347/593199e87a75e86a.png)
![](https://img.haomeiwen.com/i13713347/3ee62e84aedc06cf.png)
记得
ctrl+s
保存,然后关闭。同样的方式修改
httpd-ssl.conf
中的443端口(我这里改成了444):![](https://img.haomeiwen.com/i13713347/d8f70c7854646525.png)
![](https://img.haomeiwen.com/i13713347/a29713767cb421c2.png)
![](https://img.haomeiwen.com/i13713347/ff5d98842ce9192c.png)
再来试一试~
![](https://img.haomeiwen.com/i13713347/603d5111244ed5ca.png)
三.运行第一个php文件
找到xampp
安装目录下的htdocs
目录:
![](https://img.haomeiwen.com/i13713347/261032c490034c9e.png)
进入
htdocs
目录,这里我新建了一个test
文件夹,并将要运行的php文件放入![](https://img.haomeiwen.com/i13713347/9f9333a64dcb3441.png)
HelloWorld.php
<!DOCTYPE html>
<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
打开浏览器并访问此文件:
![](https://img.haomeiwen.com/i13713347/c14c5898e28a439e.png)
因为我在第二步里将端口改成了
800
所以这里前缀是localhost:800
,如果你跳过了第二步,直接在localhost/
后补充路径即可。
四、修改默认的目录
实际上并不是只有放在htdocs
目录下的文件才能被访问,我们可以自己定制。
和之前修改80
端口的操作一样,先打开httpd.conf
:
![](https://img.haomeiwen.com/i13713347/73e6b569a306f537.png)
找到
DocumentRoot
,修改成自己想指定的路径:![](https://img.haomeiwen.com/i13713347/5e90f5cf4bd2300a.png)
试试效果~
![](https://img.haomeiwen.com/i13713347/b35fc5c52386c9ab.png)
网友评论