Here you are going to simply add some POOL information to the PHP-FPM setup that you have already done. Unknowingly when you entered the command to install PHP-FPM, the system setup a default configuration for PHP-FPM. So most of the heavy lifting has been done for you.
You may have to do one thing and that is to create a directory where you want your Sockets to live while they are alive. I placed them here: /var/run/php5-fpm/ You can use this command to create the directory.
mkdir -p /var/run/php5-fpm/
This directory may already exists by simply installing PHP-FPM. This is the place where your file sockets will exist when online. Once you are sure that this directory exists there is nothing further you will need to do with this directory. Sockets will automatically spawn here provided you are using the virtualhost setup and PHP-FPM pool template provided.
To complete the setup move to the directory /etc/php5/fpm/pool.d/. It is here that you will setup the different UNIX Sockets that PHP-FPM will function on.
Please Note: In order for your system to function properly you will need to create a new POOL for every Virtual Host that you had setup.
The pool files should follow this naming convention: YOURDOMAIN.conf
Here is a template for the pool files.
[DOMAINNAME] listen = /var/run/php5-fpm/DOMAINNAME.socket listen.backlog = -1 ; Unix user/group of processes user = (THE USERNAME OF THE USER THAT OWNS THE SITE FILES) group = www-data ; Choose how the process manager will control the number of child processes. pm = dynamic pm.max_children = 75 pm.start_servers = 10 pm.min_spare_servers = 5 pm.max_spare_servers = 20 pm.max_requests = 500 ; Pass environment variables env[HOSTNAME] = $HOSTNAME env[PATH] = /usr/local/bin:/usr/bin:/bin env[TMP] = /tmp env[TMPDIR] = /tmp env[TEMP] = /tmp ; host-specific php ini settings here ; php_admin_value[open_basedir] = /var/www/DOMAINNAME/htdocs:/tmp
Please remember to replace all instances of "DOMAINNAME" with then name of your domain.
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

11 Comments
You can also just set the
listen = /var/run/php5-fpm/$pool.socket
Makes it a bit easier to copy configs around.
This article is great. I
Drupal is working great for everything EXCEPT using php to generate images using Drupal image styles. I get a "Error generating image." in the browser, and in the nginx logs (I set the error_log directive to debug for this) I'm seeing that it's doing the correct rewrite but then a 500 Internal Server Error happens. I checked folder permissions, and they seem fine. I can't figure it out. Any thoughts?
re: Drupal image styles
Unfortunately 500 errors are pretty generic, so it's hard to tell what the problem could be at a glance. You might check on Drupal-specific forums, as you might find more people who are familiar with the image generation functionality there.
Thanks, Jered. I actually
I used git to clone my project from my old server to the new one. I have .gitignore set up to ignore sites/*/files, so the files in there didn't get copied, and when Drupal tried to manipulate an image within there, the image didn't exist. It's odd to me that Drupal doesn't log a more specific error for this situation, but oh well, I finally figured it out. A quick scp of the files from my old server to the new one and everything is looking good. And uploading a new image to test styles shows that they're working.
I also think it should be
Thanks for the help.
re: Drupal
And thanks for the note about tuning the worker values based on your expected load and environment. It's definitely good advice - both to make sure your server can keep up with normal traffic, and to keep it from overloading the system and grinding to a halt if you get an unexpected traffic spike.
502 Bad Gateway, sockets not spawning, also /var/run/php5-fpm/
First I don't have any of this on the web yet. I am running it from an extra computer in my home to test.
I have managed to get Nginx working using a simple vhost file and an index.html file. so the issue is with fastcgi and the socket I believe.
I created the directory:
mkdir -p /var/run/php5-fpm/
and set ownership:
sudo chown -R www-data:www-data /var/www/jieiku.com
the computer I am using to access my ubuntu machine has the hosts file edited to point to the local IP address when going to jieiku.com or www.jieiku.com
After a reboot the /var/run/php5-fpm/ folder is gone.
my pool config file is named "jieiku.com.conf" and I have it set:
user = www-data
group = www-data
So I am all the way to the end of the guide when I try to access my page, I get 502 Bad Gateway with a horizontal line and then nginx/1.2.1 at the bottom of the page.
I checked the log and when I try to access www.jieiku.com/index.php it shows:
2013/02/02 20:27:02 [crit] 1798#0: *1 connect() to unix:/var/run/php5-fpm/jieiku.com.socket failed (2: No such file or directory) while connecting to upstream, client: 192.168.1.100, server: jieiku.com, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://unix:/var/run/php5-fpm/jieiku.com.socket:", host: "jieiku.com"
any help greatly appreciated :)
re: socket
If the directory is only disappearing after a reboot then there may be a system process cleaning the /var/run directory out. As an experiment you might try using another directory to hold the socket file (maybe in /etc/php/fpm/run) to see if the issue is specific to /var/run.
/var/run is typically a tmpfs
I'm trying to work on the best way to fix this at the moment too. I noticed that many other daemon processes simply make their init script check that /var/run/XYZ is already there or create it, for example mysql does this:
[ -d /var/run/mysqld ] || install -m 755 -o mysql -g root -d /var/run/mysqld
Ended up adding this to /etc
SOCKETDIR = /var/run/php5-fpm
then under do_start()
[ -d $SOCKETDIR ] || install -m 755 -o www-data -g root -d $SOCKETDIR
re: tmpfs
The error message complains about not being able to connect to the socket being created by php-fpm. That could mean something as simple as it trying to create that file and failing due to permissions or a missing directory, or it could mean there's another configuration problem or bug preventing the process from logging that it couldn't create the network socket. I don't know the inner workings of nginx/php-fpm well enough myself to say which program is responsible for creating that network socket, but I'll see if I can find out.
Add new comment