2012-09-02 49 views

回答

110

Python Web服務器將您的PHP文件發送到瀏覽器的原因很可能是因爲它未配置或無法處理PHP文件。見https://serverfault.com/questions/338394/how-to-run-php-with-simplehttpserver

PHP 5.4有一個built-in webserver。你可以從這樣的命令行調用它:

php [options] -S <addr>:<port> [-t docroot] 

C:\Users\Gordon>php -S 127.0.0.1:80 -t . 
PHP 5.4.0 Development Server started at Sun Sep 02 14:20:28 2012 
Listening on 127.0.0.1:80 
Document root is C:\Users\Gordon 
Press Ctrl-C to quit. 

請注意,如果你省略-t PHP將使用當前工作目錄。

+0

@戈登我正在嘗試[w3schools示例](http://www.w3schools.com/php/showphp.asp?filename=demo_intro)使用這個,但沒有出現。我正在OSX中運行php系列。任何想法有什麼不對? – geotheory

+0

@geotheory請定義「無」。文檔根目錄是否設置爲您的文件所在的路徑? – Gordon

+0

我'cd'到文件夾並運行'php -S 127.0.0.1:8000'。在瀏覽器中打開「http:// localhost:8000 /」或「http://127.0.0.1:8000 /」時,該文件夾中的網頁「index.html」(使用w3school代碼)爲空。然而'console.log'消息確實在瀏覽器中通過。 – geotheory

相關問題