Using " / " for web root problem

Posted on 2012-09-17
Last Modified: 2012-09-23
I'm not sure what to google or what this is even called...  

*But*, in my local environment (I use MAMP), I can in both my php scripts and js scripts use:

include "/include/sample.php";

Open in new window

                                url: '/js/ajax.php',
                                data: {pc: $('input[name="pc"]').val()},
                                dataType: 'json',
                                type: 'post',
                                success: function(data) {

Open in new window

And it "knows" to look in the web root folder (/path/to/www/)

However, once I upload it, it uses "/" as the server root...  I'd like to change that behavior so that it's the same as it is locally...  My server runs CentOS.

I've looked at my php.ini file to see if I could figure something out there, but I'm not sure what to change (if anything...).  Two things possibly worth noting is that:

(1) safe mode is on
(2) open_basedir is set to none

Is there something I can change in my php.ini file, or a relevant setting the apache settings?  I'm not sure what to look for here... Hoping someone can point me in the right direction...
Question by:n00b0101
    LVL 82

    Expert Comment

    by:Dave Baldwin
    Note that 'safe mode' is going away as of PHP 5.4.   'open_basedir' is not affect by 'safe mode'.
    LVL 7

    Expert Comment

    If your web structure is :
    - Root (www)
    -- Includes
    -- js

    You don't need the / at the beginning of your include.
    LVL 82

    Accepted Solution

    The directory problem sounds like 'DocumentRoot' is not set properly.
    LVL 107

    Expert Comment

    by:Ray Paseur
    I think DaveBaldwin may be right about the DOCUMENT_ROOT issue.  You can use phpinfo(); to print out information about the environmental variables.

    You might also want to use the predefined PHP constant DIRECTORY_SEPARATOR instead of hand-coding a slash.  DIRECTORY_SEPARATOR will be context aware and correct no matter whether your script runs on Window, Linux or whatever.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Suggested Solutions

    It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
    In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    The viewer will learn how to count occurrences of each item in an array.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now