Solved

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

Posted on 2014-01-05
3
815 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
[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
  • 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

WordPress Tutorial 4: Recommended Plugins

Now that you have WordPress installed, understand the interface, and know how to install new parts, let’s take a look at our recommended plugins.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
I was prompted to write this article after the recent World-Wide Ransomware outbreak. For years now, System Administrators around the world have used the excuse of "Waiting a Bit" before applying Security Patch Updates. This type of reasoning to me …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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 …

617 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