Custom php.ini for a virtual host

1,643 views
Skip to first unread message

Anoop Alias

unread,
Aug 13, 2008, 9:02:35 AM8/13/08
to highload-php-en
Hi,

Is there a way i can get a custom php.ini processed for each
virtualhost in nginx using php-fpm?

I am running nginx and pass php request to fastcgi (php-fpm managd)
server listening on port 9000.

One solution i have found is install another php-fpm and make it
listen on another port say 8000 with a different php.ini file loaded

Is there any better and elegant solution

Thanks in advance

--
Anoop P Alias
http://gnusys.net

Andrei Nigmatulin

unread,
Aug 13, 2008, 9:27:56 AM8/13/08
to highloa...@googlegroups.com
On Wednesday 13 August 2008 17:02, Anoop Alias wrote:
> Hi,
>
> Is there a way i can get a custom php.ini processed for each
> virtualhost in nginx using php-fpm?
>
> I am running nginx and pass php request to fastcgi (php-fpm managd)
> server listening on port 9000.
>
> One solution i have found is install another php-fpm and make it
> listen on another port say 8000 with a different php.ini file loaded
>
> Is there any better and elegant solution

It is impossible to specify different php.ini files for each virtual host.

However, you can leave common php.ini settings in the php.ini file, and
specify differences between virtual hosts like described here:

http://groups.google.com/group/highload-php-en/browse_thread/thread/2aa55858046fad17


--
Andrei Nigmatulin
GPG PUB KEY 6449830D

Now I lay me down to sleep(3)
Pray the OS my core to keep
If I die before I wake
Pray the Disk my core to take

mike

unread,
Aug 13, 2008, 1:42:15 PM8/13/08
to highloa...@googlegroups.com
On 8/13/08, Andrei Nigmatulin <andrei.n...@gmail.com> wrote:

> http://groups.google.com/group/highload-php-en/browse_thread/thread/2aa55858046fad17

It works like a charm.

I can set each fastcgi pool to have it's own error log (one pool per customer)

For the customers that need development logging, I can set
display_errors on for them. Otherwise since it's production systems I
set it to off in php.ini.

However in PHP 5.3 you'll be able to do some conditional type things
in php.ini as well so you could wait and do it then too. See here:

http://www.php.net/ini.sections

That actually might be a little more useful even so I can just define
some dev hosts, instead of having to define a separate fastcgi pool in
php-fpm so I can enable display_errors.

arteta

unread,
Aug 13, 2008, 5:57:49 PM8/13/08
to highload-php-en
> It is impossible to specify different php.ini files for each virtual host.
>
> However, you can leave common php.ini settings in the php.ini file, and
> specify differences between virtual hosts like described here:
>
> http://groups.google.com/group/highload-php-en/browse_thread/thread/2...
Hi,

I did not understand the change.

I have a vhost in nginx who does not have the cache turned on, for the
moment so I executed a 2 nd php-fpm with this:

xxx:/usr/local/php/etc# cat /etc/init.d/php-fpm2
#! /bin/sh
php_fpm_BIN=/usr/local/php/bin/php-cgi
php_fpm_CONF=/usr/local/php/etc/php-fpm2.conf
php_fpm_PID=/usr/local/php/logs/php-fpm2.pid
php_opts="--fpm-config $php_fpm_CONF"

and the php-fpm2.conf:
<value name="apc.enabled"> 0 </ value>

How in one php-fpm.conf put options for a vhost and not for another.

<workers>
<section name="pool">
...
<value name="php_defines">
<value name="apc.enabled">0</value>
...
</value>
...
</section>

<section name="pool">
...
<value name="php_defines">
<value name="apc.enabled">1</value>
...
</value>
...
</section>
</workers>

How <section with name="pool">, vhost will go to the conf 1 or 2 ?

Guillaume.

sorry for my English google:)



mike

unread,
Aug 13, 2008, 6:17:09 PM8/13/08
to highloa...@googlegroups.com
On 8/13/08, arteta <Artet...@gmail.com> wrote:

> How in one php-fpm.conf put options for a vhost and not for another.
>
> <workers>
> <section name="pool">
> ...
> <value name="php_defines">
> <value name="apc.enabled">0</value>
> ...
> </value>
> ...
> </section>
>
> <section name="pool">
> ...
> <value name="php_defines">
> <value name="apc.enabled">1</value>
> ...
> </value>
> ...
> </section>
> </workers>
>
> How <section with name="pool">, vhost will go to the conf 1 or 2 ?

You configure the webserver to send requests to the specific pool
which is listening on a specific TCP ip/port or a socket. That is
unique per pool. That is how you map your fastcgi requests to a
specific pool.

Andrei Nigmatulin

unread,
Aug 13, 2008, 6:27:56 PM8/13/08
to highloa...@googlegroups.com

Your nginx.conf should look like this:

server {
...
location ~ \.php$ {
...
fastcgi_pass 127.0.0.1:9000;
}
}

server {
...
location ~ \.php$ {
...
fastcgi_pass 127.0.0.1:8000;
}
}

Next, you need to put this line "apc.enabled=1" into php.ini.

The last step: configure two separate pools of workers in one php-fpm.conf:

<workers>
<section name="pool">
<value name="listen_address">127.0.0.1:8000</value>


...
<value name="php_defines">
<value name="apc.enabled">0</value>
...
</value>
...
</section>

<section name="pool">
<value name="listen_address">127.0.0.1:9000</value>
...
</section>
</workers>

The first pool of php-fastcgi workers will be listening on port 8000 and have
ini option apc.enabled == "0" (disabled).

The second one will be listening on port 9000 and have default "apc.enabled"
value from php.ini, which is "1" (enabled).

arteta

unread,
Aug 13, 2008, 7:02:57 PM8/13/08
to highload-php-en
Ok, I use this technique at the moment, I thought we could put
different values for vhosts in the configuration file. A delirium what
^ ^
Reply all
Reply to author
Forward
0 new messages