EzDev.org

php-fpm interview questions

Top 15 php-fpm interview questions

1627 Jobs openings for php-fpm


How to configure php-fpm to log logs to log files configured in nginx virtualhosts

I have Fedora 16 with nginx and php-fpm. Everything is working very good. All logs with php notice,warnig error etc. are in /var/log/php-fpm/www-error.log. Is there a way to configure php-fpm to write errors in proper log files configured as error logs for nginx ? So I want to logs php errors per virtualhost not in one global file. (like in apache and php).


Source: (StackOverflow)

PHP-FPM's chroot and chdir directory

I am setting up php-fpm with chrooting enabled. Now I see that there are two options, and I want to know what the exact difference is.

The setup has:

chroot = /var/www/domains/domain.tld/
; Chdir to this directory at the start. This value must be an absolute path.
; Default Value: current directory or / when chroot
chdir = /docroot/

Why are there two different locations here, and which path is php allowed to access. Can the php website access /var/www/domains/domain.tld/, or can it only access files withing the docroot directory.

===

Maybe there is some concrete advice for me. I want to have a setup like this:

webroot location: /var/www/

domain.com/
 |---conf/
 |    |--nginx.conf
 |    |--php-fpm.conf
 |
 |---ssl/
 |---logs/
 |---session/
 |---domains/
       |---www/
       |---app/
       |---dev/

Now here the php-fpm settings would be:

chroot = /var/www/domain.com/
chdir  = /domains/www

Now the main question here is, will the application located in the www subdomain be able to access the files in dev or app. Or even the files located in session, which is the session save path, or the other folders such as ssl and logs.


Source: (StackOverflow)

Blank Page: wordpress on nginx+php-fpm

Good day.

While this post discusses a similar setup to mine serving blank pages occasionally after having made a successful installation, I am unable to serve anything but blank pages. There are no errors present in /var/log/nginx/error.log, /var/log/php-fpm.log or /var/log/nginx/us/sharonrhodes/blog/error.log.

My setup:

  • Wordpress 3.0.4
  • nginx 0.8.54
  • php-fpm 5.3.5 (fpm-fcgi)
  • Arch Linux

Configuration Files

php-fpm.conf:

[global]
pid = run/php-fpm/php-fpm.pid
error_log = log/php-fpm.log
log_level = notice

[www]
listen = 127.0.0.1:9000
listen.owner = www
listen.group = www
listen.mode = 0660
user = www
group = www

pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 5
pm.max_spare_servers = 35
pm.max_requests = 500

nginx.conf:

user www;
worker_processes  1;

error_log  /var/log/nginx/error.log  notice;
pid        /var/run/nginx.pid;


events {
    worker_connections  1024;
}


