473,390 Members | 1,065 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,390 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 2138

"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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.