无法在localhost上运行test.php

时间:2015-08-18 19:43:50

标签: php apache localhost

所以我在我的本地Debian系统上安装了php5和apache2,并希望运行我的测试。我在/ var / www中有一个test.php,里面有这个:

<?php phpinfo(); ?>

我转到http://localhost,我看到了apache默认页面。一切都好。
我的问题是,我去了http://localhost/test.php,我得到了404.

我有一个高级时刻吗?

2 个答案:

答案 0 :(得分:1)

根据commanigy.com blog page首次运行命令:

ps -ef | grep apache

这个命令的结果将是这样的几行:

root      4053     1  0 06:26 ?        00:00:04 /usr/sbin/apache2 -k start

复制给定路径并运行以下命令:

/usr/sbin/apache2 -V

在结果中找到以下行:

 -D SERVER_CONFIG_FILE="conf/httpd.conf"

如果您喜欢我 - 开头没有根元素/的相对路径,请找到该行:

 -D HTTPD_ROOT="/etc/httpd"

并加入这两个值。在我们的例子中将是:

/etc/httpd/conf/httpd.conf

现在使用vim编辑器查看此文件并搜索DocumentRoot设置。在我的文件中,它看起来像:

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/var/www/html"

现在将test.php复制到此文件夹并使用网络浏览器运行它。

答案 1 :(得分:0)

我猜你的服务器设置上不允许使用php文件扩展名。

尝试这样的事情可能有所帮助:

<IfModule mime_module>
    AddType text/html .php .phps
</IfModule>
相关问题