http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    gzip  on;

    include /etc/nginx/sites-enabled/*.conf;
}

/etc/nginx/sites-enabled/blog_sharonrhodes_us.conf:

upstream php {
    server 127.0.0.1:9000;
}

server {
    error_log /var/log/nginx/us/sharonrhodes/blog/error.log notice;
    access_log /var/log/nginx/us/sharonrhodes/blog/access.log;

    server_name blog.sharonrhodes.us;
    root /srv/apps/us/sharonrhodes/blog;
    index index.php;

    location = /favicon.ico {
            log_not_found off;
            access_log off;
    }

    location = /robots.txt {
            allow all;
            log_not_found off;
            access_log off;
    }

    location / {
            # This is cool because no php is touched for static content                                                                                        
            try_files $uri $uri/ /index.php?q=$uri&$args;
    }

    location ~ \.php$ {
            fastcgi_split_path_info ^(.+\.php)(/.+)$;
            #NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini                                                                                          
            include fastcgi_params;
            fastcgi_intercept_errors on;
            fastcgi_pass php;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
            expires max;
            log_not_found off;
    }
}

/etc/nginx/conf/fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect                                                                                         
fastcgi_param  REDIRECT_STATUS    200;

Source: (StackOverflow)

Can I globally set $_SERVER['REDIRECT_URL'] before script execution?

I'm in the process of migrating many sites from an old to a new server configuration. Each site is based on a similar (but sadly not identical) codebase, using mod_rewrite URLs.

  • Ubuntu 8.04 LTS => Ubuntu 12.04 LTS
  • Apache 2.22.8 => Apache 2.2.22
  • PHP 5.2 (FastCGI) => PHP 5.3 (PHP5-FPM)

Mostly working like a charm, but on the new config the $_SERVER['REDIRECT_URL'] is no longer set, and the code is failing due to a dependence on this global variable.

From what I understand, this variable gets set by Apache when a redirect occurs. Obviously this isn't happening now, but I'm struggling to find the cause.

  • Is it the Apache upgrade, or (my guess) the switch from PHP FastCGI to PHP5-FPM?
  • How do I get this variable back?

I'd really rather not have to edit the code on each site, so I'll set a global PHP auto_prepend if necessary, but ideally I'd like to fix the server configuration and have this set in the first place.

Potentially related: I now also have a couple of new $_SERVER variables, namely REDIRECT_SCRIPT_URL and REDIRECT_REDIRECT_SCRIPT_URL. These seem to have the correct data I want for the REDIRECT_URL, but also seem to indicate there's two internal redirects occurring that weren't before - Google searches for REDIRECT_REDIRECT_SCRIPT_URL only returns random var_dump outputs. Is SCRIPT_URL the new REDIRECT_URL?

Edit 1

Checking again REDIRECT_URL is (now) set, but always to 'index.php' (the mod_rewrite target) instead of the expected typed URL. I have resorted to a using PHP auto_prepend_file to manually set the needed variable.

I'm not sure how I missed it the first time round, but I've made several changes in the meantime so I suppose there's an outside chance it wasn't there. Apologies if this mislead anyone.

Edit 2

To address the mentions of ErrorDocument below, the mod_rewrite rule in use is:

RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]

The $_GET['url'] variable is set, so the rule must be working.

To be clear, at this stage I've gone with the auto_prepend_file workaround I mentioned initially.


Source: (StackOverflow)

Nginx and PHP-FPM running out of connections

I keep running into errors like these,

[02-Jun-2012 01:52:04] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 19 idle, and 49 total children
[02-Jun-2012 01:52:05] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 19 idle, and 50 total children
[02-Jun-2012 01:52:06] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 19 idle, and 51 total children
[02-Jun-2012 03:10:51] WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 18 idle, and 91 total children

I changed my settings for php-fpm to these,

pm.max_children = 150 (It was at 100, i got a max_children reached and upped to 150)
pm.start_servers = 75
pm.min_spare_servers = 20
pm.max_spare_servers = 150

Resulting in

[02-Jun-2012 01:39:19] WARNING: [pool www] server reached pm.max_children setting (150), consider raising it

I've just launched a new website that is getting a conciderable amount of traffic on it. This traffic is legitimate and users are getting 504 gateway timeouts when the limit is reached.

I have limited connections to my server with IPTABLES and I'm running fail2ban and keeping track of nginx access logs. The traffic is all legitimate, i'm just running out of room for users.

I'm currently running on a dual core box with ubuntu 64bit.

free
             total       used       free     shared    buffers     cached
Mem:       6114284    5726984     387300          0     141612    4985384
-/+ buffers/cache:     599988    5514296
Swap:       524284       5804     518480

My php.ini max_input_time = 60

My nginx config is

worker_processes 4;
pid /var/run/nginx.pid;

events {
    worker_connections 19000;
    # multi_accept on;
}
worker_rlimit_nofile    20000;  #each connection needs a filehandle (or 2 if you are proxying)

client_max_body_size 30M;
client_body_timeout   10;
client_header_timeout 10;
keepalive_timeout     5 5;
send_timeout          10;

    location ~ \.php$ {
    try_files $uri /er/error.php;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_connect_timeout 60;
    fastcgi_send_timeout 180;
    fastcgi_read_timeout 180;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 256 16k;
    fastcgi_busy_buffers_size 256k;
    fastcgi_temp_file_write_size 256k;
    fastcgi_max_temp_file_size 0;
    fastcgi_intercept_errors on;
    fastcgi_pass unix:/tmp/php5-fpm.sock;
    fastcgi_index index.php;
    include fastcgi_params;
}

What can I do to stop running out of connections? Why does this keep occurring? I'm monitoring my traffic on Google Analytics realtime and when the user count gets above about 120 my php-fpm.log is full of these warnings..


Source: (StackOverflow)

What is wrong in my php-fpm configuration?

I have a 64-bit server but only 256MB of RAM. So, I moved to nginx server with fast-cgi to connect to PHP. I have PHP 5.3.6 running.

The issue is that after every two or three days when I try to access any PHP page then I get server internal error. The only way around is to restart php-fpm manually. This means I should have set some wrong parameters which is causing it to choke. Below I have listed the relevant configs.

/etc/php-fpm.conf :-

include=/etc/php-fpm.d/*.conf
log_level = error
;emergency_restart_threshold = 0
;emergency_restart_interval = 0
;process_control_timeout = 0

/etc/php-fpm.d/www.conf :-

[www]
pm = dynamic
pm.max_children = 10
pm.start_servers = 3
pm.min_spare_servers = 2
pm.max_spare_servers = 5
pm.max_requests = 500

/etc/nginx/php.conf :-

location ~ \.php {
        fastcgi_param  QUERY_STRING       $query_string;
        fastcgi_param  REQUEST_METHOD     $request_method;
        fastcgi_param  CONTENT_TYPE       $content_type;
        fastcgi_param  CONTENT_LENGTH     $content_length;

        fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
        fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
        fastcgi_param  REQUEST_URI        $request_uri;
        fastcgi_param  DOCUMENT_URI       $document_uri;
        fastcgi_param  DOCUMENT_ROOT      $document_root;
        fastcgi_param  SERVER_PROTOCOL    $server_protocol;

        fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
        fastcgi_param  SERVER_SOFTWARE    nginx;

        fastcgi_param  REMOTE_ADDR        $remote_addr;
        fastcgi_param  REMOTE_PORT        $remote_port;
        fastcgi_param  SERVER_ADDR        $server_addr;
        fastcgi_param  SERVER_PORT        $server_port;
        fastcgi_param  SERVER_NAME        $server_name;

        fastcgi_pass unix:---some-location---;
}

Update 1

And I have four nginx processes running. On an average each php-fpm process takes 35MB of RAM (Virtual memory size 320MB each). I also have a MySql process running.

Update 2

I forgot to paste the logs.

php-fpm error log :-

WARNING: [pool www] seems busy (you may need to increase start_servers, or min/max_spare_servers), spawning 8 children, there are 1 idle, and 7 total children
WARNING: [pool www] server reached max_children setting (10), consider raising it
NOTICE: Terminating ...

php-fpm www.error log :-

PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 122880 bytes) in /home/webadmin/blog.applegrew.com/html/wordpress/wp-content/plugins/jetpack/class.jetpack-signature.php on line 137
PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 122880 bytes) in /home/webadmin/blog.applegrew.com/html/wordpress/wp-content/plugins/jetpack/class.jetpack-signature.php on line 137
PHP Fatal error:  Allowed memory size of 33554432 bytes exhausted (tried to allocate 122880 bytes) in /home/webadmin/blog.applegrew.com/html/wordpress/wp-content/plugins/jetpack/class.jetpack-signature.php on line 137

Source: (StackOverflow)

nginx / php-fpm error logging

I'm trying to figure out where the PHP errors are going in my setup. I'm running nginx as the reverse proxy to PHP-FPM, but I'm not seeing the various E_NOTICE or E_WARNING messages my app is producing. The only reason I know they're happening is failed responses and NewRelic catching stack traces.

Here's the logging config:

nginx.conf

proxy_intercept_errors on;
fastcgi_intercept_errors on;

php.ini

error_reporting  =  E_ALL
display_errors = Off
display_startup_errors = Off
log_errors = On
log_errors_max_len = 1024
ignore_repeated_errors = Off
ignore_repeated_source = Off
report_memleaks = On
track_errors = On
error_log = syslog

php-fpm.conf

[global]
error_log = /var/log/php-fpm/fpm-error.log

[www]
access.log = /var/log/php-fpm/access.log
access.format = "%t \"%m %r%Q%q\" %s %{mili}dms %{kilo}Mkb %C%%"
catch_workers_output = yes

php_flag[display_errors] = on
php_admin_flag[log_errors] = true

rsyslog.conf

:syslogtag, contains, "php" /var/log/php-fpm/error.log

I've configured PHP to log to syslog, however FPM has no syslog function so it's logging to a file. I don't really care where the errors end up, just that they end up somewhere.

Any clues on how I might get this to work?


Source: (StackOverflow)

Webserver randomly serves different vhosts

We've got nginx running on Ubuntu Trusty. It serves several websites over https, running on one ip address.

Randomly, although it seems slightly related to work load, sometimes single requests turn up on the wrong vhost. This leads to requests on lustrum.thalia.nu being served by thalia.nu and vice-versa. This then gives nasty error pages as users suddenly end up on a different web site. When you press F5, users then end up on the original target again.

It does not seem browser or operating system related. It's been confirmed to happen on Firefox (Linux, Windows, Mac), Edge (Windows) and Chrome (Linux, Windows, Android) and Safari (iOS).

The issue appears to occur more frequently when the system is put under load, suggesting some sort of race condition.

lustrum.thalia.nu

server {
        server_name lustrum.thalia.nu;

        listen 443 ssl;

        ssl on;
        ssl_certificate /etc/nginx/certs/lustrum.thalia.nu.crt;
        ssl_certificate_key /etc/nginx/certs/lustrum.thalia.nu.key;

        add_header Strict-Transport-Security "max-age=63072000; preload";

        root /var/www/thalia-lustrum/public_html;

        location / {
                index index.php;
                try_files $uri $uri/ /index.php?$args;
        }

        # Add trailing slash to */wp-admin requests.
        rewrite /wp-admin$ $scheme://$host$uri/ permanent;

        # Pass all .php files onto a php-fpm/php-fcgi server.
        location ~ [^/]\.php(/|$) {
                include         /etc/nginx/fastcgi_params;

                fastcgi_split_path_info ^(.+?\.php)(/.*)$;

                if (!-f $document_root$fastcgi_script_name) {
                        return 404;
                }

                fastcgi_pass    unix:/var/run/php5-fpm-thalia-lustrum.sock;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME  /public_html$fastcgi_script_name;
        }
}

