determine home directory?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • lawpoop

    determine home directory?

    I'm working on a PHP site and I have my database password file behind
    the server root directory.

    I can reference the password file by include("../
    database_passwo rd.inc.php"), but I would like to make the code more
    portable and not have this relative path reference. Is there a way I
    can know for certain what the home directory is called?

    As i'm developing this project in version control, I sometimes
    checkout a development branch. I want to interact with this branch, so
    I put it in its own directory under the web root directory. E. g.
    /home/user/website-root
    hosts the site, and
    /home/user/website-root/development-branch
    is where I'm testing my development.

    Of course, this breaks the relative path reference in the development
    branch.

    I could set up another parallel site, e.g.
    /home/user/development-webhost-root/
    and that would properly reference the password file, but I'd rather
    just have my checkout under the web root. That way my code is more
    portable, and I could deploy it

    I could make a configuration file where I specify the reference, but
    that adds an extra step when I do a checkout or export from source
    control -- I need to copy in my local configuration file. It would be
    great if I could have a "zero-configuration" app ( provided that the
    password file already exists in the home directory).

    I could try to figure out the home directory from the script path, but
    that is based on the assumptions of the directory layout that this
    particular hosting provider is using. If we deploy on another host, I
    would have to have this "just work".

    If could do something like include($_HOME . "/password.inc.ph p"); that
    would make things so much simpler. Is this possible?






  • =?UTF-8?B?SXbDoW4gU8OhbmNoZXogT3J0ZWdh?=

    #2
    Re: determine home directory?

    lawpoop wrote:
    I can reference the password file by
    include("../database_passwo rd.inc.php"), but I would like to make the code
    more portable and not have this relative path reference.
    Pardon me - you want to make the code more portable by NOT using relative
    paths?
    Is there a way I can know for certain what the home directory is called?
    Yeah, it's always called "~".

    --
    ----------------------------------
    Iván Sánchez Ortega -ivan-algarroba-sanchezortega-punto-es-

    You will always get the greatest recognition for the job you least like.

    Comment

    • Rik Wasmus

      #3
      Re: determine home directory?

      On Wed, 22 Oct 2008 23:05:00 +0200, lawpoop <lawpoop@gmail. comwrote:
      I'm working on a PHP site and I have my database password file behind
      the server root directory.
      >
      I can reference the password file by include("../
      database_passwo rd.inc.php"), but I would like to make the code more
      portable and not have this relative path reference. Is there a way I
      can know for certain what the home directory is called?
      Dubious usage of 'home' directory. Home of a user, of document root? If
      the latter:

      echo realpath($_SERV ER['DOCUMENT_ROOT'].'/../');
      --
      Rik

      Comment

      • Jerry Stuckle

        #4
        Re: determine home directory?

        lawpoop wrote:
        I'm working on a PHP site and I have my database password file behind
        the server root directory.
        >
        I can reference the password file by include("../
        database_passwo rd.inc.php"), but I would like to make the code more
        portable and not have this relative path reference. Is there a way I
        can know for certain what the home directory is called?
        >
        As i'm developing this project in version control, I sometimes
        checkout a development branch. I want to interact with this branch, so
        I put it in its own directory under the web root directory. E. g.
        /home/user/website-root
        hosts the site, and
        /home/user/website-root/development-branch
        is where I'm testing my development.
        >
        Of course, this breaks the relative path reference in the development
        branch.
        >
        I could set up another parallel site, e.g.
        /home/user/development-webhost-root/
        and that would properly reference the password file, but I'd rather
        just have my checkout under the web root. That way my code is more
        portable, and I could deploy it
        >
        I could make a configuration file where I specify the reference, but
        that adds an extra step when I do a checkout or export from source
        control -- I need to copy in my local configuration file. It would be
        great if I could have a "zero-configuration" app ( provided that the
        password file already exists in the home directory).
        >
        I could try to figure out the home directory from the script path, but
        that is based on the assumptions of the directory layout that this
        particular hosting provider is using. If we deploy on another host, I
        would have to have this "just work".
        >
        If could do something like include($_HOME . "/password.inc.ph p"); that
        would make things so much simpler. Is this possible?
        >
        >
        >
        >
        >
        >
        >
        $_SERVER['DOCUMENT_ROOT'] always contains the root directory of the web
        server. So you can access your file by
        $_SERVER['DOCUMENT_ROOT'] . '/../password.inc.ph p'.

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • lawpoop

          #5
          Re: determine home directory?

          On Oct 22, 7:18 pm, "Rik Wasmus" <luiheidsgoe... @hotmail.comwro te:
          Dubious usage of 'home' directory. Home of a user, of document root? If  
          the latter:
          >
          echo realpath($_SERV ER['DOCUMENT_ROOT'].'/../');

          Thanks for replying, Rik. What would you say is the best practice in
          this case? Using a config file?

          Comment

          • lawpoop

            #6
            Re: determine home directory?

            On Oct 22, 5:27 pm, Iván Sánchez Ortega <ivansanchez-...@rroba-
            escomposlinux.-.punto.-.orgwrote:
            >
            Pardon me - you want to make the code more portable by NOT using relative
            paths?
            In this case, yes. If you want to have a password stored in a file,
            but don't want the webserver to serve it, where would you put it, and
            how would you reference it? The added wrinkle is that you want to be
            able to install the php files in any directory under the web root, so
            you can't just say "../" -- you could be three directories under the
            web root, in which case the password file would be going in a
            publically served directory, presumably with other things in that
            directory already.
            >
            Is there a way I can know for certain what the home directory is called?
            >
            Yeah, it's always called "~".
            That works in the shells, but PHP doesn't apparently seem to know it:

            Warning: dir(~) [function.dir]: failed to open dir: No such file or
            directory

            Warning: dir(~/) [function.dir]: failed to open dir: No such file or
            directory

            Comment

            • lawpoop

              #7
              Re: determine home directory?

              On Oct 23, 12:09 am, Jerry Stuckle <jstuck...@attg lobal.netwrote:
              >
              $_SERVER['DOCUMENT_ROOT'] always contains the root directory of the web
              server.  So you can access your file by
              $_SERVER['DOCUMENT_ROOT'] . '/../password.inc.ph p'.
              >
              Thanks, Jerry. That's what I'm looking for!

              Comment

              Working...