使用XAMPP搭建本地服务器并运行第一个php文件
2019-03-05 本文已影响0人
拾实
一.XAMPP的下载
官网地址:https://www.apachefriends.org/zh_cn/index.html

下面演示的
Windows
系统下XAMPP的安装与使用。


之后也是一直Next
直至最后Finish
...

启动软件并开启服务,这里我们只需点击
Apache
所在行对应的Start
即可。
二.意料之外的情况
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,请跳到下一步:“三”。
修改端口

在
httpd.conf
中找到 Listen
所在行,修改默认的80(我这里改成了800)

记得
ctrl+s
保存,然后关闭。同样的方式修改
httpd-ssl.conf
中的443端口(我这里改成了444):


再来试一试~

三.运行第一个php文件
找到xampp
安装目录下的htdocs
目录:

进入
htdocs
目录,这里我新建了一个test
文件夹,并将要运行的php文件放入
HelloWorld.php
<!DOCTYPE html>
<html>
<body>
<?php
echo "Hello World";
?>
</body>
</html>
打开浏览器并访问此文件:

因为我在第二步里将端口改成了
800
所以这里前缀是localhost:800
,如果你跳过了第二步,直接在localhost/
后补充路径即可。
四、修改默认的目录
实际上并不是只有放在htdocs
目录下的文件才能被访问,我们可以自己定制。
和之前修改80
端口的操作一样,先打开httpd.conf
:

找到
DocumentRoot
,修改成自己想指定的路径:
试试效果~