thalia.nu

server {
        server_name thalia.nu;    
        listen 443 ssl;

        ssl on;
        ssl_certificate /etc/nginx/certs/www.thalia.nu.crt;
        ssl_certificate_key /etc/nginx/certs/www.thalia.nu.key;

        add_header Strict-Transport-Security "max-age=63072000; preload";

        root /var/www/thalia/public_html;

        location / {
                try_files $uri $uri/ /index.php/$request_uri;
                index index.php index.html index.htm;
        }

        location ~ \.php($|/) {
                include         /etc/nginx/fastcgi_params;
                set  $script     $uri;
                set  $path_info  "";
                if ($uri ~ "^(.+\.php)(/.+)") {
                                set  $script     $1;
                                set  $path_info  $2;
                }
                fastcgi_read_timeout    120;
                fastcgi_pass    unix:/var/run/php5-fpm-thalia-www.sock;
                fastcgi_index   index.php;
                fastcgi_param   SCRIPT_FILENAME  /public_html$fastcgi_script_name;
        }
}

As you can see, we're running different PHP5-FPM pools for these two domains. These pools are chrooted to different folders and run as different users. PHP-FPM's configuration are otherwise fairly standard as far as I can tell.

We've tried both nginx 1.4.6-ubuntu3 and nginx 1.8.0-1+trusty.

