我的/var/www folder
中有以下php文件(try.php)。我在操作一台mac。
$html = "testing print";
$handle = printer_open();
printer_set_option($handle, PRINTER_MODE, "RAW");
printer_write($handle, $html);
printer_close($handle);
我安装了apache和php。如果我执行命令。
apachectl -version
我得到
Server version: Apache/2.2.26 (Unix)
Server built: Dec 10 2013 22:09:38
类似地为php版本执行,我得到
PHP 5.4.30 (cli) (built: Jul 29 2014 23:43:29)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
我使用以下命令重新启动服务器。
sudo apachectl restart
该命令在控制台上返回,不打印任何内容。之后我点击了网址。
http://localhost/try.php
这给了我一个404错误。
在此服务器上找不到请求的URL/try.php。
我还授予了/var/www
文件夹的读取、写入和执行权限。
你知道我犯了什么错误吗。
http.conf文件中的文档根配置如下。
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
首先,您应该找到文档根。
通过在shell中运行下面的命令,您应该获得apache配置文件的路径:
/usr/sbin/apache2 -V | grep SERVER_CONFIG_FILE
然后选择您最喜欢的编辑器,并在其中搜索DocumentRoot
参数。默认情况下,DocumentRoot
定义公共数据的路径。该文件夹内的任何内容都可以被服务器外的其他人看到。
有关更多信息,我建议阅读apache文档
将文件放入/var/www/html文件夹