美文网首页
使用XAMPP搭建本地服务器并运行第一个php文件

使用XAMPP搭建本地服务器并运行第一个php文件

作者: 拾实 | 来源:发表于2019-03-05 21:04 被阅读0次

一.XAMPP的下载

官网地址:https://www.apachefriends.org/zh_cn/index.html

根据自己的系统选择对应的版本
下面演示的Windows系统下XAMPP的安装与使用。
Next 根据需要选择,Next 设置路径,Next

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

Finish
启动软件并开启服务,这里我们只需点击Apache所在行对应的Start即可。
点击红圈圈中的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)
httpd.conf
修改后
记得ctrl+s保存,然后关闭。
同样的方式修改httpd-ssl.conf中的443端口(我这里改成了444):
点击httpd-ssl.conf
httpd-ssl.conf
修改后
再来试一试~
成功!

三.运行第一个php文件

找到xampp安装目录下的htdocs目录:

htdocs
进入htdocs目录,这里我新建了一个test文件夹,并将要运行的php文件放入
image.png
HelloWorld.php
<!DOCTYPE html>
<html>
<body>
    <?php
        echo "Hello World";  
    ?>
</body>
</html>

打开浏览器并访问此文件:

HelloWorld
因为我在第二步里将端口改成了800所以这里前缀是localhost:800,如果你跳过了第二步,直接在localhost/后补充路径即可。

四、修改默认的目录

实际上并不是只有放在htdocs目录下的文件才能被访问,我们可以自己定制。
和之前修改80端口的操作一样,先打开httpd.conf

按顺序依次点击
找到DocumentRoot,修改成自己想指定的路径:
两处均需要修改
试试效果~
依然可以运行

相关文章

网友评论

      本文标题:使用XAMPP搭建本地服务器并运行第一个php文件

      本文链接:https://www.haomeiwen.com/subject/xqzouqtx.html