newbie: website's root directory

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

    newbie: website's root directory

    Hello,
    I am learning PHP5. I need to obtain my website's root directory in .php
    code. I tried the code:
    echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
    but it displays:
    __DIR__/var/www/html
    although my_website is installed in user's
    directory: /home/robert/public_html/my_website.
    I don't know why and how to obtain root directory.
    Please help.
    Thanks!
  • =?ISO-8859-1?Q?=22=C1lvaro_G=2E_Vicario=22?=

    #2
    Re: newbie: website's root directory

    Jivanmukta escribió:
    I am learning PHP5. I need to obtain my website's root directory in .php
    code. I tried the code:
    echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
    but it displays:
    __DIR__/var/www/html
    although my_website is installed in user's
    directory: /home/robert/public_html/my_website.
    The __DIR__ constant was added in PHP 5.3.0, which as fas as I know is
    expected to be released in the next months.

    PHP is a popular general-purpose scripting language that powers everything from your blog to the most popular websites in the world.


    Your problem is that your ISP has configured the web server in such a
    way that the DOCUMENT_ROOT value is unreliable. You'll need to calculate
    it yourself. A simple dirname(__FILE_ _) in your site root will do the trick.



    --
    -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    -- Mi sitio sobre programación web: http://bits.demogracia.com
    -- Mi web de humor al baño María: http://www.demogracia.com
    --

    Comment

    • Jerry Stuckle

      #3
      Re: newbie: website's root directory

      Jivanmukta wrote:
      Hello,
      I am learning PHP5. I need to obtain my website's root directory in .php
      code. I tried the code:
      echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
      but it displays:
      __DIR__/var/www/html
      although my_website is installed in user's
      directory: /home/robert/public_html/my_website.
      I don't know why and how to obtain root directory.
      Please help.
      Thanks!
      echo $_SERVER['DOCUMENT_ROOT'] should display the root. What webserver
      are you running (i.e. Apache, IIS, etc.), and are you running as a
      module or a cgi?

      If you're not sure, you can find this (and a lot of other information)
      with phpinfo(), i.e. a file containing only:

      <?php
      phpinfo();
      ?>

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

      Comment

      • sheldonlg

        #4
        Re: newbie: website's root directory

        Jivanmukta wrote:
        Hello,
        I am learning PHP5. I need to obtain my website's root directory in .php
        code. I tried the code:
        echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
        but it displays:
        __DIR__/var/www/html
        although my_website is installed in user's
        directory: /home/robert/public_html/my_website.
        I don't know why and how to obtain root directory.
        Please help.
        Thanks!
        Do

        echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];

        Comment

        • sheldonlg

          #5
          Re: newbie: website's root directory

          sheldonlg wrote:
          Jivanmukta wrote:
          >Hello,
          >I am learning PHP5. I need to obtain my website's root directory in .php
          >code. I tried the code:
          > echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
          >but it displays:
          > __DIR__/var/www/html
          >although my_website is installed in user's
          >directory: /home/robert/public_html/my_website.
          >I don't know why and how to obtain root directory.
          >Please help.
          >Thanks!
          >
          Do
          >
          echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
          Scratch that. Just do:

          echo $_SERVER['DOCUMENT_ROOT'];

          Comment

          • 703designs

            #6
            Re: newbie: website's root directory

            On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote :
            sheldonlg wrote:
            Jivanmukta wrote:
            Hello,
            I am learning PHP5. I need to obtain my website's root directory in .php
            code. I tried the code:
                    echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
            but it displays:
                    __DIR__/var/www/html
            although my_website is installed in user's
            directory: /home/robert/public_html/my_website.
            I don't know why and how to obtain root directory.
            Please help.
            Thanks!
            >
            Do
            >
            echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
            >
            Scratch that.  Just do:
            >
            echo $_SERVER['DOCUMENT_ROOT'];
            Many shared hosts pull crap like this. As soon as I can figure out how
            to configure a Debian LAMP setup, all of my sites will be on my Linode
            account. On these type of shared hosts, "/" can be unreliable if not
            handled with care.

            Thomas

            Comment

            • Jerry Stuckle

              #7
              Re: newbie: website's root directory

              703designs wrote:
              On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote :
              >sheldonlg wrote:
              >>Jivanmukta wrote:
              >>>Hello,
              >>>I am learning PHP5. I need to obtain my website's root directory in .php
              >>>code. I tried the code:
              >>> echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
              >>>but it displays:
              >>> __DIR__/var/www/html
              >>>although my_website is installed in user's
              >>>directory: /home/robert/public_html/my_website.
              >>>I don't know why and how to obtain root directory.
              >>>Please help.
              >>>Thanks!
              >>Do
              >>echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
              >Scratch that. Just do:
              >>
              >echo $_SERVER['DOCUMENT_ROOT'];
              >
              Many shared hosts pull crap like this. As soon as I can figure out how
              to configure a Debian LAMP setup, all of my sites will be on my Linode
              account. On these type of shared hosts, "/" can be unreliable if not
              handled with care.
              >
              Thomas
              Thomas,

              Don't install LAMP. Everything you need on Debian is available via
              aptitude or apt_get. They're not necessarily the absolute latest and
              greatest - but they're fairly recent and stable.

              Debian already comes with MySQL installed (in fact, you want to use that
              version because Debian also uses MySQL). And it will make
              administration much easier.

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

              Comment

              • 703designs

                #8
                Re: newbie: website's root directory

                On Nov 10, 1:18 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                703designs wrote:
                On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote :
                sheldonlg wrote:
                >Jivanmukta wrote:
                >>Hello,
                >>I am learning PHP5. I need to obtain my website's root directory in ..php
                >>code. I tried the code:
                >>        echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
                >>but it displays:
                >>        __DIR__/var/www/html
                >>although my_website is installed in user's
                >>directory: /home/robert/public_html/my_website.
                >>I don't know why and how to obtain root directory.
                >>Please help.
                >>Thanks!
                >Do
                >echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
                Scratch that.  Just do:
                >
                echo $_SERVER['DOCUMENT_ROOT'];
                >
                Many shared hosts pull crap like this. As soon as I can figure out how
                to configure a Debian LAMP setup, all of my sites will be on my Linode
                account. On these type of shared hosts, "/" can be unreliable if not
                handled with care.
                >
                Thomas
                >
                Thomas,
                >
                Don't install LAMP.  Everything you need on Debian is available via
                aptitude or apt_get.  They're not necessarily the absolute latest and
                greatest - but they're fairly recent and stable.
                >
                Debian already comes with MySQL installed (in fact, you want to use that
                version because Debian also uses MySQL).  And it will make
                administration much easier.
                >
                --
                =============== ===
                Remove the "x" from my email address
                Jerry Stuckle
                JDS Computer Training Corp.
                jstuck...@attgl obal.net
                =============== ===
                Thanks, I know how Debian works, after all (it's my favorite OS). I
                actually have no trouble running LAMP itself (having used a Debian
                LAMP server locally for a year), it's getting the mail services and
                DNS that gives me fits. I may check out that book put out by No Starch
                once they update it to Etch (it was stuck on Sarge last I checked). At
                this point, they may as well update it for Lenny.

                Thomas

                Comment

                • Jerry Stuckle

                  #9
                  [OT] Re: newbie: website's root directory

                  703designs wrote:
                  On Nov 10, 1:18 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                  >703designs wrote:
                  >>On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote :
                  >>>sheldonlg wrote:
                  >>>>Jivanmukt a wrote:
                  >>>>>Hello,
                  >>>>>I am learning PHP5. I need to obtain my website's root directory in .php
                  >>>>>code. I tried the code:
                  >>>>> echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
                  >>>>>but it displays:
                  >>>>> __DIR__/var/www/html
                  >>>>>although my_website is installed in user's
                  >>>>>director y: /home/robert/public_html/my_website.
                  >>>>>I don't know why and how to obtain root directory.
                  >>>>>Please help.
                  >>>>>Thanks!
                  >>>>Do
                  >>>>echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
                  >>>Scratch that. Just do:
                  >>>echo $_SERVER['DOCUMENT_ROOT'];
                  >>Many shared hosts pull crap like this. As soon as I can figure out how
                  >>to configure a Debian LAMP setup, all of my sites will be on my Linode
                  >>account. On these type of shared hosts, "/" can be unreliable if not
                  >>handled with care.
                  >>Thomas
                  >Thomas,
                  >>
                  >Don't install LAMP. Everything you need on Debian is available via
                  >aptitude or apt_get. They're not necessarily the absolute latest and
                  >greatest - but they're fairly recent and stable.
                  >>
                  >Debian already comes with MySQL installed (in fact, you want to use that
                  >version because Debian also uses MySQL). And it will make
                  >administrati on much easier.
                  >>
                  >--
                  >============== ====
                  >Remove the "x" from my email address
                  >Jerry Stuckle
                  >JDS Computer Training Corp.
                  >jstuck...@attg lobal.net
                  >============== ====
                  >
                  Thanks, I know how Debian works, after all (it's my favorite OS). I
                  actually have no trouble running LAMP itself (having used a Debian
                  LAMP server locally for a year), it's getting the mail services and
                  DNS that gives me fits. I may check out that book put out by No Starch
                  once they update it to Etch (it was stuck on Sarge last I checked). At
                  this point, they may as well update it for Lenny.
                  >
                  Thomas
                  Exim does pretty with a little work. It can be hard to configure for
                  special circumstances, but I've found it works OK.

                  With that said - I've heavily customized my Exim installations for spam
                  filtering, aliases via MySQL database, etc. But even without that, it
                  worked with minimal setup.

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

                  Comment

                  • 703designs

                    #10
                    Re: newbie: website's root directory

                    On Nov 10, 2:52 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                    703designs wrote:
                    On Nov 10, 1:18 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                    703designs wrote:
                    >On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote :
                    >>sheldonlg wrote:
                    >>>Jivanmukta wrote:
                    >>>>Hello,
                    >>>>I am learning PHP5. I need to obtain my website's root directory in .php
                    >>>>code. I tried the code:
                    >>>>        echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
                    >>>>but it displays:
                    >>>>        __DIR__/var/www/html
                    >>>>although my_website is installed in user's
                    >>>>directory : /home/robert/public_html/my_website.
                    >>>>I don't know why and how to obtain root directory.
                    >>>>Please help.
                    >>>>Thanks!
                    >>>Do
                    >>>echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
                    >>Scratch that.  Just do:
                    >>echo $_SERVER['DOCUMENT_ROOT'];
                    >Many shared hosts pull crap like this. As soon as I can figure out how
                    >to configure a Debian LAMP setup, all of my sites will be on my Linode
                    >account. On these type of shared hosts, "/" can be unreliable if not
                    >handled with care.
                    >Thomas
                    Thomas,
                    >
                    Don't install LAMP.  Everything you need on Debian is available via
                    aptitude or apt_get.  They're not necessarily the absolute latest and
                    greatest - but they're fairly recent and stable.
                    >
                    Debian already comes with MySQL installed (in fact, you want to use that
                    version because Debian also uses MySQL).  And it will make
                    administration much easier.
                    >
                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstuck...@attgl obal.net
                    =============== ===
                    >
                    Thanks, I know how Debian works, after all (it's my favorite OS). I
                    actually have no trouble running LAMP itself (having used a Debian
                    LAMP server locally for a year), it's getting the mail services and
                    DNS that gives me fits. I may check out that book put out by No Starch
                    once they update it to Etch (it was stuck on Sarge last I checked). At
                    this point, they may as well update it for Lenny.
                    >
                    Thomas
                    >
                    Exim does pretty with a little work.  It can be hard to configure for
                    special circumstances, but I've found it works OK.
                    >
                    With that said - I've heavily customized my Exim installations for spam
                    filtering, aliases via MySQL database, etc.  But even without that, it
                    worked with minimal setup.
                    >
                    --
                    =============== ===
                    Remove the "x" from my email address
                    Jerry Stuckle
                    JDS Computer Training Corp.
                    jstuck...@attgl obal.net
                    =============== ===
                    Just curious, what led you to choose Exim over SendMail? Is SendMail
                    the CVS of mail servers?

                    Thanks,
                    Thomas

                    Comment

                    • Jerry Stuckle

                      #11
                      Re: newbie: website's root directory

                      703designs wrote:
                      On Nov 10, 2:52 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                      >703designs wrote:
                      >>On Nov 10, 1:18 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                      >>>703designs wrote:
                      >>>>On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote :
                      >>>>>sheldonl g wrote:
                      >>>>>>Jivanmukt a wrote:
                      >>>>>>>Hello,
                      >>>>>>>I am learning PHP5. I need to obtain my website's root directory in .php
                      >>>>>>>code. I tried the code:
                      >>>>>>> echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
                      >>>>>>>but it displays:
                      >>>>>>> __DIR__/var/www/html
                      >>>>>>>althou gh my_website is installed in user's
                      >>>>>>>director y: /home/robert/public_html/my_website.
                      >>>>>>>I don't know why and how to obtain root directory.
                      >>>>>>>Please help.
                      >>>>>>>Thanks !
                      >>>>>>Do
                      >>>>>>echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
                      >>>>>Scratch that. Just do:
                      >>>>>echo $_SERVER['DOCUMENT_ROOT'];
                      >>>>Many shared hosts pull crap like this. As soon as I can figure out how
                      >>>>to configure a Debian LAMP setup, all of my sites will be on my Linode
                      >>>>account. On these type of shared hosts, "/" can be unreliable if not
                      >>>>handled with care.
                      >>>>Thomas
                      >>>Thomas,
                      >>>Don't install LAMP. Everything you need on Debian is available via
                      >>>aptitude or apt_get. They're not necessarily the absolute latest and
                      >>>greatest - but they're fairly recent and stable.
                      >>>Debian already comes with MySQL installed (in fact, you want to use that
                      >>>version because Debian also uses MySQL). And it will make
                      >>>administrati on much easier.
                      >>>--
                      >>>============ ======
                      >>>Remove the "x" from my email address
                      >>>Jerry Stuckle
                      >>>JDS Computer Training Corp.
                      >>>jstuck...@at tglobal.net
                      >>>============ ======
                      >>Thanks, I know how Debian works, after all (it's my favorite OS). I
                      >>actually have no trouble running LAMP itself (having used a Debian
                      >>LAMP server locally for a year), it's getting the mail services and
                      >>DNS that gives me fits. I may check out that book put out by No Starch
                      >>once they update it to Etch (it was stuck on Sarge last I checked). At
                      >>this point, they may as well update it for Lenny.
                      >>Thomas
                      >Exim does pretty with a little work. It can be hard to configure for
                      >special circumstances, but I've found it works OK.
                      >>
                      >With that said - I've heavily customized my Exim installations for spam
                      >filtering, aliases via MySQL database, etc. But even without that, it
                      >worked with minimal setup.
                      >>
                      >--
                      >============== ====
                      >Remove the "x" from my email address
                      >Jerry Stuckle
                      >JDS Computer Training Corp.
                      >jstuck...@attg lobal.net
                      >============== ====
                      >
                      Just curious, what led you to choose Exim over SendMail? Is SendMail
                      the CVS of mail servers?
                      >
                      Thanks,
                      Thomas
                      It's much easier to configure, for one thing. SendMail is a real bear!
                      It's difficult even to configure it to handle all of your incoming
                      mail without accidentally becoming a spam relay.

                      Of course, so is Exim for more complicated things - but at least for the
                      majority of the sites it's pretty easy to configure. And the basic
                      configuration is done by a command line script - all you need to do is
                      fill in the blanks and it configures Exim for your site.



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

                      Comment

                      • 703designs

                        #12
                        Re: newbie: website's root directory

                        On Nov 10, 5:23 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                        703designs wrote:
                        On Nov 10, 2:52 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                        703designs wrote:
                        >On Nov 10, 1:18 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
                        >>703designs wrote:
                        >>>On Nov 10, 1:04 pm, sheldonlg <sheldonlgwrote :
                        >>>>sheldonlg wrote:
                        >>>>>Jivanmuk ta wrote:
                        >>>>>>Hello,
                        >>>>>>I am learning PHP5. I need to obtain my website's root directoryin .php
                        >>>>>>code. I tried the code:
                        >>>>>>        echo __DIR__, $_SERVER['DOCUMENT_ROOT'];
                        >>>>>>but it displays:
                        >>>>>>        __DIR__/var/www/html
                        >>>>>>althoug h my_website is installed in user's
                        >>>>>>directory : /home/robert/public_html/my_website.
                        >>>>>>I don't know why and how to obtain root directory.
                        >>>>>>Please help.
                        >>>>>>Thanks!
                        >>>>>Do
                        >>>>>echo __DIR__ . $_SERVER['DOCUMENT_ROOT'];
                        >>>>Scratch that.  Just do:
                        >>>>echo $_SERVER['DOCUMENT_ROOT'];
                        >>>Many shared hosts pull crap like this. As soon as I can figure out how
                        >>>to configure a Debian LAMP setup, all of my sites will be on my Linode
                        >>>account. On these type of shared hosts, "/" can be unreliable if not
                        >>>handled with care.
                        >>>Thomas
                        >>Thomas,
                        >>Don't install LAMP.  Everything you need on Debian is available via
                        >>aptitude or apt_get.  They're not necessarily the absolute latest and
                        >>greatest - but they're fairly recent and stable.
                        >>Debian already comes with MySQL installed (in fact, you want to use that
                        >>version because Debian also uses MySQL).  And it will make
                        >>administratio n much easier.
                        >>--
                        >>============= =====
                        >>Remove the "x" from my email address
                        >>Jerry Stuckle
                        >>JDS Computer Training Corp.
                        >>jstuck...@att global.net
                        >>============= =====
                        >Thanks, I know how Debian works, after all (it's my favorite OS). I
                        >actually have no trouble running LAMP itself (having used a Debian
                        >LAMP server locally for a year), it's getting the mail services and
                        >DNS that gives me fits. I may check out that book put out by No Starch
                        >once they update it to Etch (it was stuck on Sarge last I checked). At
                        >this point, they may as well update it for Lenny.
                        >Thomas
                        Exim does pretty with a little work.  It can be hard to configure for
                        special circumstances, but I've found it works OK.
                        >
                        With that said - I've heavily customized my Exim installations for spam
                        filtering, aliases via MySQL database, etc.  But even without that, it
                        worked with minimal setup.
                        >
                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstuck...@attgl obal.net
                        =============== ===
                        >
                        Just curious, what led you to choose Exim over SendMail? Is SendMail
                        the CVS of mail servers?
                        >
                        Thanks,
                        Thomas
                        >
                        It's much easier to configure, for one thing.  SendMail is a real bear!
                          It's difficult even to configure it to handle all of your incoming
                        mail without accidentally becoming a spam relay.
                        >
                        Of course, so is Exim for more complicated things - but at least for the
                        majority of the sites it's pretty easy to configure.  And the basic
                        configuration is done by a command line script - all you need to do is
                        fill in the blanks and it configures Exim for your site.
                        >
                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstuck...@attgl obal.net
                        =============== ===
                        Sounds like exactly what I'm looking for, as I'm not exactly building
                        Gmail here. SendMail was driving me up the wall.

                        Thanks!

                        Thomas

                        Comment

                        Working...