Log telemetry

266.266.266.266 - - [25/Nov/2015:09:24:40 +0100] "GET /committees/175 HTTP/1.1" 302 5 "https://thalia.nu/committees" "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:42.0) Gecko/20100101 Firefox/42.0" Host: "thalia.nu" Location: "https://thalia.nu/index.php//committees/wp-admin/setup-config.php"

In this line you can see that the request for the page /committees suddenly gets redirected to wp-admin. This appears that the request for /committees got handled by the thalia-lustrum PHP-fpm pool...

DNS zone file

We don't see how this can possibly be relevant, but...

;; MX Records
thalia.nu.    300    IN    MX    20    relay.transip.nl.
thalia.nu.    300    IN    MX    10    ivo.thalia.nu.

;; TXT Records
thalia.nu.    300    IN    TXT    "v=spf1 a mx a:mulgore.hexon-is.nl a:moonray.hexon-is.nl a:fred.thalia.nu a:ivo.thalia.nu ~all"

;; SPF Records (Sender Policy Framework)
thalia.nu.    300    IN    SPF    "v=spf1 a mx a:mulgore.hexon-is.nl a:moonray.hexon-is.nl a:fred.thalia.nu a:ivo.thalia.nu ~all"

;; CNAME Records
lustrum.thalia.nu.    300    IN    CNAME    thalia.nu.

