SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: Server paths

  1. #1
    SitePoint Wizard ryanhellyer's Avatar
    Join Date
    Oct 2006
    Location
    New Zealand
    Posts
    2,323
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Server paths

    At the risk of looking a total idiot I'm going to post an abridged version of a ticket I filed with my webhost today after switching accounts. I know I'm doing something wrong, but I have no idea what.

    My host has responded (see below) with an answer, which I'm sure is correct, but no solution (which is fine as it's not really their job, not that it's yours either but I'm going to ask anyway ).


    ... Things seem to be working fine, except none of my server paths are working correctly On my previous accounts, I could simply use $_SERVER[\'DOCUMENT_ROOT\'] in PHP to find the root of my domain. However it is now pointing to /usr/local/apache/htdocs/ rather than my public_html folder. I tried appending public_html to my paths but that isn't working either.

    The following URL contains this script <?php require (\'license.txt\'); ?> .... http://174.132.170.155/~ryan/temp.php .... which works

    The following URL contains this script <?php require ($_SERVER[\'DOCUMENT_ROOT\'].\'/license.txt\'); ?> .... http://174.132.170.155/~ryan/temp2.php .... which doesn\'t work

    Any ideas what on earth I'm doing wrong? This is driving me nuts.
    ...

    The reason for this problem is due to your accessing the site from . http://174.132.170.155/~ryan/ and since server = 174.132.170.155 the document root is /use/local/apache/htdocs now if you were accessing this from http://ryansdomain.com/temp.php server = ryansdomain.com document root /home/ryan/public_html


    This is driving me batty. I don't want to point my domain at the server just so that I can set it up. I should be able to do it just from the IP but I have no idea how

  2. #2
    SitePoint Evangelist simshaun's Avatar
    Join Date
    Apr 2008
    Location
    North Carolina
    Posts
    438
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try
    PHP Code:
    <?php require (dirname(__FILE__) . '/license.txt'); ?>
    and see if that works. (I have no idea if it will.)

  3. #3
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2008
    Posts
    5,757
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    That variable is dependant upon the webserver configuration.

    I used to think that document_root variable made things easier, but I feel relative filepaths are far less dependant upon things out of your control, like this. It's also much easier if you need to move an application into another directory, as filesystem paths will still work. You can still construct an absolute filesystem path if you like and pass it around as a constant or variable. construct it in a config file.

  4. #4
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by simshaun View Post
    PHP Code:
    dirname(__FILE__
    This.

    Define a constant in one of your config or bootstrap files, and then use the constant throughout your application.
    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •