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 xxx.xxx.xxx.xxx] (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 xxx.xxx.xxx.xxx] 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!


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.

  • Thanks for clarificating it! What do you exactly mean by "asynchronously"? If I understood it well, I should put it into a new job with "at" for example, and if it is done, it should inform the user? – user2302838 Aug 9 '13 at 18:47
  • There are many different ways you could do it; that's just one of them. :) – Michael Hampton Aug 9 '13 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.