By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,203 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,203 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.php 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
Jul 17 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"Dave Smithz" <SPAM FREE WORLD> wrote in message news:42********@news1.homechoice.co.uk...
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.php 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


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($_SERVER['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
Jul 17 '05 #2

P: n/a
On Tue, 8 Feb 2005 01:41:27 -0000, Dave Smithz <SPAM FREE WORLD> wrote:
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.php 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

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.
Jul 17 '05 #3

P: n/a
"Dave Smithz" <SPAM FREE WORLD> writes:
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:


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/
Jul 17 '05 #4

P: n/a
"Jerry Sievers" <je***@jerrysievers.com> wrote in message
news:m3************@prod01.jerrysievers.com...

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


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
Jul 17 '05 #5

P: n/a
"Dave Smithz" <SPAM FREE WORLD> writes:
"Jerry Sievers" <je***@jerrysievers.com> wrote in message
news:m3************@prod01.jerrysievers.com...

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
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?


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.

Do remember that generally the code is on shared hosting packages so I do
not have full control of the webserver.
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.

Kind regards,

Dave


--
-------------------------------------------------------------------------------
Jerry Sievers 305 854-3001 (home) WWW ECommerce Consultant
305 321-1144 (mobile http://www.JerrySievers.com/
Jul 17 '05 #6

P: n/a
The other replied were expired, how did you accomplish this? Curious

Written by "Dave Smithz" on 2/7/05 8:41p:
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.php 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


--

Belmin Fernandez

Visit: http://www.belminfernandez.com/homepage
Email: belminf at gmail period com
Jul 17 '05 #7

P: n/a

"Belmin" <an*******@nospam.com> wrote in message
news:1H********************@twister.nyc.rr.com...
The other replied were expired, how did you accomplish this? Curious


What do you mean by this? There were quite a few suggestions.
Jul 17 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.