473,324 Members | 2,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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.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
7 2136

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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: William D. Gill | last post by:
I use a notebook (win 98) because of its portability. Unfortunately it is very slow. When I try to develop and test python cgi scripts I use Xitami as a local server, but with python, Xitami, and...
5
by: The Mighty Chaffinch | last post by:
I want to have 2 completely separate instances of my ASP/Access application running on the same web server. One will be a live production application, and the other part of a system test...
24
by: Lovely Angel | last post by:
Dear Friends Hope you doing great. I have recently shifted to a webhost which is Using Windows 2003 and IIS 6. Now my application was working fine earlier but now I am facing this problem ...
6
by: john_williams_800 | last post by:
Hi; I am writing an html page that will live on one server in an ms windows network, but access pictures from a directory on another ms windows server in the network. I know in html the...
4
by: Benne Smith | last post by:
In our company, i have three servers; 1) a development server (mine only - here i make daily changes and test my stuff) 2) a test server (for the users to test milestone builds - changes weekly)...
6
by: Pat Carden | last post by:
Hi, We need to allow webusers to upload a file on our website (on Server3, all servers run Server 2003, remotely hosted) and eventually save it on our SBS Server (Server2) which is not exposed...
27
by: Josh | last post by:
We have a program written in VB6 (over 100,000 lines of code and 230 UI screens) that we want to get out of VB and into a better language. The program is over 10 years old and has already been...
8
by: swell | last post by:
I would like to write a server with the low level API of python ( socket+select and/or socket+thread ) that allow me to register client and update them every X seconds ( could be the time, the...
6
by: sam | last post by:
Hi, I want to compile and test php script in my pc without using internet or web site which is online ? Do you have any idea about it? It is possible to do that ?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.