2

I have 2 Macs whose general configuration I want to keep sync'd. For Apache and PHP, I store the conf files (httpd.conf and php.ini, respectively) in my Dropbox (~/Dropbox/config) and use symlinks to reference the shared from from the expected location.

Similarly, I share a couple of code bases in the same way. The physical files are located in ~/Dropbox/Development and linked to from ~/Development/. Now I need to share a library of utility classes and I can't figure out how to do that. The problem is that every directory in play sits within my home directory and my username is different on each machine. On one, it's ~/rwilkerson and it's ~/rob on the other.

How can I get my php.ini to resolve this? In my httpd.conf, I've done so by using environmental variables. For example, in a virtual host config file, I can set my web root to /Users/${SUDO_USER}/path/to/webroot. Since I use sudo to restart Apache (sudo apachectl restart), the environment variable evaluates to the proper username on whichever machine I'm on.

As far as I can tell, I can't use variables in my php.ini in a similar way. I thought that if I simply included both paths in my include_path, PHP would simply ignore the one that doesn't exist on a given machine, but that doesn't appear to be the case. My shared libraries will only be included if the correct path appears before the incorrect path.

I can't find any resource that spells out the nuances of how the include_path directive works, so I can't find any way around this apparent limitation. Anyone have any ideas?

Answer:

I ended up using StasM's solution #1 below. In my httpd.conf file (also shared), I added:

php_value include_path "/opt/local/lib/php:${HOME}/Dropbox/Development/lib/php/classes"

Doing that overrode any value in php.ini and worked beautifully.

2 Answers 2

1

include_path should ignore directories that do not exist. But besides that, you could do one of:

  1. Using httpd.conf to set your include_path via php_value directive
  2. If you run 5.3, using user_ini.filename
  3. Use auto_prepend_file to include a script that would calculate correct include path and set it with set_include_path() before each other script.
Sign up to request clarification or add additional context in comments.

3 Comments

I sort of assumed that include_path would ignore non-existent directories too, but that doesn't seem to be the case. Since you've confirmed, though, I'll do some further testing on that. Maybe I just didn't do a deep enough check. The httpd.conf idea is a good one, though. Not sure why I didn't think of that, but is there a way to have php_value include_path append the include path rather than overwrite it?
Yeah, that just doesn't seem to work. If I have /Users/rwilkerson/Dropbox/dev/lib/php/classes before /Users/rob/Dropbox/dev/lib/php/classes in my include_path (on the machine whose home directory is /Users/rob, the classes don't load. If I switch the order, they do.
This looks like a bug, maybe you want to submit issue with reproduction to bugs.php.net?
1

i also develop on several machines (all macs) and the easiest way for me to keep everything in sync was git, dropbox, and zend_config.

I have a parent git directory, /git and then each project each /git/projecta /git/projectb. This way you're not dealing with issues of $HOME or ~/

Any changes i do i push to dropbox and it syncs across all machines in real time.

With zend_config i have a config file for each project that i usually store in /etc/projecta.ini That will point to external libraries, db params, etc.

As far as the shared libraries, i try to keep each of my projects to have all their dependencies. Each project is application, html/public, library. And the library folder would have pear, zend, etc, propel.

As far as the include_path problem why not store that in a common directory across all your machines. /usr/local/lib/php for all your libraries and then symlink it to dropbox and do the same with all your projects. Then in your application set the include_path to /usr/local/lib/php or set that in your php.ini.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.