我试图建立一个PHP网站,我想测试我的PHP文件,而不是上传到我的主机。基本上是在上传之前先在我自己的机器上测试。我怎么做呢?
当前回答
安装并运行XAMPP: http://www.apachefriends.org/en/xampp.html
其他回答
安装XAMPP。如果你用的是MS Windows, WAMP也是一种选择。
如果你有一台本地机器,有正确的软件:支持PHP的web服务器,没有理由你不能像你描述的那样做。
目前我正在一台Windows XP机器上使用XAMPP,(在家里)使用Kubuntu和LAMP堆栈。
您还可以使用代码在PHP中创建自己的服务器!
<?php
set_time_limit(0);
$address = '127.0.0.1';
$port =4444;
$server = '$address + $port';
// <-- Starts Server
$sock = socket_create(AF_INET, SOCK_STREAM, 0);
socket_bind($sock, $address, $port) or die('Could not bind to address');
echo "\n Server is running on port $port waiting for connection... \n\n";
while(1)
{
socket_listen($sock);
$client = socket_accept($sock);
$input = socket_read($client, 443);
$incoming = array();
$incoming = explode("\r\n", $input);
$fetchArray = array();
$fetchArray = explode(" ", $incoming[0]);
$file = $fetchArray[1];
if($file == "/"){
$file = "src/browser.php";//当服务器启动时,这个文件是打开的!
} else {
$filearray = array();
$filearray = explode("/", $file);
$file = $filearray[1];
}
echo $fetchArray[0] . " Request " . $file . "\n";
// <-- Control Header
$output = "";
$Header = "HTTP/1.1 200 OK \r\n" .
"Date: Fri, 31 Dec 1999 23:59:59 GMT \r\n" .
"Content-Type: text/html \r\n\r\n";
$Content = file_get_contents($file);
$output = $Header . $Content;
socket_write($client,$output,strlen($output));
socket_close($client);
}
print('server running..');
运行这段代码,然后打开浏览器到localhost:443或任何您选择的端口
AppServ是一个在Windows中运行的小程序:
Apache PHP MySQL phpMyAdmin
它还将为Apache提供启动和停止按钮。我觉得这很有用。
安装并运行XAMPP: http://www.apachefriends.org/en/xampp.html
推荐文章
- 移动一个文件到服务器上的另一个文件夹
- Laravel中使用雄辩的ORM进行批量插入
- PHP 5.4调用时引用传递-容易修复可用吗?
- 格式化字节到千字节,兆字节,千兆字节
- 如何在PHP中获得变量名作为字符串?
- 用“+”(数组联合运算符)合并两个数组如何工作?
- Laravel PHP命令未找到
- 如何修复从源代码安装PHP时未发现xml2-config的错误?
- 在PHP中对动态变量名使用大括号
- 如何从对象数组中通过对象属性找到条目?
- 如何从关联数组中删除键及其值?
- PHP字符串中的花括号
- PHP -如何最好地确定当前调用是否来自CLI或web服务器?
- 无法打开流:没有这样的文件或目录
- 在php中生成一个随机密码