Solved

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

Posted on 2014-01-05
3
774 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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

These days socially coordinated efforts have turned into a critical requirement for enterprises.
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

773 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