;; A Records (IPv4 addresses)
thalia.nu.    300    IN    A    131.174.31.8
www.thalia.nu.    300    IN    A    131.174.31.8
ivo.thalia.nu.    300    IN    A    131.174.31.8

Source: (StackOverflow)

Php5-fpm Crash if much visitors

I decided to change my OP to Nginx from Litespeed because i read much about the low resource that Nginx would cost.

Im running a Wordpress site with 500 users online

Okay thanks Guys for that much help :) I edited some things.

I have some questions left too:

Do i have to remove the ; before the pm. settings? I removed it What config counts? I got two fast cgi one in /etc/php5/fpm called php-fpm.conf and one in /etc/php5/fpm/pool.d called www.conf ?

I tried the new config over night and when i wake up i already got a blank page. Top:

top - 13:55:27 up 1 day, 19:28,  2 users,  load average: 0.18, 0.36, 0.19
Tasks:  84 total,   1 running,  83 sleeping,   0 stopped,   0 zombie
Cpu(s):  0.2%us,  0.0%sy,  0.0%ni, 99.8%id,  0.0%wa,  0.0%hi,  0.0%si,  0.0%st
Mem:   3974264k total,  1051360k used,  2922904k free,   162380k buffers
Swap:  3998700k total,        0k used,  3998700k free,   609220k cached

  PID USER      PR  NI  VIRT  RES  SHR S %CPU %MEM    TIME+  COMMAND
 1857 www-data  20   0  193m  55m  22m S    0  1.4   0:04.67 php5-fpm
    1 root      20   0  8356  808  680 S    0  0.0   0:01.37 init
    2 root      20   0     0    0    0 S    0  0.0   0:00.00 kthreadd

I think cpu usage is now lower, but thats not fixing the crash...

My configs are now: php-fpm.conf

    ;;;;;;;;;;;;;;;;;;;;;
; FPM Configuration ;
;;;;;;;;;;;;;;;;;;;;;

; All relative paths in this configuration file are relative to PHP's install
; prefix (/usr). This prefix can be dynamicaly changed by using the
; '-p' argument from the command line.

