一、xampp安装
下载路径:https://www.apachefriends.org/download.html
(安装这个以后不需要再安装Apache 和 php了)
进入网站可以根据不同需求选择不同的操作系统,自己的电脑是win7系统,64位,是从下面选择其中一个下载的,下载下来的格式:xampp-win32-5.6.24-1-VC11-installer.exe,可以直接进行安装。
安装好之后可以打开启动一下apache看是否可以启动。如果启动时出现:
21:22:25 [Apache] Error: Apache shutdown unexpectedly.
21:22:25 [Apache] This may be due to a blocked port, missing dependencies,
21:22:25 [Apache] improper privileges, a crash, or a shutdown by another method.
21:22:25 [Apache] Press the Logs button to view error logs and check
21:22:25 [Apache] the Windows Event Viewer for more clues
21:22:25 [Apache] If you need more help, copy and post this
21:22:25 [Apache] entire log window on the forums\
Apache服务器所使用的端口被其它程序占用了(80端口或443端口被占用)。解决办法:点击Netstat查看哪个端口号被占用
如果是 443 端口号被占用:
简便的方法是在Apache对应的config中将Listen 443这句注释掉:# Listen 443 或 将443改为4433或其它值(尽量不要使用0-1023)。也可以到安装目录下的httpd-ssl.conf文件中修改。
如果是80端口号被占用:
简便地的方法是 将Listen 80和 ServerName localhost:80中的80改为8081或其它值(尽量不要使用0-1023端口,这个是系统保留端口),要保持一致。也可以到安装目录下的httpd.conf文件中修改。
修改完成后记得重启一下xampp这样才能生效。
二、运行php文件的方法
1. 在xampp的htdocs文件下的php文件可以直接在浏览器中输入localhost/文件路径/文件名.php
例如:我的 helloworld.php 文件放在D:\xampp\htdocs\myProjects下,那么我在浏览器中的运行路径是: localhost/myProjects/helloword.php
2. 如果根据项目需求我不想将开发项目放在安装目录下(D:\xampp\htdocs)路径下,可以吗?答案是可以的。
在Apache安装目录下的conf文件中找到httpd.conf,找到"DocumentRoot”,把后面的路径改成需要指定的目录的绝对路径(注意把"\"改成"/"),比如我想把我的G:\myProjects设置成我php站点的根目录,就把DocumentRoot这一行改为 DocumentRoot "G:/myProjects",修改之后重启Apache,测试是否生效。
如果无法访问你所设置的目录,可以改一下httpd.conf中带绝对路径的<directory>标记,比如我以前的 是<Directory "D:/Program Files.....">,就改成<Directory "G:/myProjects">,然后重启Apache。
3. 想在elclipse下直接运行,需要设置eclipse,设置方法转自:http://blog.csdn.net/silence1214/article/details/8287189