Bitnami PHP-FPM

NOTE: Before running the commands shown on this page, you should load the Bitnami stack environment by executing the installdir/use_APPNAME script (Linux and Mac OS X) or by clicking the shortcut in the Start Menu under "Start -> Bitnami APPNAME Stack -> Application console" (Windows). Learn more.

PHP-FPM is an alternative PHP FastCGI implementation with additional features.

How to configure PHP-FPM options?

To override any of the PHP configuration options (eg. memory_limit, max_execution_time), set these options in the installdir/php/etc/php.ini file and in the installdir/apps/APPNAME/conf/php-fpm/php-settings.conf file.

For example, to increase the PHP memory limit, edit the installdir/APPNAME/conf/php-fpm/php-settings.conf file and set the corresponding variable as follows. Replace the NEW_LIMIT placeholder with the new memory limit you wish to use.

php_value[memory_limit]=NEW_LIMIT

Then, also modify the installdir/php/etc/php.ini file and set the memory_limit variable to a new value, as shown below:

memory_limit=NEW_LIMIT

Restart Apache and PHP-FPM for the changes to take effect:

$ installdir/ctlscript.sh restart apache
$ installdir/ctlscript.sh restart php-fpm

How to configure PHP-FPM processes?

It is possible to configure PHP-FPM processes per application. If you have a lot of applications, this may result in excessive CPU usage.

  • You can configure your application's PHP-FPM processes to start automatically when needed. Add this option to the installdir/apps/APPNAME/conf/pfp-fpm/pool.conf file:

     pm=ondemand
    
  • You can also reduce the number of PHP-FPM processes per application by modifying the files below.

    • If you configured the processes to start dynamically, modify the installdir/php/etc/common-dynamic.conf as below:

      pm=dynamic
      pm.max_children=5
      pm.start_servers=2
      pm.min_spare_servers=1
      pm.max_spare_servers=3
      
    • If you configured the processes to start on demand, modify the installdir/php/etc/common-ondemand.conf as below:

      pm=ondemand
      pm.max_children=5
      pm.start_servers=2
      pm.min_spare_servers=1
      pm.max_spare_servers=3
      

How to disable PHP-FPM?

To disable an already enabled PHP-FPM configuration, follow these steps:

  • Disable mpm_event by commenting the LoadModule directive:

     #LoadModule mpm_event_module modules/mod_mpm_event.so
    
  • Enable mpm_prefork by uncommenting its LoadModule directive:

     LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
    
  • Enable mod_php by uncommenting its LoadModule directive:

     LoadModule php5_module  modules/libphp5.so
    
  • Restart Apache:

     $ installdir/ctlscript.sh restart apache
    
  • Stop PHP-FPM:

     $ installdir/ctlscript.sh stop php-fpm
    
  • Disable PHP-FPM:

     $ sudo mv installdir/php/scripts/ctl.sh installdir/php/scripts/ctl.sh.disabled
    

How to enable FastCGI on Windows?

PHP-FPM is not built with the windows binaries. However, it is possible to use PHP-CGI. The executable php-cgi.exe that is bundled in our stacks is a FastCGI interface. Note that it is not FPM (Fastcgi Process Manager) and does not have multi-threading or concurrent request support, nor support for any of the FPM configuration options. Find below the steps to enable it:

  • Assuming your application is running under installdir\apps\application directory, edit installdir\php\php.ini file and set doc_root parameter as below:

    doc_root = "installdir/apps/application/htdocs/"
    
  • Download winserv from this link.
  • Extract winserv.exe and place it on installdir\scripts directory.
  • Execute this command to create the FastCGI service:

    installdir\scripts\winserv.exe install phpCGI -displayname phpCGI -start auto "installdir\php\php-cgi.exe" -b 127.0.0.1:9123 -c="installdir\php\php.ini"
    
  • Add the line below in installdir\properties.ini file, inside PHP section:

    php_unique_service_name=phpCGI
    
  • Execute installdir\manager-windows.exe and start PHP server on Manage Servers tab.
  • Edit installdir\apache2\conf\httpd.conf file and enable mod_proxy, mod_proxy_fcgi and authnz_fcgi modules. For that, uncomment these lines:

    #LoadModule proxy_module modules/mod_proxy.so
    #LoadModule proxy_fcgi_module modules/mod_proxy_fcgi.so
    #LoadModule authnz_fcgi_module modules/mod_authnz_fcgi.so
    
  • Add the code below in installdir\apps\application\conf\httpd-app.conf file, inside Directory tag:

    <FilesMatch "\.php$">
      <If "-f %{REQUEST_FILENAME}">
        SetHandler "proxy:fcgi://127.0.0.1:9123/"
      </If>
    </FilesMatch>
    
  • Restart Apache server.

How to enable PHP-FPM?

PHP-FPM is disabled by default. To enable it, follow these steps:

  • Enable its control script:

     $ cd installdir
     $ mv php/scripts/ctl.sh.disabled php/scripts/ctl.sh
    
  • Start PHP-FPM:

     $ cd installdir
     $ ./ctlscript.sh start php-fpm
    
  • Enable PHP-FPM configuration in Apache. Update the installdir/apache2/conf/httpd.conf file and comment out the LoadModule directive:

     # Comment the below module to enable PHP-FPM
     # LoadModule php5_module  modules/libphp5.so
     # This enables using PHP-FPM when mod_php is disabled
     <IfModule !php5_module>
         Define USE_PHP_FPM
     </IfModule>
    
  • In the same file, disable the mpm_prefork module:

     #LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
    
  • In the same file, enable the mpm_event module:

     LoadModule mpm_event_module modules/mod_mpm_event.so
    
  • Restart Apache:

     $ cd installdir
     $ ./ctlscript.sh restart apache
    

Troubleshooting

PHP-FPM did not handle the connection error

PHP-FPM is configured such that PHP requests are delivered to the appropriate PHP-FPM pool. It may happen, however, that none of those pools consumes the request, either because it is a custom application that was not configured to use PHP-FPM, or because of a misconfiguration.

In these cases, Apache tries to serve the plaintext version of the PHP file (its source code), which may contain sensitive information. To avoid this, we have configured the server to throw an error of the form:

Not Found
The requested URL /bitnami-error-php-fpm-did-not-handle-the-connection/info.php was not found on this server.

If you come across this error, please post a question in our community forums and we will help you troubleshooting the error and release a fixed version of the misconfigured application if needed.

NOTE: When running the commands shown on this page, replace the installdir placeholder with the full installation directory for your Bitnami stack.
nativeInstaller

Bitnami Documentation