; Include one or more files. If glob(3) exists, it is used to include a bunch of
; files from a glob(3) pattern. This directive can be used everywhere in the
; file.
; Relative path can also be used. They will be prefixed by:
;  - the global prefix if it's been set (-p arguement)
;  - /usr otherwise
;include=/etc/php5/fpm/*.conf

;;;;;;;;;;;;;;;;;;
; Global Options ;
;;;;;;;;;;;;;;;;;;

[global]
; Pid file
; Note: the default prefix is /var
; Default Value: none
pid = /var/run/php5-fpm.pid

; Error log file
; If it's set to "syslog", log is sent to syslogd instead of being written
; in a local file.
; Note: the default prefix is /var
; Default Value: log/php-fpm.log
error_log = /var/log/php5-fpm.log

; syslog_facility is used to specify what type of program is logging the
; message. This lets syslogd specify that messages from different facilities
; will be handled differently.
; See syslog(3) for possible values (ex daemon equiv LOG_DAEMON)
; Default Value: daemon
;syslog.facility = daemon

; syslog_ident is prepended to every message. If you have multiple FPM
; instances running on the same server, you can change the default value
; which must suit common needs.
; Default Value: php-fpm
;syslog.ident = php-fpm

; Log level
; Possible Values: alert, error, warning, notice, debug
; Default Value: notice
;log_level = notice

; If this number of child processes exit with SIGSEGV or SIGBUS within the time
; interval set by emergency_restart_interval then FPM will restart. A value
; of '0' means 'Off'.
; Default Value: 0
emergency_restart_threshold = 1

; Interval of time used by emergency_restart_interval to determine when 
; a graceful restart will be initiated.  This can be useful to work around
; accidental corruptions in an accelerator's shared memory.
; Available Units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
emergency_restart_interval = 1s

; Time limit for child processes to wait for a reaction on signals from master.
; Available units: s(econds), m(inutes), h(ours), or d(ays)
; Default Unit: seconds
; Default Value: 0
process_control_timeout = 10s

; The maximum number of processes FPM will fork. This has been design to control
; the global number of processes when using dynamic PM within a lot of pools.
; Use it with caution.
; Note: A value of 0 indicates no limit
; Default Value: 0
process.max = 150

; Send FPM to background. Set to 'no' to keep FPM in foreground for debugging.
; Default Value: yes
;daemonize = yes

; Set open file descriptor rlimit for the master process.
; Default Value: system defined value
rlimit_files = 1024

; Set max core size rlimit for the master process.
; Possible Values: 'unlimited' or an integer greater or equal to 0
; Default Value: system defined value
;rlimit_core = 0

; Specify the event mechanism FPM will use. The following is available:
; - select     (any POSIX os)
; - poll       (any POSIX os)
; - epoll      (linux >= 2.5.44)
; - kqueue     (FreeBSD >= 4.1, OpenBSD >= 2.9, NetBSD >= 2.0)
; - /dev/poll  (Solaris >= 7)
; - port       (Solaris >= 10)
; Default Value: not set (auto detection)
; events.mechanism = epoll

;;;;;;;;;;;;;;;;;;;;
; Pool Definitions ; 
;;;;;;;;;;;;;;;;;;;;

; Multiple pools of child processes may be started with different listening
; ports and different management options.  The name of the pool will be
; used in logs and stats. There is no limitation on the number of pools which
; FPM can handle. Your system will tell you anyway :)

; To configure the pools it is recommended to have one .conf file per
; pool in the following directory:
include=/etc/php5/fpm/pool.d/*.conf

request_terminate_timeout = 30s

pm.max_children = 25

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: min_spare_servers + (max_spare_servers - min_spare_servers) / 2
pm.start_servers = 5

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 2

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 5

; The number of seconds after which an idle process will be killed.
; Note: Used only when pm is set to 'ondemand'
; Default Value: 10s
pm.process_idle_timeout = 10s;

fastcgi_params:

fastcgi_param   QUERY_STRING        $query_string;
fastcgi_param   REQUEST_METHOD      $request_method;
fastcgi_param   CONTENT_TYPE        $content_type;
fastcgi_param   CONTENT_LENGTH      $content_length;

fastcgi_param   SCRIPT_FILENAME     $request_filename;
fastcgi_param   SCRIPT_NAME     $fastcgi_script_name;
fastcgi_param   REQUEST_URI     $request_uri;
fastcgi_param   DOCUMENT_URI        $document_uri;
fastcgi_param   DOCUMENT_ROOT       $document_root;
fastcgi_param   SERVER_PROTOCOL     $server_protocol;

fastcgi_param   GATEWAY_INTERFACE   CGI/1.1;
fastcgi_param   SERVER_SOFTWARE     nginx/$nginx_version;

fastcgi_param   REMOTE_ADDR     $remote_addr;
fastcgi_param   REMOTE_PORT     $remote_port;
fastcgi_param   SERVER_ADDR     $server_addr;
fastcgi_param   SERVER_PORT     $server_port;
fastcgi_param   SERVER_NAME     $server_name;

#fastcgi_param  HTTPS           $https;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param   REDIRECT_STATUS     200;

fastcgi_connect_timeout 60;
fastcgi_send_timeout 180;
fastcgi_read_timeout 180;
fastcgi_buffer_size 128k;
fastcgi_buffers 4 256k;
fastcgi_busy_buffers_size 256k;
fastcgi_temp_file_write_size 256k;
fastcgi_intercept_errors on;

nginx config:

user www-data;
worker_processes 2;
pid /var/run/nginx.pid;

events {
    worker_connections 500;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 40;
    types_hash_max_size 2048;
    server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    ##
    # Logging Settings
    ##

    # access_log /var/log/nginx/access.log;
    # error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

 gzip_vary on;
 gzip_proxied any;
 gzip_comp_level 9;
 gzip_buffers 16 8k;
 gzip_http_version 1.1;
 gzip_types text/plain text/css application/json application/x-javascript text/$

www.conf

; Start a new pool named 'www'.
; the variable $pool can we used in any directive and will be replaced by the
; pool name ('www' here)
[www]

user = www-data
group = www-data


pm = dynamic

pm.max_children = 25

pm.start_servers = 5

pm.min_spare_servers = 2

pm.max_spare_servers = 5

pm.process_idle_timeout = 10s;

pm.max_requests = 100

request_terminate_timeout = 120s

The Mashine: Dualcore 4gb ram


Source: (StackOverflow)

PECL command produces long list of errors

Currently running PHP 5.4 on CentOS 6.5.

I installed the webtatic php55w package then installed PEAR+PECL without issue along with redis and mongo through PECL.

Shortly after, I realized 5.5 is not compatible with the framework I was working with so I yum erased php55w and installed php54w in it's place.

Now the pecl command doesn't work at all. It just produces this really long string of errors every time I issue any pecl command (abbreviated...most repeated dozens of times):

Warning: Invalid argument supplied for foreach() in Command.php on line 259

Warning: Invalid argument supplied for foreach() in /usr/share/pear/PEAR/Command.php on line 259

...etc etc etc...

Notice: Undefined index: honorsbaseinstall in Role.php on line 180

Notice: Undefined index: honorsbaseinstall in Role.php on line 180

...etc etc etc...

Notice: Undefined index: installable in Role.php on line 145

Notice: Undefined index: installable in Role.php on line 145

...etc etc etc...

Notice: Undefined index: phpfile in Role.php on line 212

Notice: Undefined index: phpfile in Role.php on line 212

...etc etc etc...

Notice: Undefined index: config_vars in Role.php on line 49

Notice: Undefined index: config_vars in Role.php on line 49

...etc etc etc...

Warning: Invalid argument supplied for foreach() in PEAR/Command.php on line 259

Warning: Invalid argument supplied for foreach() in /usr/share/pear/PEAR/Command.php on line 259

...etc etc etc...

XML Extension not found

How can I fix this?


Source: (StackOverflow)

Access PHP-FPM's /status page manually (bypass Apache)

There is a PHP5.3.3 bug that won't allow me to view php-fpm's /status page via Apache2. Is there a way to manually access this data? I cannot upgrade the box (Ubuntu 10.10, php5.3.4 not supported).

I've tried connecting using the technique here: http://inode.co.nz/testing-a-fastcgi-service, but no luck.


Source: (StackOverflow)

pecl install mongo - keeps compiling with wrong module API

Working with Ubuntu 12.04 here, nginx and php5-fpm

I had mongo working well on php 5.3, then I added the ondrej/php5 ppa and updated to php5.4. It kept GD and CURL extensions, but not mongo. I re-added the line to the php.ini file, and nothing. Then I enabled startup errors and got this:

PHP Startup: Unable to load dynamic library '/usr/lib/php5/20100525/mongo.so' - /usr/lib/php5/20100525/mongo.so: cannot open shared object file: No such file or directory

So, wild guess, I did find -name 'mongo.so' and moved the file from 20090626/ to 20100525/ ...which resulted in this error:

PHP Startup: mongo: Unable to initialize module
Module compiled with module API=20090626
PHP    compiled with module API=20100525
These options need to match

I then did pecl uninstall mongo and pecl install mongo - which created the new mongo.so file right back in 20090626/

I'm kinda new to all this so hopefully this is a blind easy mistake to fix! I just need to get mongo back up and running.


Source: (StackOverflow)

Apache MPMs - Worker vs Prefork

I'm trying to figure out what which is the best Apache MPM I can install on my VPS. I saw some benchmarks and MPM Worker seems to perform better than the Prefork one but for some reason everyone seems to be recommending Prefork over Worker for PHP setups.

Is this just because some PHP functions are not thread-safe? Only setlocale() comes to mind, but I'll be using the same locale on every instance so I don't think that will be a problem. My VPS has little memory and I feel that the worker MPM would be a better match for my needs, however I'm not sure.

Can someone help me make up my mind about this? Thanks!


PS: I've also looked into nginx and lighttpd. nginx seems awesome but I'm trying to avoid compiling from source and I still don't quite understand what php-fpm is for. Regarding lighttpd - it was incredible easy to setup PHP/FCGI with it, but I heard that it has memory leaks. Is this still true?


Source: (StackOverflow)

nginx fastcgi "Primary script unknown" when configuring userdir

I hate configuring nginx. It's so complicated. How do I get PHP to work in my user dirs? Here's the relevant part of my nginx.conf:

    location ~ ^/~(.+?)(/.*)?$ {
        autoindex on;
        autoindex_exact_size off;
        alias /home/$1/public_html$2;

        location ~ \.php {
            include /etc/nginx/fastcgi.conf;
            fastcgi_intercept_errors on;
            fastcgi_pass  127.0.0.1:9000;
            fastcgi_index index.php;
        }
    }

This gives me the error: FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream in the nginx error log.

Here's my /etc/nginx/fastcgi.conf:

fastcgi_param  SCRIPT_FILENAME    $document_root$fastcgi_script_name;
fastcgi_param  QUERY_STRING       $query_string;
fastcgi_param  REQUEST_METHOD     $request_method;
fastcgi_param  CONTENT_TYPE       $content_type;
fastcgi_param  CONTENT_LENGTH     $content_length;

fastcgi_param  SCRIPT_NAME        $fastcgi_script_name;
fastcgi_param  REQUEST_URI        $request_uri;
fastcgi_param  DOCUMENT_URI       $document_uri;
fastcgi_param  DOCUMENT_ROOT      $document_root;
fastcgi_param  SERVER_PROTOCOL    $server_protocol;
fastcgi_param  HTTPS              $https if_not_empty;

fastcgi_param  GATEWAY_INTERFACE  CGI/1.1;
fastcgi_param  SERVER_SOFTWARE    nginx/$nginx_version;

fastcgi_param  REMOTE_ADDR        $remote_addr;
fastcgi_param  REMOTE_PORT        $remote_port;
fastcgi_param  SERVER_ADDR        $server_addr;
fastcgi_param  SERVER_PORT        $server_port;
fastcgi_param  SERVER_NAME        $server_name;

# PHP only, required if PHP was built with --enable-force-cgi-redirect
fastcgi_param  REDIRECT_STATUS    200;

I'm assuming nginx isn't resolving the script name correctly. I hate having to tell nginx where to look in my filesystem, writing custom regexes for what should be built-in (or at least standardized and documented) functionality.


Source: (StackOverflow)

Nginx + php5-fpm = "File not found"

I've hit a wall whilst setting up a site using nginx / fpm. The page displays "File not found", and this appears in the nginx error.log:

FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream

I'm new to both nginx and fpm, and that error message means nothing to me (even the google machine hasn't helped!). Can anyone shed any light onto what could be happening?


Source: (StackOverflow)