PHP5-FPM reload from web browser: Internal server error 500

user2302838 asked:

I am creating a free shared hosting service for fun and learning. I made a simple form where the user enters the subdomain and ftp password. When the user hits submit, a script generates a linux user, encrypts the entered password with crypt() then sends the data to a linux script. Here is the wrong part of the full script:

echo "[$1]
user = $1
group = $1
listen = /var/run/sock_$1.sock
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
php_value[disable_functions] = "phpinfo, system, exec, shell_exec, passthru , ini_alter, dl, pfsockopen, openlog, syslog, readlink, symlink, link, leak, fsockopen, popen, escapeshellcmd, apache_child_terminate apache_get_modules, apache_get_version, apache_getenv, apache_note,apache_setenv,virtual"
php_value[open_basedir] = "/home/$1:/home/$1/tmp"" | sudo /usr/bin/tee /etc/php5/fpm/pool.d/$1.conf;

sudo /usr/sbin/service php5-fpm reload;

As you can see it creates a PHP-FPM pool then reloads the service. When I manually create the pool and also manually reload FPM, it works fine, the new website loads with no problem. The problem that I noticed if I comment out the reload line it creates the pool so there is no problem with file writing but with reloading.

So when I submit the post with all the data, it has Internal server error 500.

Apache log:

[Thu Aug 08 01:43:44 2013] [error] [client] (104)Connection reset by peer: FastCGI: comm with server "/vhost_asd_tld" aborted: read failed, referer: http://asd.tld/
[Thu Aug 08 01:43:44 2013] [error] [client] FastCGI: incomplete headers (0 bytes) received from server "/vhost_asd_tld", referer: http://asd.tld/

The asd.tld pool:

user = asd_tld
group = asd_tld
listen = /var/run/sock_asd_tld.sock
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

The asd.tld vhost:

<VirtualHost *:80>
ServerAdmin asd@asd.tld
ServerName asd.tld
DocumentRoot /var/www
<Directory /var/www>  
  AllowOverride All
  Order Allow,Deny
  Allow from all
ErrorLog "/var/www/log/asd.tld-error.log"
CustomLog "/var/www/log/asd.tld-access.log" combined
CustomLog "/var/www/log/asd.tld-bandwidth.log" common
<IfModule mod_fastcgi.c>
  <FilesMatch .php$>
    SetHandler php-script
  Action php-script /php5-fpm-handler
  Alias /php5-fpm-handler /vhost_asd_tld
  FastCGIExternalServer /vhost_asd_tld -socket /var/run/sock_asd_tld.sock

OS: Ubuntu Desktop 13.04

Any ideas? Thanks in advance!

My answer:

Reloading php-fpm interrupts active connections, such as yours in this circumstance. When possible you should avoid doing it, or if you can’t, do it asynchronously, after you’ve completed sending the data to the browser.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.