Test Server to Live server - best way of handling different file paths in scripts?

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

    Test Server to Live server - best way of handling different file paths in scripts?

    Hi There,

    I have taken over someone else's PHP code and am quite new to PHP. I made
    some changes and have implemented them to a live environment fine so far.

    However, I now want to setup a test environment. All the PHP scripts start
    with a few lines of:

    require_once "library file at specific location on server"

    and when I move them from the test location to live location I have to
    manually apply the changes to each script to reflect the different paths for
    each server.

    I was thinking of writing a small script that is contained within the same
    folder as any folder that contains scripts that actually calls another
    require for that server .

    E.g.
    Have script do_something.ph p which I am developing regularly.
    On live server it starts with
    require_once "/home/live/phplib/library.php";
    On test server
    require_once "/home/test/phplib/library.php";

    Currently I apply a manual change this (via global change or whatever) when
    moving from Test to Live
    However, I might just change all requires to:
    require_once "./require.php";

    And then have a server specific version of require.php that contains the
    necessary requires for the particular server on which it resides.

    This way I can just change all the scripts to just require the require.php
    file in the same folder as itself. The actual PHP scripts where I do most of
    my updates need no changes whether on live or test servers.

    I just wanted to know if there was a better way of doing it then this. I
    know nothing about directives in PHP or if there was a way of determining
    the current server name and then calling different require commands
    appropriately.

    Any more elegant suggestions for handling this are welcome.

    Dave


  • WindAndWaves

    #2
    Re: Test Server to Live server - best way of handling different file paths in scripts?


    "Dave Smithz" <SPAM FREE WORLD> wrote in message news:420818c5$1 @news1.homechoi ce.co.uk...[color=blue]
    > Hi There,
    >
    > I have taken over someone else's PHP code and am quite new to PHP. I made
    > some changes and have implemented them to a live environment fine so far.
    >
    > However, I now want to setup a test environment. All the PHP scripts start
    > with a few lines of:
    >
    > require_once "library file at specific location on server"
    >
    > and when I move them from the test location to live location I have to
    > manually apply the changes to each script to reflect the different paths for
    > each server.
    >
    > I was thinking of writing a small script that is contained within the same
    > folder as any folder that contains scripts that actually calls another
    > require for that server .
    >
    > E.g.
    > Have script do_something.ph p which I am developing regularly.
    > On live server it starts with
    > require_once "/home/live/phplib/library.php";
    > On test server
    > require_once "/home/test/phplib/library.php";
    >
    > Currently I apply a manual change this (via global change or whatever) when
    > moving from Test to Live
    > However, I might just change all requires to:
    > require_once "./require.php";
    >
    > And then have a server specific version of require.php that contains the
    > necessary requires for the particular server on which it resides.
    >
    > This way I can just change all the scripts to just require the require.php
    > file in the same folder as itself. The actual PHP scripts where I do most of
    > my updates need no changes whether on live or test servers.
    >
    > I just wanted to know if there was a better way of doing it then this. I
    > know nothing about directives in PHP or if there was a way of determining
    > the current server name and then calling different require commands
    > appropriately.
    >
    > Any more elegant suggestions for handling this are welcome.
    >
    > Dave
    >
    >[/color]

    Hi Dave

    I did what you are doing recently (i have no comp background though).

    I am sorry, I do not have time to read your whole story. However, this may be of use:

    $mylocation =
    'http://'.$_SERVER['HTTP_HOST'].dirname($_SERV ER['PHP_SELF']).'/myurl.php';

    I just tested everything straight on the server (the site is not life yet) - I do not even have php installed locally at all - but
    it worked great for me.

    Later

    - Nicolaas


    Comment

    • Kelvin Mackay

      #3
      Re: Test Server to Live server - best way of handling different file paths in scripts?

      On Tue, 8 Feb 2005 01:41:27 -0000, Dave Smithz <SPAM FREE WORLD> wrote:
      [color=blue]
      > Hi There,
      >
      > I have taken over someone else's PHP code and am quite new to PHP. I made
      > some changes and have implemented them to a live environment fine so far.
      >
      > However, I now want to setup a test environment. All the PHP scripts
      > start
      > with a few lines of:
      >
      > require_once "library file at specific location on server"
      >
      > and when I move them from the test location to live location I have to
      > manually apply the changes to each script to reflect the different paths
      > for
      > each server.
      >
      > I was thinking of writing a small script that is contained within the
      > same
      > folder as any folder that contains scripts that actually calls another
      > require for that server .
      >
      > E.g.
      > Have script do_something.ph p which I am developing regularly.
      > On live server it starts with
      > require_once "/home/live/phplib/library.php";
      > On test server
      > require_once "/home/test/phplib/library.php";
      >
      > Currently I apply a manual change this (via global change or whatever)
      > when
      > moving from Test to Live
      > However, I might just change all requires to:
      > require_once "./require.php";
      >
      > And then have a server specific version of require.php that contains the
      > necessary requires for the particular server on which it resides.
      >
      > This way I can just change all the scripts to just require the
      > require.php
      > file in the same folder as itself. The actual PHP scripts where I do
      > most of
      > my updates need no changes whether on live or test servers.
      >
      > I just wanted to know if there was a better way of doing it then this. I
      > know nothing about directives in PHP or if there was a way of determining
      > the current server name and then calling different require commands
      > appropriately.
      >
      > Any more elegant suggestions for handling this are welcome.
      >
      > Dave
      >
      >[/color]


      If your testing environment is linux, have you considered using symbolic
      links to replicate the remote server's directory structure?
      I recently did this for a client's site and found it very effective. No
      more worrying about remote files using the local server's paths for one
      thing. In the long term, though, this probably isn't the best option.

      A more common solution, which is usually more practical, is to include a
      common configuration file in all scripts that contains a 'site_root'
      variable, set to an appropriate value for the server it's on, then
      changing all require_once to use it instead of a hard coded path.
      Example:
      [config.inc.php]
      $site_root = '/home/live/phplib/';

      [some_file.php]
      require_once $site_root . 'library.php';

      This is much better because if at some stage in the future you have to
      move the live site to a new server with a different directory structure,
      you only have to change your configuration file.

      Comment

      • Jerry Sievers

        #4
        Re: Test Server to Live server - best way of handling different file paths in scripts?

        "Dave Smithz" <SPAM FREE WORLD> writes:
        [color=blue]
        > Hi There,
        >
        > I have taken over someone else's PHP code and am quite new to PHP. I made
        > some changes and have implemented them to a live environment fine so far.
        >
        > However, I now want to setup a test environment. All the PHP scripts start
        > with a few lines of:[/color]

        Better to use

        php_value include_path ".:/home/someusername/www/phplib" (example)

        Maybe this is of no help for an existing, not very well thought out
        system of scripts though since you'd have to edit each one of them to
        change the existing hard coded path names.

        I pretty much NEVER use absolute paths in require/include statements
        but rather pull from one or more defined include dirs.

        Doing so and we can move an entire code base by changing only one line
        the top level .htaccess file in DOC_ROOT.

        HTH

        --
        -------------------------------------------------------------------------------
        Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
        305 321-1144 (mobile http://www.JerrySievers.com/

        Comment

        • Dave Smithz

          #5
          Re: Test Server to Live server - best way of handling different file paths in scripts?

          "Jerry Sievers" <jerry@jerrysie vers.com> wrote in message
          news:m3fz07ks9d .fsf@prod01.jer rysievers.com.. .[color=blue]
          >
          > Better to use
          >
          > php_value include_path ".:/home/someusername/www/phplib" (example)
          >
          > Maybe this is of no help for an existing, not very well thought out
          > system of scripts though since you'd have to edit each one of them to
          > change the existing hard coded path names.
          >
          > I pretty much NEVER use absolute paths in require/include statements
          > but rather pull from one or more defined include dirs.
          >
          > Doing so and we can move an entire code base by changing only one line
          > the top level .htaccess file in DOC_ROOT.
          >
          > HTH[/color]

          Thanks for all the responses. Your described benefits of this method appeal
          but can you explain a little more. Are php_vale and include_path specific
          php commands.
          Isn't what you have shown very similar to what I said about having all my
          current files do a require_once of a file in the same folder?

          Do remember that generally the code is on shared hosting packages so I do
          not have full control of the webserver.

          Kind regards,

          Dave


          Comment

          • Jerry Sievers

            #6
            Re: Test Server to Live server - best way of handling different file paths in scripts?

            "Dave Smithz" <SPAM FREE WORLD> writes:
            [color=blue]
            > "Jerry Sievers" <jerry@jerrysie vers.com> wrote in message
            > news:m3fz07ks9d .fsf@prod01.jer rysievers.com.. .[color=green]
            > >
            > > Better to use
            > >
            > > php_value include_path ".:/home/someusername/www/phplib" (example)
            > >
            > > Maybe this is of no help for an existing, not very well thought out
            > > system of scripts though since you'd have to edit each one of them to
            > > change the existing hard coded path names.
            > >
            > > I pretty much NEVER use absolute paths in require/include statements
            > > but rather pull from one or more defined include dirs.
            > >
            > > Doing so and we can move an entire code base by changing only one line
            > > the top level .htaccess file in DOC_ROOT.
            > >
            > > HTH[/color]
            >
            > Thanks for all the responses. Your described benefits of this method appeal
            > but can you explain a little more. Are php_vale and include_path specific
            > php commands.
            > Isn't what you have shown very similar to what I said about having all my
            > current files do a require_once of a file in the same folder?[/color]

            Pretty much the same result but I think the php config setting in
            ..htaccess even easier. That's up to you.

            A single point administration for this include path value is all we
            need to achieve and there is more than one way to do it.
            [color=blue]
            >
            > Do remember that generally the code is on shared hosting packages so I do
            > not have full control of the webserver.[/color]

            Right. The php_value setting goes in .htaccess and unless the web
            server is configured to not even allow a virtual host administrator to
            change PHP settings, it should work.

            Test it a little is about all I can suggest.
            [color=blue]
            >
            > Kind regards,
            >
            > Dave
            >
            >[/color]

            --
            -------------------------------------------------------------------------------
            Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
            305 321-1144 (mobile http://www.JerrySievers.com/

            Comment

            • Belmin

              #7
              Re: Test Server to Live server - best way of handling different filepaths in scripts?

              The other replied were expired, how did you accomplish this? Curious

              Written by "Dave Smithz" on 2/7/05 8:41p:[color=blue]
              > Hi There,
              >
              > I have taken over someone else's PHP code and am quite new to PHP. I made
              > some changes and have implemented them to a live environment fine so far.
              >
              > However, I now want to setup a test environment. All the PHP scripts start
              > with a few lines of:
              >
              > require_once "library file at specific location on server"
              >
              > and when I move them from the test location to live location I have to
              > manually apply the changes to each script to reflect the different paths for
              > each server.
              >
              > I was thinking of writing a small script that is contained within the same
              > folder as any folder that contains scripts that actually calls another
              > require for that server .
              >
              > E.g.
              > Have script do_something.ph p which I am developing regularly.
              > On live server it starts with
              > require_once "/home/live/phplib/library.php";
              > On test server
              > require_once "/home/test/phplib/library.php";
              >
              > Currently I apply a manual change this (via global change or whatever) when
              > moving from Test to Live
              > However, I might just change all requires to:
              > require_once "./require.php";
              >
              > And then have a server specific version of require.php that contains the
              > necessary requires for the particular server on which it resides.
              >
              > This way I can just change all the scripts to just require the require.php
              > file in the same folder as itself. The actual PHP scripts where I do most of
              > my updates need no changes whether on live or test servers.
              >
              > I just wanted to know if there was a better way of doing it then this. I
              > know nothing about directives in PHP or if there was a way of determining
              > the current server name and then calling different require commands
              > appropriately.
              >
              > Any more elegant suggestions for handling this are welcome.
              >
              > Dave
              >
              >[/color]

              --

              Belmin Fernandez

              Visit: http://www.belminfernandez.com/homepage
              Email: belminf at gmail period com

              Comment

              • Dave Smithz

                #8
                Re: Test Server to Live server - best way of handling different file paths in scripts?


                "Belmin" <anonymous@nosp am.com> wrote in message
                news:1HCPd.7154 $qn2.1266626@tw ister.nyc.rr.co m...[color=blue]
                > The other replied were expired, how did you accomplish this? Curious[/color]

                What do you mean by this? There were quite a few suggestions.


                Comment

                Working...