Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Best Way To Use Same Files for Live and Local

Posted on 2013-05-13
7
Medium Priority
?
206 Views
Last Modified: 2013-06-27
Hi,

I want to use the same files whether they are on my live server or on my test server.

I have a config file /includes/config.php that I load into each file

<?php require $_SERVER['DOCUMENT_ROOT'].'../includes/config.php';?>

When this file is loaded, it contains the paths for either local or live, Its just the trick of getting it to load.

On my test server the doc_root is C:\xampp\htdocs (but then in a difft folder /testsite)
On my live server the doc root is /home/live/live.net
What is the simplest way for me to achieve this with code I DON'T have to change if I were to load this site on any server?
0
Comment
Question by:Computer Guy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39161193
Run this function and look at the output: getcwd() and then read the documentation about Directory Functions.  You may find that the use of DOCUMENT_ROOT is not an advantage, but an impediment to developing a universal, correct path!
0
 
LVL 6

Expert Comment

by:BurundiLapp
ID: 39161365
We use DOCUMENT_ROOT but we define it in a seperate file that is loaded using the prepend command in php.ini, the file is unique to the server not the website but it is one of only two files that need editing on the move from test to live, or in your case from local to live.

This is on IIS internally but on Apache externally and it works ok.
0
 
LVL 3

Author Comment

by:Computer Guy
ID: 39161384
This is Apache. Does not have to be DOCUMENT_ROOT, I'm totally open to suggestions.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39161407
What do you see from this script?  Please post the output from both the local and live versions.
<?php var_dump(getcwd());

Open in new window

0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39162595
Generally speaking, I try to build all my applications to use relative paths, so I generally avoid using DOCUMENT_ROOT or any specified "top folder" at all.

If I ever need to rely on an absolute path (not frequently), I use dirname(__FILE__) to get the current full path to the file that is executing that code, then I step up as necessary to get to the application's root folder.

So for example, my PHP code looks like:
include("../modules/dosomething.inc.php");
require("includes/library.php");

and in HTML:
<script type="text/javascript" src="js/jquery.js"></script>
<img src="images/logo.gif">

It makes my applications VERY portable and makes it easy to establish testing and dev environments. It might be too late in this application (not sure how much code uses absolute paths), but I figured I would add my 2 cents.
0
 
LVL 3

Author Comment

by:Computer Guy
ID: 39215900
I'm still working on this.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39249881
How's it going? Did you run this one-line script yet?
<?php var_dump(getcwd());

Open in new window

0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question