# Should we add php-fpm for each Virtual Host or in Global Configuration?

**URL:** <https://www.ruby-forum.com/t/should-we-add-php-fpm-for-each-virtual-host-or-in-global-configuration/242975>\
**Category:** NGINX\
**Created:** [August 12, 2015, 4:38am UTC](https://www.ruby-forum.com/t/should-we-add-php-fpm-for-each-virtual-host-or-in-global-configuration/242975 "2015-08-12T04:38:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sadaf\_N](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/858c86/32.png) [@Sadaf\_N](https://www.ruby-forum.com/u/Sadaf_N)\
**Post date:** [August 12, 2015, 4:38am UTC](https://www.ruby-forum.com/t/should-we-add-php-fpm-for-each-virtual-host-or-in-global-configuration/242975/1 "2015-08-12T04:38:05Z")

</div>

This is my configuration for my Virtual Host. I am not sure, but is this  
the  
ideal way of defining things ?

For every domain / sub-domain, i’m adding a location ~/.php directive.  
Should i add it in the global nginx.conf itself instead of specifying  
individually for each domain i add ?

Sample Configuration :-

server {  
listen 80;  
server\_name [example.com](http://example.com);

location / {  
root /var/www/example.com;  
index index.php;

```
}

```

location ~ .php$ {  
root /var/www/example.com/;  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
# fastcgi\_read\_timeout 30000;  
# fastcgi\_param SCRIPT\_FILENAME $fastcgi\_script\_name;  
fastcgi\_param SCRIPT\_FILENAME $request\_filename;  
include fastcgi\_params;  
}

server {  
listen 80;  
server\_name [www.example.net](http://www.example.net);

location / {  
root /var/www/example.net/;  
index index.php;

```
}

```

location ~ .php$ {  
root /var/www/example.net/;  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
# fastcgi\_read\_timeout 30000;  
# fastcgi\_param SCRIPT\_FILENAME $fastcgi\_script\_name;  
fastcgi\_param SCRIPT\_FILENAME $request\_filename;  
include fastcgi\_params;  
}

Posted at Nginx Forum:

> **[Should we add php-fpm for each Virtual Host or in Global Configuration ?](https://forum.nginx.org/read.php?2,260943,260943#msg-260943)**
>
> This is my configuration for my Virtual Host. I am not sure, but is this the ideal way of defining things ? For every domain / sub-domain, i'm adding a location ~/.php directive. Should i add it in the global nginx.conf itself instead of specifying...

---

<div class="post-metadata">

**Author:** ![sunzeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/87869e/32.png) [@sunzeal](https://www.ruby-forum.com/u/sunzeal)\
**Post date:** [August 12, 2015, 10:21am UTC](https://www.ruby-forum.com/t/should-we-add-php-fpm-for-each-virtual-host-or-in-global-configuration/242975/2 "2015-08-12T10:21:06Z")

</div>

Please see  
[http://nginx.org/en/docs/http/ngx\_http\_core\_module.html#location](http://nginx.org/en/docs/http/ngx_http_core_module.html#location)

location should be in a server or location context .So you cannot define  
it  
outside of all the server context’s.

One thing you can do is define a single location block for php and  
include  
it in every server context which will save you the trouble of adding it  
everytime.

But note that in real life you may need to change the fastcgi\_pass to  
different pools defined in php-fpm to separate php process based on user  
etc.
