Solved

Working with PHP Absolute Path differences between production server and MAMP development server

Posted on 2014-01-05
3
782 Views
Last Modified: 2014-01-09
I'm running MAMP for development work in PHP, and am looking for an efficient way to write my includes so that they work properly on both the development and production server when they differ in file structure.  

To illustrate:

My absolute path on my production server is /web/something/someplace/web/site/content/include.php

My absolute path on the development server is
/Applications/MAMP/htdocs/site/content/include.php

How do most people do this in an efficient way without having to rewrite the paths when going from development to production for everything above the site folder?
0
Comment
Question by:DaveNegron
  • 2
3 Comments
 
LVL 24

Accepted Solution

by:
mankowitz earned 500 total points
ID: 39757851
I usually use seomthing like this:

if (!@include '/path/to/production/server') 
     require('/path/to/test/server/');

Open in new window


Another option is to make your files relative to document root, if possible:

require_once($_SERVER['DOCUMENT_ROOT'].'/relative/path/tofile');
0
 

Author Comment

by:DaveNegron
ID: 39757893
@mankowitz Along these same lines, what do you use when the file is above the document root?
0
 
LVL 24

Expert Comment

by:mankowitz
ID: 39758385
To be honest, I usually do not keep documents outside the document root. I understand that this is necessary sometimes, but I find it easier to keep individual copies. In those cases, however where I can't keep the document inside the document root, then I use the first option above.
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

In this article we discuss how to recover the missing Outlook 2011 for Mac data like Emails and Contacts manually.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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