Search code examples
phpmacosapachemamp

Server document root variable is empty (Apache MAMP)


I'm having a problem with proper configuration of my MAMP apache server. Problem is following: variable $_SERVER['DOCUMENT_ROOT'] is always empty.

In my httpd.conf i have configured

DocumentRoot "/Users/<user>/workspace"
<Directory "/Users/<user>/workspace">    
    Options All
    AllowOverride All
    Order allow,deny
    Allow from all
    XSendFilePath "/Users/<user>/workspace"
</Directory>

This is my 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>

And when i var_dump variable

var_dump($_SERVER['DOCUMENT_ROOT']);
die();

result is

string(0) ""

What else do i need to do in order to get document root value printed out? If you need any additional informations, please let me know and i will provide. Thank you!


Solution

  • The problem was because I was running php trough terminal! If you print_r($_SERVER) you will see that $_SERVER['DOCUMENT_ROOT'] is not set!

    If I print $_SERVER['DOCUMENT_ROOT'] in browser i see proper path as it should be