0

I'm using php-fpm over TCP, because Is my intention load balance it.

Should I have PHP files on every server?

Or can I store it at the web server (Lighttpd)? I'm receiving 404 Error when trying to request a simple php file. That file is stored at lighttpd server and the php-fpm is running on another machine.

It's my configuration at lighttpd:

server.modules += ( "mod_fastcgi" )
fastcgi.debug = 1


fastcgi.server += ( ".php" =>
        ((
                "host" => "10.5.0.3",
                "port" => "9000",
                "broken-scriptfilename" => "enable"
        ))
)

And the php-fpm pool config:

[www]
listen = 127.0.0.1:9000
user = www-data
group = www-data
pm = ondemand
pm.max_children = 5
pm.start_servers = 2
pm.process_idle_timeout = 10s;
pm.max_requests = 500

PHP-FPM log:

[13-Sep-2017 20:22:54] NOTICE: fpm is running, pid 1
[13-Sep-2017 20:22:54] NOTICE: ready to handle connections
10.5.0.2 -  13/Sep/2017:20:24:50 -0300 "GET /info.php" 404

And lighttpd log:

2017-09-13 20:24:50: (configfile-glue.c.615) 7 (uncached) result: false
2017-09-13 20:24:50: (response.c.350) -- splitting Request-URI
2017-09-13 20:24:50: (response.c.351) Request-URI     :  /info.php
2017-09-13 20:24:50: (response.c.352) URI-scheme      :  http
2017-09-13 20:24:50: (response.c.353) URI-authority   :  localhost
2017-09-13 20:24:50: (response.c.354) URI-path (raw)  :  /info.php
2017-09-13 20:24:50: (response.c.355) URI-path (clean):  /info.php
2017-09-13 20:24:50: (response.c.356) URI-query       :
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 1 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 2 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 3 (cached) result: true
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 4 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 5 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 6 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 7 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 1 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 2 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 3 (cached) result: true
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 4 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 5 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 6 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 7 (cached) result: false
2017-09-13 20:24:50: (mod_access.c.148) -- mod_access_uri_handler called
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 1 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 2 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 3 (cached) result: true
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 4 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 5 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 6 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 7 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 1 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 2 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 3 (cached) result: true
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 4 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 5 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 6 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 7 (cached) result: false
2017-09-13 20:24:50: (response.c.490) -- before doc_root
2017-09-13 20:24:50: (response.c.491) Doc-Root     : /var/www
2017-09-13 20:24:50: (response.c.492) Rel-Path     : /info.php
2017-09-13 20:24:50: (response.c.493) Path         :
2017-09-13 20:24:50: (response.c.542) -- after doc_root
2017-09-13 20:24:50: (response.c.543) Doc-Root     : /var/www
2017-09-13 20:24:50: (response.c.544) Rel-Path     : /info.php
2017-09-13 20:24:50: (response.c.545) Path         : /var/www/info.php
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 1 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 2 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 3 (cached) result: true
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 4 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 5 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 6 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 7 (cached) result: false
2017-09-13 20:24:50: (response.c.562) -- logical -> physical
2017-09-13 20:24:50: (response.c.563) Doc-Root     : /var/www
2017-09-13 20:24:50: (response.c.564) Basedir      : /var/www
2017-09-13 20:24:50: (response.c.565) Rel-Path     : /info.php
2017-09-13 20:24:50: (response.c.566) Path         : /var/www/info.php
2017-09-13 20:24:50: (response.c.583) -- handling physical path
2017-09-13 20:24:50: (response.c.584) Path         : /var/www/info.php
2017-09-13 20:24:50: (response.c.591) -- file found
2017-09-13 20:24:50: (response.c.592) Path         : /var/www/info.php
2017-09-13 20:24:50: (response.c.753) -- handling subrequest
2017-09-13 20:24:50: (response.c.754) Path         : /var/www/info.php
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 1 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 2 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 3 (cached) result: true
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 4 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 5 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 6 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 7 (cached) result: false
2017-09-13 20:24:50: (mod_access.c.148) -- mod_access_uri_handler called
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 1 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 2 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 3 (cached) result: true
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 4 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 5 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 6 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 7 (cached) result: false
2017-09-13 20:24:50: (mod_compress.c.839) -- handling file as static file
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 1 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 2 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 3 (cached) result: true
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 4 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 5 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 6 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 7 (cached) result: false
2017-09-13 20:24:50: (mod_fastcgi.c.3500) handling it in mod_fastcgi
2017-09-13 20:24:50: (mod_fastcgi.c.2875) got proc: pid: 0 socket: tcp:10.5.0.3:9000 load: 1
2017-09-13 20:24:50: (mod_fastcgi.c.2543) FastCGI-stderr: Primary script unknown
2017-09-13 20:24:50: (mod_fastcgi.c.1642) released proc: pid: 0 socket: tcp:10.5.0.3:9000 load: 0
2017-09-13 20:24:50: (response.c.122) Response-Header: \nHTTP/1.1 404 Not Found\r\nCache-Control: no-cache\r\nX-Powered-By: PHP/7.1.9\r\nContent-type: text/html; charset=UTF-8\r\nContent-Length: 16\r\nDate: Wed, 13 Sep 2017 23:24:50 GMT\r\nServer: lighttpd/1.4.45\r\n\r\n
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 1 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 2 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 3 (cached) result: true
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 4 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 5 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 6 (cached) result: false
2017-09-13 20:24:50: (configfile-glue.c.694) === start of condition block ===
2017-09-13 20:24:50: (configfile-glue.c.622) 7 (cached) result: false

Note: It's running inside docker to simulate that condition, if some aditional information about docker is necessary to debug this behavior please let me know.

LeonanCarvalho
  • 620
  • 2
  • 5
  • 21

1 Answers1

2

You need to have the PHP files on the servers where PHP-FPM is running. Lighttpd only passes the request to PHP-FPM, not the actual files which contain the contents.

You need to also have all possible resources that PHP scripts use on the PHP-FPM servers.

One option to achieve this is to have the lighttpd machine share the files over a network file system. However, this could have performance issues.

A cluster file system is another option.

I have used lsyncd daemon to synchronize the files from a single system to multiple destinations. This way all PHP-FPM servers have local copies of the scripts, and there is no performance overhead for file access.

Tero Kilkanen
  • 34,499
  • 3
  • 38
  • 58
  • 1
    If looking at these tools, check out [csync2](http://oss.linbit.com/csync2/) as well. – gxx Sep 14 '17 at 11:35
  • Thanks for your time to answer my questions. It clarified a lot about the design of this clusterization. @gf_ It's a good tool to sync among clusters. I recommend it. – LeonanCarvalho Sep 14 '17 at 12:14