开发者

Setting include_path in a shared php.ini file

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