PHP with FPM on Gentoo

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...
php-fpm.conf > Loading...
emerge --info php nginx > Loading...

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

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:

Hello,

On Tue, 3 Apr 2012 04:02:14 -0400 (EDT)
“locojohn” [email protected] 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

Rainer D. Wrote:

Am Tue, 3 Apr 2012 12:48:21 +0200
schrieb Silvio S. [email protected]:

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:

Hello,

On Tue, 3 Apr 2012 12:56:02 +0200
Rainer D. [email protected] 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

Hello,

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

It were nice.

Regards
Silvio

Am Tue, 3 Apr 2012 12:48:21 +0200
schrieb Silvio S. [email protected]:

Hello,

On Tue, 3 Apr 2012 04:02:14 -0400 (EDT)
“locojohn” [email protected] 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

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

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:

Hello,

On Wed, 04 Apr 2012 08:30:18 +0200
Ole Markus W. [email protected] 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