PHP with Nginx at DreamHost

Overview

This article lists some basic configuration information if you've changed your VPS or Dedicated server to run Nginx in the panel.

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

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 is 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
    /etc/nginx-httpd-argon
  2. Use sudo and edit the environ file in this directory. 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/php##.cgi $*
    

    Make sure you replace php##.cgi with the specific version of PHP you want to use, such as php80.cgi. Your server's available PHP versions can be found under the /dh/cgi-system/ directory.

  3. Make the script executable:
    [server]$ chmod a+x .php-launcher

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?