15

Apache lets you set php.ini values for virtual hosts with the php_value directive.

Does nginx have something similar? Is there another way to set the include_path on a per-site basis?

2 Answers 2

27

Now, it is possible to do this way:

fastcgi_param  PHP_VALUE  "include_path=/my/include/path";

More information here: http://bugs.php.net/bug.php?id=51595

Using this technique to set php values, I have successfully set different "error_log" locations for multiple virtual hosts.

Thanks, PHP and NginX guys!

Sign up to request clarification or add additional context in comments.

4 Comments

That is awesome! So much better!
This is not a good way to go. I did this and changed in one vhost and it added these settings globally, completely breaking other vhosts.
As mentioned above, I set this in a server block on Nginx and it set it globally. Keep in mind if you want to use this that you will need to set the value for each host individually before making live
As others have commented, this value gets passed to the child PHP process and persists for that child process even for other virtual hosts. This means that other requests handled by that child will have this set, but requests handled by a different child will NOT have this set (what a nightmare). You could have all of your nginx confs set this value as a solution, but it's not a great solution. Also worth noting - if you're running multiple versions of PHP on the same server, this will only affect the version that this nginx conf invokes.
1

Sean, php_value and php_admin_value will not work with nginx. This is a limitation of php-cgi and not nginx.

You can work around this by starting multiple instances of PHP and passing in a custom php.ini like so:

php-cgi -c /path/to/php.ini

You can also set the include path explicitly in your PHP code like so:

$paths = array(
    PATH_PROJECT . 'lib/',
    PATH_PROJECT . 'lib/Doctrine/lib',
    PATH_PROJECT . 'application/doctrine/mappers/',
    PATH_PROJECT . 'application/lib',
    PATH_PROJECT . 'application/modules/',
    PATH_PROJECT . 'lib/classes',
    PATH_PROJECT . 'application/lib/reports/',
    get_include_path()
);

set_include_path(implode(PATH_SEPARATOR, $paths));
unset($paths);

2 Comments

Thanks! I also found this link forum.slicehost.com/comments.php?DiscussionID=3087 - setting it using php itself isn't feasible because of the way the project is set up (no front controller).
I switched to the newer answer

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.