我在正确配置MAMP apache服务器时遇到问题。问题如下:变量$ _SERVER [' DOCUMENT_ROOT']始终为空。
在我已配置的httpd.conf中
DocumentRoot "/Users/<user>/workspace"
<Directory "/Users/<user>/workspace">
Options All
AllowOverride All
Order allow,deny
Allow from all
XSendFilePath "/Users/<user>/workspace"
</Directory>
这是我的vhost
<VirtualHost *:80>
ServerName myApp.dev
ServerAlias *.myApp.dev
ServerAdmin info@myApp.dev
DocumentRoot "/Users/<user>/workspace/myApp"
LogLevel debug
ErrorLog "/Users/<user>/workspace/myApp/rest/application/logs/myApp.dev-error_log"
CustomLog "/Users/<user>/workspace/myApp/rest/application/logs/myApp.dev-access_log" common
<Directory "/Users/<user>/workspace/myApp">
Options Indexes FollowSymLinks
AllowOverride All
Allow from all
</Directory>
</VirtualHost>
当我的var_dump变量
var_dump($_SERVER['DOCUMENT_ROOT']);
die();
结果是
string(0) ""
为了获得文档根值,我还需要做些什么?如果您需要任何其他信息,请告诉我,我会提供。谢谢!
答案 0 :(得分:1)
问题是因为我在运行php trough终端!如果您print_r($_SERVER)
,您会看到$_SERVER['DOCUMENT_ROOT']
未设置!
如果我在浏览器中打印$_SERVER['DOCUMENT_ROOT']
,我会看到正确的路径