Deploying a PHP Application

Updated by Ben Heisel on Jan 29, 2016


Application developers


AppFog includes the Cloud Foundry PHP buildpack by default. This enables the deployment of PHP applications with a limited amount of configuration changes to an existing application.

The buildpack includes a customizable Apache (by deafult) or nginx server.

Deploying a Simple Example

Run the following in a Bash shell to generate the simplest working example.

mkdir hello-php
cd hello-php
printf "<?php\n  phpinfo();\n?>"> index.php
cf push -m 128M --random-route hello-php

The -m 128M on cf push tells AppFog that it should allocate 128 MB of memory to run this website. Once it is deployed AppFog will return a URL where you can access the website in your browser:

➜  hello-php cf push -m 128M --random-route hello-php
Finished: [2015-07-07 16:33:37.539588]
-----> Uploading droplet (16M)

1 of 1 instances running

App started


App hello-php was started using this command `$HOME/.bp/bin/start`

Showing health and status for app hello-php in org testOrg / space Dev as admin...

requested state: started
instances: 1/1
usage: 128M x 1 instances
last uploaded: Tue Jul 7 16:33:31 UTC 2015
stack: cflinuxfs2

     state     since                    cpu    memory          disk          details   
#0   running   2015-07-07 09:33:44 AM   0.0%   33.7M of 128M   37.4M of 1G

Once the application has successfully started then you can go to the given URL route provided as the value for urls in the console log. The example URL route above is Take this URL and go to a browser to see the running application.

Buildpack Options

The buildpack has several configuration options that a developer might want to customize. For example, to change the PHP version to the latest PHP 5.5, create a file .bp-config/options.json with the following contents:


For a complete list of options, see:


Many buildpack default php.ini settings may be modified by including a .user.ini file in your application's root directory. Additionally, a .user.ini file can be placed in any directory to limit modifications to a specific directory as described in the PHP Documentation. This PHP Manual page describes where a configuration setting may be set. A .user.ini file will work for php.ini settings that do not have a Changeable mode value of PHP_INI_SYSTEM. Here you can find the default PHP 5.5 php.ini and PHP 5.6 php.ini settings.

For example, a script that takes a long time to execute may need the following modifications within a .user.ini file:

max_execution_time = 300
max_input_time = 180

To modify php.ini settings marked PHP_INI_SYSTEM, create the directory .bp-config/php/conf.d in the root of your application. Next add a file with any name using the .ini extension in the directory, such as php-settings.ini. Then set the environment variable PHP_INI_SCAN_DIR to .bp-config/php/conf.d. This will instruct PHP to look for additional INI configuration in the directory you just created:

cf set-env <YOUR_APPNAME> PHP_INI_SCAN_DIR .bp-config/php/conf.d

Configuring Apache

Developers have complete control over the buildpack's Apache server. For example, to change the modules and enable mod_alias to add Redirect support in .htaccess (which is off by default), add httpd-modules.conf the following to .bp-config/httpd/extra/ with contents:

LoadModule authz_core_module modules/
LoadModule authz_host_module modules/
LoadModule log_config_module modules/
LoadModule env_module modules/
LoadModule setenvif_module modules/
LoadModule dir_module modules/
LoadModule mime_module modules/
LoadModule reqtimeout_module modules/
LoadModule unixd_module modules/
LoadModule mpm_event_module modules/
LoadModule proxy_module modules/
LoadModule proxy_fcgi_module modules/
LoadModule remoteip_module modules/
LoadModule rewrite_module modules/
LoadModule alias_module modules/

This is the same as the default, with the added line LoadModule alias_module modules/

Some users have reported issues with timeouts beyond the PHP configuration and have needed to modify the Apache timeout settings. This can be done by creating a httpd-default.conf file located within the .bp-config/httpd/extra/ directory. The default can be found here: In the example below note the only change is updating the Timeout value from the default of 60 seconds to 300 seconds:

Timeout 300
KeepAlive On
MaxKeepAliveRequests 100
KeepAliveTimeout 5
UseCanonicalName Off
UseCanonicalPhysicalPort Off
AccessFileName .htaccess
ServerTokens Prod
ServerSignature Off
HostnameLookups Off
EnableMMAP Off
EnableSendfile On
RequestReadTimeout header=20-40,MinRate=500 body=20,MinRate=500

Here are the default Apache configuration files. To override any file, simply provide a file of the same name and path in .bp-config/httpd/


It's important to specify a specific buildpack with this level of customization. As we upgrade the platform, the default PHP buildpack version will increase and it could be incompatible with any customizations you've made. To lock the buildpack to a specific version so you can control buildpack upgrades, include the buildpack directive in your manifest.yml. Example manifest specifying buildpack version 3.3.0:

  - name: my-php-app
    host: chk-my-php-app
    memory: 128M

Using nginx

To use nginx, instead of the default Apache, create a file .bp-config/options.json, with the following contents:

    "WEB_SERVER": ["nginx"]

The server can be cusomtized in the same way as that described in the "Configuring Apache" section. Here are the default nginx configuration files


To enable the buildpack debug mode you can set the BP_DEBUG environment variable to true using the following command. This will instruct the buildpack to set it's log level to DEBUG and write to stdout:


NOTE: If you enable debug logging it might include sensitive information like usernames, passwords, tokens, service info and file names from your application. Be careful where you post those logs and if necessary, redact any sensitive information first.

Additional Information

More information on deploying PHP applicatinos can be found in the Cloud Foundry Documentation.

Customer Support

Can’t find what you need?
Give us a call.


M – F, 8am to 6pm