Pivotal Knowledge Base

Follow

Using your own version of PHP with vFabric Enterprise Ready Server (ERS) under Linux/Unix (2001316)

Using your own version of PHP with vFabric Enterprise Ready Server (ERS) under Linux/Unix (2001316)

Purpose

VMware vFabric Enterprise Ready Server (ERS) 4 ships with a specific version of PHP, compiled for use by the webserver via mod_php. If you would like to use a different version of PHP, more easily control the PHP extensions available, or just separate PHP execution out from your webserver, you may use mod_fcgid to link your web server to your desired PHP installation.

Resolution

This article assumes that you have installed ERS 4 in /usr/local/ers and want to use PHP from an instance defined in /usr/local/ers/servers/instance/. To do so, modify the files and directories specified below to match your own installation:
  1. Install the desired version of PHP, either via your operating system update mechanism, or by compiling a source download from http://php.net/.

    Note: The preceding link was correct as of July 8, 2011. If you find the link is broken, provide feedback and a VMware employee will update the link.

    1. As part of this, you need to have a FastCGI-enabled executable. The default for this is is /usr/local/bin/php-cgi, but these directions can be adjusted to match your installation.

      Notes:
      • php-cgi may not be part of a base PHP package provided by your OS.

        Example: Red Hat Enterprise Linux 5 comes with the separate package php-cli (or php53-cli).

      • If you are compiling PHP 5.3 from source, add --enable-cgi to the configure options to create php-cgi.

    2. You need to know the location of php.ini. The default location is is /usr/local/etc/php.ini, but these directions can be adjusted to match your installation.

      Example: Red Hat Enterprise Linux 5 packaged PHP uses /etc/php.ini.

    Note: PHP should be non-thread-safe for best performance.

  2. Create a FastCGI wrapper script for use by mod_fcgid. This script can be used to specify environment variables.

    Example:
    #!/bin/sh
    # Set desired PHP_FCGI_* environment variables.
    # Example:
    # PHP FastCGI processes exit after 500 requests by default.
    PHP_FCGI_MAX_REQUESTS=10000
    export PHP_FCGI_MAX_REQUESTS

    # Replace with the path to your FastCGI-enabled PHP executable
    exec /usr/local/bin/php-cgi


    Save the script as as /usr/local/bin/php-wrapper.

  3. Configure mod_fcgid into your instance.

    1. Add these lines to /usr/local/ers/servers/instance/conf/httpsd.conf:

      LoadModule fcgid_module "/usr/local/ers/apache2.2/modules/standard/mod_fcgid.so"
      <IfModule mod_fcgid.c>
          AddHandler fcgid-script .php
          FcgidInitialEnv PHPRC "/usr/local/etc/php.ini"
          FcgidInitialEnv PATH "/usr/local/ers/apache2.2/bin"
          # How many requests a process should handle before recycling itself:
          FcgidMaxRequestsPerProcess 10000
          # Should match or exceed the number above
          FcgidInitialEnv PHP_FCGI_MAX_REQUESTS 10000
          # Max PHP requests to handle at a time:
          FcgidMaxProcesses 10
          FcgidIOTimeout 120
          FcgidIdleTimeout 120
          FcgidWrapper "/usr/local/bin/php-wrapper" .php
          AddType application/x-httpd-php .php
      </IfModule>

    2. Add Options ExecCGI in the directory section where you want PHP to be enabled.

      Example: Add it to the <Directory "/usr/local/ers/servers/instance/htdocs/"> section, so that it looks like this:

      Options Indexes FollowSymLinks Includes ExecCGI
    3. Completely remove any references to the original mod_php module. These may have been automatically created with the instance:

      <IfModule mpm_winnt.c> 
          LoadFile "/usr/local/ers/php5.2/php5ts.dll"
      </IfModule>
      LoadModule php5_module "/usr/local/ers/apache2.2/modules/php/mod_php5.so"

      and later on

      <IfModule mod_php5.c> 
          PHPINIDir "/usr/local/ers/php5.2/etc" 
          AddType application/x-httpd-php .php
      </IfModule>
  4. To verify that the instance works with your new PHP, create the file /usr/local/ers/servers/instance /htdocs/info.php with exactly these contents:

    <?php 
        phpinfo();
    ?>
  5. Start the instance ( bin/apache_startup.sh start). In your browser, navigate to page created on your server in step 4.

    Example: http://localhost:8080/info.php

The standard PHP Information screen is displayed. The Server API parameter is CGI/FastCGI and indicates your version of PHP (under Core).

When looking at a system process tree (ps faxw), the /usr/local/bin/php-cgi process is running under one of the httpsd child processes. This is only created after a PHP request has been served.

In the /usr/local/ers/servers/instance/logs/error.log file, there are [notice] messages. These indicate that mod_fcgid is configured and a child process has been started.

Additional Information

For more information about configuration details, see the mod_fcgid documentation.

For more information about the FastCGI standard itself, see the FastCGI web site.

Note: The preceding links were correct as of July 8, 2011. If you find a link is broken, provide feedback and a VMware employee will update the link.

Comments

Powered by Zendesk