# PHP with FPM on Gentoo

**URL:** <https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511>\
**Category:** NGINX\
**Created:** [April 3, 2012, 12:12am UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511 "2012-04-03T00:12:52Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [April 3, 2012, 12:12am UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/1 "2012-04-03T00:12:52Z")

</div>

Hello,

i try run Nginx with PHP-FPM under Gentoo. Under my FreeBSD Rootserver  
it run without any problems but under Gentoo want not run.

nginx.conf \> [Loading...](http://nopaste.info/72a40e9c5e.html)  
php-fpm.conf \> [Loading...](http://nopaste.info/94a9de62d5.html)  
emerge --info php nginx \> [Loading...](http://nopaste.info/225b12e106.html)

The last change in config is:

server {  
listen 80 default;  
server\_name localhost;  
access\_log /var/log/nginx/localhost.access\_log main;  
error\_log /var/log/nginx/localhost.error\_log debug;  
root /var/www/localhost/htdocs;  
location ~ (.\*).php$ {  
include fastcgi.conf;  
fastcgi\_pass 127.0.0.1:9000;  
fastcgi\_index index.php;  
fastcgi\_param SCRIPT\_FILENAME  
/var/www/localhost/htdocs$fastcgi\_script\_name;  
}  
}

The last Logs which i has:

\<acces\_log\>  
192.168.0.20 - - [02/Apr/2012:17:59:05 +0200] “GET / HTTP/1.1” 200 633  
“-” “Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML, like Gecko)  
Chrome/18.0.1025.142 Safari/535.19” “-”  
192.168.0.20 - - [02/Apr/2012:17:59:05 +0200] “GET /favicon.ico  
HTTP/1.1” 200 1650 “-” “Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19  
(KHTML, like Gecko) Chrome/18.0.1025.142 Safari/535.19” “-”  
192.168.0.20 - - [02/Apr/2012:17:59:21 +0200] “GET /info.php HTTP/1.1”  
200 289 “-” “Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.19 (KHTML,  
like Gecko) Chrome/18.0.1025.142 Safari/535.19” “0.47”  
192.168.0.20 - - [02/Apr/2012:17:59:24 +0200] “-” 400 0 “-” “-” “-”  
\</acces\_log\>

\<error\_log\>  
2012/04/02 17:59:24 [info] 21288#0: \*4 client closed prematurely  
connection while reading client request line, client: 192.168.0.20,  
server: localhost  
\</error\_log\>

I really not understand where is my mistake. Has someone a idea?

Regards  
Silvio

---

<div class="post-metadata">

**Author:** ![silviosilva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@silviosilva](https://www.ruby-forum.com/u/silviosilva)\
**Post date:** [April 3, 2012, 10:02am UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/2 "2012-04-03T10:02:52Z")

</div>

Hi,

Do you actually get any content, apart from errors in nginx error\_log?  
The message “client closed prematurely connection while reading client  
request line, client: …” shouldn’t be a problem itself.

“Some modern browsers tend to open 2 tcp connections to server from  
start, and if you are loading a single static file - one of them remains  
unused. The browser eventually closes it without sending any request,  
and this causes the above message in logs.” - Maxim D…

I can see from your access\_log that requests are processed normally and  
responses are OK (code 200) for all your files including PHP files  
(request: /info.php).

You can also use sockets for fastcgi connections, but that’s a matter of  
preference and probably won’t solve your issue, which I do not fully  
understand yet.

shell:

mkdir -p /var/run/fastcgi/php-fpm.sock

php-fpm.conf:

;listen = 127.0.0.1:9000  
;listen.allowed\_clients = 127.0.0.1  
listen = /var/run/fastcgi/php-fpm.sock  
listen.owner = nginx  
listen.group = nginx

nginx.conf:

location .php$ {  
include fastcgi\_params;  
fastcgi\_pass unix:/var/run/fastcgi/php-fpm.sock;  
}

Andrejs

Posted at Nginx Forum:

> **[Re: PHP with FPM on Gentoo](https://forum.nginx.org/read.php?2,224804,224821#msg-224821)**
>
> Hello, i try run Nginx with PHP-FPM under Gentoo. Under my FreeBSD Rootserver it run without any problems but under Gentoo want not run. nginx.conf \> http://nopaste.info/72a40e9c5e.html php-fpm.conf \> http://nopaste.info/94a9de62d5.html emerge...

---

<div class="post-metadata">

**Author:** ![silviosilva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@silviosilva](https://www.ruby-forum.com/u/silviosilva)\
**Post date:** [April 3, 2012, 12:48pm UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/3 "2012-04-03T12:48:07Z")

</div>

Hello,

On Tue, 3 Apr 2012 04:02:14 -0400 (EDT)  
“locojohn” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> nginx.conf:
> 
> location .php$ {  
> include fastcgi\_params;  
> fastcgi\_pass unix:/var/run/fastcgi/php-fpm.sock;  
> }

Thx for advice. But will not run. When i start nginx it come only

gentoo-desk ~ # /etc/init.d/nginx start

- Checking nginx’ configuration …  
nginx: [emerg] invalid host in upstream “/var/run/fastcgi/php-fpm.sock”  
in /etc/nginx/nginx.conf:35  
nginx: configuration file /etc/nginx/nginx.conf test failed  
nginx: [emerg] invalid host in upstream “/var/run/fastcgi/php-fpm.sock”  
in /etc/nginx/nginx.conf:35  
nginx: configuration file /etc/nginx/nginx.conf test failed
- failed, please correct errors above  
[!!]
- ERROR: nginx failed to start

\<error\_log\>  
2012/04/03 12:44:52 [emerg] 2062#0: invalid host in upstream  
“/var/run/fastcgi/php-fpm.sock” in /etc/nginx/nginx.conf:35  
2012/04/03 12:44:52 [emerg] 2063#0: invalid host in upstream  
“/var/run/fastcgi/php-fpm.sock” in /etc/nginx/nginx.conf:35  
2012/04/03 12:45:02 [emerg] 2073#0: invalid host in upstream  
“/var/run/fastcgi/php-fpm.sock” in /etc/nginx/nginx.conf:35  
2012/04/03 12:45:02 [emerg] 2074#0: invalid host in upstream  
“/var/run/fastcgi/php-fpm.sock” in /etc/nginx/nginx.conf:35  
\</error\_log\>

Mmh can it be that nginx and / or php not right build with emerge?

Regards  
Silvio

---

<div class="post-metadata">

**Author:** ![silviosilva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@silviosilva](https://www.ruby-forum.com/u/silviosilva)\
**Post date:** [April 3, 2012, 12:59pm UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/4 "2012-04-03T12:59:55Z")

</div>

## Rainer D. Wrote:

> Am Tue, 3 Apr 2012 12:48:21 +0200  
> schrieb Silvio S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > > mkdir -p /var/run/fastcgi/php-fpm.sock
> 
> Shouldn’t that only be:
> 
> mkdir -p /var/run/fastcgi/

Right, of course! My stupid mistake.

Andrejs

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,224804,224850#msg-224850](http://forum.nginx.org/read.php?2,224804,224850#msg-224850)

---

<div class="post-metadata">

**Author:** ![silviosilva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@silviosilva](https://www.ruby-forum.com/u/silviosilva)\
**Post date:** [April 3, 2012, 1:02pm UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/5 "2012-04-03T13:02:23Z")

</div>

Hello,

On Tue, 3 Apr 2012 12:56:02 +0200  
Rainer D. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Rainer

Thank u, yes thats right i have only run mkdir -p /var/run/fastcgi,  
that i know from freebsd. But it wont not run. When i run complete  
mkdir -p /var/run/fastcgi/php-fpm.sock it give mistakes have try both  
ways.

Regards  
Silvio

---

<div class="post-metadata">

**Author:** ![silviosilva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@silviosilva](https://www.ruby-forum.com/u/silviosilva)\
**Post date:** [April 3, 2012, 11:38pm UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/6 "2012-04-03T23:38:57Z")

</div>

Hello,

Could someone possibly provide me the USE flags available  
if someone has run Nginx, PHP and Fpm.

It were nice.

Regards  
Silvio

---

<div class="post-metadata">

**Author:** ![silviosilva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@silviosilva](https://www.ruby-forum.com/u/silviosilva)\
**Post date:** [April 3, 2012, 12:56pm UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/7 "2012-04-03T12:56:47Z")

</div>

Am Tue, 3 Apr 2012 12:48:21 +0200  
schrieb Silvio S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hello,
> 
> On Tue, 3 Apr 2012 04:02:14 -0400 (EDT)  
> “locojohn” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > mkdir -p /var/run/fastcgi/php-fpm.sock

Shouldn’t that only be:

mkdir -p /var/run/fastcgi/

though, on FreeBSD, I think this is created automatically.

Remove the php-fpm.sock directory.

Rainer

---

<div class="post-metadata">

**Author:** ![silviosilva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@silviosilva](https://www.ruby-forum.com/u/silviosilva)\
**Post date:** [April 4, 2012, 10:21pm UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/8 "2012-04-04T22:21:03Z")

</div>

Hello,

now i have build php and nginx from source direct, emerge --unmerge,  
have downloaded the sourcecode and compile it and same it run not.

Thats really crazy, what is this? Is this maybe with eselect profile  
list  
option? Because i use

gentoo-desk imap # eselect profile list  
Available profile symlink targets:  
[1] default/linux/x86/10.0  
[2] default/linux/x86/10.0/selinux  
[3] default/linux/x86/10.0/desktop \*  
[4] default/linux/x86/10.0/desktop/gnome  
[5] default/linux/x86/10.0/desktop/kde  
[6] default/linux/x86/10.0/developer  
[7] default/linux/x86/10.0/server  
[8] hardened/linux/x86  
[9] hardened/linux/x86/selinux

Is this maybe the mistake or where can be the error?

Regards  
Silvio

---

<div class="post-metadata">

**Author:** ![silviosilva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@silviosilva](https://www.ruby-forum.com/u/silviosilva)\
**Post date:** [April 4, 2012, 1:46pm UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/9 "2012-04-04T13:46:25Z")

</div>

## Silvio S. Wrote:

> Hello,
> 
> Could someone possibly provide me the USE flags  
> available  
> if someone has run Nginx, PHP and Fpm.

/etc/make.conf:

NGINX\_MODULES\_HTTP=“access autoindex browser charset   
empty\_gif fastcgi flv geoip gzip limit\_zone   
map proxy rewrite stub\_status upstream\_ip\_hash   
upload\_progress”

/etc/portage/package.use:

www-servers/nginx aio

dev-lang/php -\* fpm cli bcmath ssl ctype curl fileinfo filter ftp gd  
hash iconv json mysqlnd mysql mysqli nls pcntl pcre posix readline  
reflection session simplexml  
sharedmem spl sysvipc tokenizer truetype unicode xml zlib xmlreader  
xmlwriter

* * *

www-servers/nginx-1.1.18::x-portage USE=“aio http http-cache pcre ssl  
-debug -ipv6 -libatomic -pcre-jit -vim-syntax”  
NGINX\_MODULES\_HTTP=“access autoindex browser charset empty\_gif fastcgi  
flv geoip gzip limit\_zone map proxy rewrite stub\_status upload\_progress  
upstream\_ip\_hash -addition -auth\_basic -cache\_purge -dav -degradation  
-geo -gzip\_static -headers\_more -image\_filter -limit\_req -memcached -mp4  
-passenger -perl -push -random\_index -realip -referer -scgi -secure\_link  
-slowfs\_cache -split\_clients -ssi -sub -upload -userid -uwsgi -xslt”  
NGINX\_MODULES\_MAIL=“-imap -pop3 -smtp” 0 kB

dev-lang/php-5.3.10-r2 USE=“bcmath cli ctype curl fileinfo filter fpm  
ftp gd hash iconv json mysql mysqli mysqlnd nls pcntl posix readline  
session sharedmem simplexml ssl sysvipc tokenizer truetype unicode xml  
xmlreader xmlwriter zlib -apache2 -berkdb -bzip2 -calendar -cdb -cgi  
-cjk -crypt -curlwrappers -debug -doc -embed -enchant -exif -firebird  
-flatfile (-frontbase) -gdbm -gmp -imap -inifile -intl -iodbc -ipv6  
-kerberos -kolab -ldap -ldap-sasl -libedit -mhash -mssql  
-oci8-instant-client -odbc -pdo -phar -pic -postgres -qdbm -recode -snmp  
-soap -sockets -spell -sqlite -sqlite3 -suhosin (-sybase-ct) -threads  
-tidy -wddx -xmlrpc -xpm -xsl -zip” 0 kB

> Has set again the IPs, which permissions must habe Unix sockets?  
> Owner  
> is normal, nginx but chmod?

The socket file configured in php-fpm.conf should be readable and  
writeable by nginx. Naturally, if socket owner/group in php-fpm are set  
to nginx:nginx, nginx should work with php fpm over socket connection  
just fine.

One question: do you use selinux? Any specific Gentoo installation?  
Please send me your /etc/make.conf file.

Andrejs

Posted at Nginx Forum:  
[http://forum.nginx.org/read.php?2,224804,224931#msg-224931](http://forum.nginx.org/read.php?2,224804,224931#msg-224931)

---

<div class="post-metadata">

**Author:** ![silviosilva](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/5daacb/32.png) [@silviosilva](https://www.ruby-forum.com/u/silviosilva)\
**Post date:** [April 5, 2012, 4:47am UTC](https://www.ruby-forum.com/t/php-with-fpm-on-gentoo/218511/10 "2012-04-05T04:47:25Z")

</div>

Hello,

On Wed, 04 Apr 2012 08:30:18 +0200  
Ole Markus W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Did you see the Gentoo install instructions [1]?

Yes i have read.

> You only need the fpm USE flag enabled for php.  
> Nginx require NGINX\_MODULES\_HTTP=“fastcgi”

In PHP is activated and Nginx i have reinstalled yesterdays with fastcgi  
Flag.  
I use Google normaly before.

> With those set, fpm + nginx should work pretty much out of the box after  
> adding the fastcgi\_pass line to nginx.conf.

No work not pretty. On FreeBSD yes, on Gentoo nothing.

> TCP sockets are the easiest to configure. If you want to use unix  
> sockets, you have to make sure the file permissions are correct etc.

Has set again the IPs, which permissions must habe Unix sockets? Owner  
is normal, nginx but chmod?

Regards  
Silvio
