PHP with Nginx at DreamHost

This article contains information/examples using root/sudo/admin users. If you require sudo/admin access, you must upgrade to a Dedicated server or DreamCompute.

PHP 5.6 is the only version available in the panel to use with your Nginx website.

PHP processes per user

For security purposes, it's generally advised to assign a single user to each domain. This way if that user is compromised, no other sites are affected. However, when running Nginx, it's recommended that you consolidate your domains under a single username. This is for performance reasons.

Nginx uses a set number of PHP processes when starting up. This happens for each user, and the same number are started regardless of how many domains are hosted under the user.

However, if you have 10 domains spread across 10 separate FTP users, you'll get 10x as many PHP processes as you would otherwise get with a single user.

Also, keep in mind that the number of PHP processes that spawn per user is automatically scaled with the amount of memory your VPS is set to use.

Limiting the amount of processes spawned per domain

Unlike Apache or Lighttpd, Nginx does not automatically spawn FCGI processes. You must start them separately. PHP5 auto-spawns as many as you set in the PHP_FCGI_CHILDREN environment variable.

View the following article for details:

The PHP_FCGI_CHILDREN variable affects how many PHP pages can be processed simultaneously. The lower the value, the less memory used. But if you're getting a lot of traffic this slows down your response time. This value defaults to 9 on DreamHost Nginx servers.

Globally on a Dedicated server

  1. Using an admin user on a Dedicated server, navigate to the following directory:
    /dh/nginx/servers/httpd-ps12345/environ
    
  2. Use the 'sudo' command to edit this file. You'll see the following lines:
    PHP_FCGI_CHILDREN=9
    PHP_FCGI_MAX_REQUESTS=1000
    

PHP_FCGI_CHILDREN is the number of desired processes per domain.

Per-user

  1. Navigate to your user's $HOME directory.
    [server]$ cd ~
  2. Create a .php-launcher file with the following contents:
    #!/bin/sh
    export PHP_FCGI_CHILDREN=9
    exec /dh/cgi-system/php5.cgi $*
    
  3. Make the script executable:
    [server]$ chmod a+x .php-launcher

See also

Did this article answer your questions?

Article last updated .