What is the right path for PHP includes on a Mac?
Posted
by skorned
on Stack Overflow
See other posts from Stack Overflow
or by skorned
Published on 2010-03-13T19:22:07Z
Indexed on
2010/03/13
19:25 UTC
Read the original article
Hit count: 226
Running Mac OS X 10.5.8, with PHP 5.2.11 Pre-installed. Using Coda 1.6.10.
I'm writing PHP files, and then preview them running from file, not server. This was working fine till I tried PHP includes. These don't work as a relative path, only as an absolute from the root of the drive.
Is there any way I can use statements like
include_once "common/header.php";
without specifying my entire file path like so :
include_once "/Volumes/Macintosh HD/Users/neil/Desktop/Website/ColoredLists_v1.0/common/base.php";
,where ColoredLists_v1.0 is the directory with all the website files in it. I tried solutions like prepending _SERVER[DOCUMENT_ROOT] or dirname(File) to the file paths, but that didn't work as the variables were not set. Is there any easy way to do this, or a configuration I can change so that it looks in a specific directory by default instead of looking at the drive root? Currently, echo_include_path shows .:
When I include this line at the start of the script, it works:
set_include_path('/Volumes/Macintosh HD/Users/neil/Desktop/Website/ColoredLists_v1.0');
However, if I want to do this for all my scripts, I can't seem to make the change permanent. Even after I edited the Unix include_path in my php.ini, it doesn't seem to work.
© Stack Overflow or respective owner