/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] Doc Root Directory Confusion

  • 1. In my [B]php.ini[/B] (for Windows) file I have
  • [INDENT]doc_root = “Z:/WebRroot”
    include_path = “.;Z:WebRoot;Z:WebRootPHPClasses”[/INDENT]

  • 2.

    In the [B]Z:WebRoot[/B] directory, I have placed the file [B]WebSiteLocator.php[/B]

  • 3.

    In the file [B]SysInfo.php[/B] (located in directory [B]Z:NiK[/B]), I have the line:

    [code=php]require_once(‘WebSiteLocator.php’);[/code]

  • In [B]httpd.conf[/B], I have

    [FONT=”Courier New”][INDENT]Alias /nik “Z:/NiK”[/INDENT][/FONT]

    as this directory contains PHP and HTML files and is outside the PHP and Apache doc roots

  • 4. When I run a PHP script ([B]afile.php[/B]) in [B]Z:NiK[/B] that includes [B]SysInfo.php[/B] (that is, I enter [url]http://localhost/nik/afile.php[/url]), I get the following messages:
  • [INDENT][B]Warning[/B]: [FONT=”Courier New”]require_once(WEBSITELOCATOR.PHP)[/FONT] [function.require-once.html]: failed to open stream: No such file or directory in [B]Z:NiKSysInfo.php[/B] on line 8

    [B]Fatal error[/B]: [FONT=”Courier New”]require_once()[/FONT] [function.require.html]: Failed opening required ‘WebSiteLocator.php’ (include_path=’PHPClasses;.;;PHPClasses;’) in [B]Z:NiKSysInfo.php[/B] on line 8
    [/INDENT]
    Note that [B]Z:NiK[/B] is a virtual directory to the HTTP (Apache) server

  • 5. I modified the script in item 3 to be:
  • [code=php]
    echo “realpath ==> “.realpath(‘/’);
    require_once(‘WebSiteLocator.php’)
    [/code]

    and before the error message, I get

    [INDENT]
    realpath ==> Z:
    [/INDENT]
    Why is it not the following??

    [INDENT] realpath ==> Z:WebRoot[/INDENT]

    to post a comment
    PHP

    3 Comments(s)

    Copy linkTweet thisAlerts:
    @Jarrod1937Nov 02.2010 — Not sure if this is the cause of your problem, but doesn't windows only support the use of for directories, not / as you have for things like your php.ini doc root?
    Copy linkTweet thisAlerts:
    @NogDogNov 02.2010 — I'd strongly suggest making use of the $_SERVER['DOCUMENT_ROOT'] super-global, and not having to worry about the real web server path within your PHP script, since it may change.

    [code=php]
    include $_SERVER['DOCUMENT_ROOT'] . DIRECTORY_SEPARATOR . 'WebSiteLocator.php';
    [/code]

    You can get away with using "/" instead of the DIRECTORY_SEPARATOR constant, as PHP will automatically figure out whether to use "/" or "" based on the OS, but it *might* be slightly more efficient to use the constant in some cases.
    Copy linkTweet thisAlerts:
    @senisevenauthorNov 02.2010 — I trried

    doc_root = Z:WebRoot

    instead of doc_root = Z:/WebRoot in php.ini. Did not work.

    I used NogDog's solution, and it did work.

    My use of realpath() PHP function was intended as a debugging tool.

    Thanks Jarrod1937 and NogDog.
    ×

    Success!

    Help @seniseven spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.27,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...