Skip to content

PHP with Apache application runtime

Overview

PHP is a widely-used general-purpose scripting language that is especially suited for Web development and can be embedded into HTML.

The HTTP server is Apache 2, and the PHP code is executed by PHP-FPM.

Create your PHP application

To create a new PHP application, use the Clever Cloud Console or Clever Tools:

clever create --type php

Configure your PHP application

Mandatory needs

PHP runtime requires a working web application. The HTTP server is Apache 2 with PHP-FPM. If you need to serve files from a specific directory, set the CC_WEBROOT environment variable to its absolute path from the root of your project (e.g. /public). The deployment fails if this path is relative or contains ...

clever env set CC_WEBROOT /public

Build phase

Composer build is supported out of the box. If a composer.json file is present at the root of your repository, dependencies are installed automatically during the build phase.

PHP version

Set the CC_PHP_VERSION environment variable to one of the following versions.

Default VersionAccepted Versions
8 (8.5)5.6 (EOL)
7 (EOL)
7.1 (EOL)
7.2 (EOL)
7.3 (EOL)
7.4 (EOL)
8
8.0 (EOL)
8.1 (EOL)
8.2
8.3
8.4
8.5

The end-of-life (EOL) versions are marked as such.

All new PHP applications are created with a default CC_PHP_VERSION. You can change it whenever you want then redeploy your application to use the version you want. Only values based on the first two digits (X or X.Y, not X.Y.Z) are supported.

Custom PHP configuration

Most PHP settings can be changed using a .user.ini file.

If you want the settings to be applied to the whole application, you should put this file in your webroot. If you did not change it, then your webroot is the root of the repository.

If you put the .user.ini file in a subdirectory, settings will be applied recursively starting from this subdirectory.

You can review the available directives; all the PHP_INI_USER, PHP_INI_PERDIR, and PHP_INI_ALL directives can be set from within .user.ini.

Same configuration between PHP-CLI and PHP-FPM

.user.ini files are not loaded by the PHP CLI by default.

However, some PHP applications may want to check for the PHP-FPM configuration pre-requisites, post_max_size or upload_max_filesize values for example.

To load the PHP-FPM .user.ini file during a PHP-CLI process, in a hook, use the PHP_INI_SCAN_DIR environment variable to load the additional file.

Assuming the script runs at the root-folder of the application:

#!/usr/bin/env bash

export PHP_INI_SCAN_DIR=":."
php myscript.php

This appends the current directory while still loading the default configuration.

Note

The : at the beginning of the string is mandatory. It indicates defaults files must still load.

A specific .ini file can be loaded with:

#!/usr/bin/env bash

export PHP_INI_SCAN_DIR=":.php-configuration/"
php myscript.php

This loads every .ini files in the php-configuration/ directory.

Timezone configuration

All instances on Clever Cloud run in the UTC time zone. Handle your dates in UTC internally, and convert them to a time zone only when you read or display them.

Additionally, you can set PHP’s time zone setting with .user.ini. For instance, to use the french time zone, edit .user.ini to add this line:

date.timezone=Europe/Paris

This setting doesn’t change when CRON jobs run: to schedule them in a local time zone, add a CRON_TZ line to clevercloud/cron.json.

Memory limit

Clever Cloud configures PHP’s memory_limit directive, which limits how much memory each PHP script can allocate. For web requests, this limit applies independently within each PHP-FPM worker; memory is not reserved when workers start. Both the default limit and the maximum value accepted through MEMORY_LIMIT depend on the application’s available memory, which excludes memory reserved for the system:

FlavorDefault memory_limitMaximum MEMORY_LIMIT
Nano91 MiB358 MiB
XS161 MiB859 MiB
S249 MiB1683 MiB
M406 MiB3579 MiB
L658 MiB7523 MiB
XL1051 MiB15496 MiB
2XL1377 MiB23503 MiB
3XL1666 MiB31525 MiB

To change the limit, set MEMORY_LIMIT to a positive integer interpreted in MiB, without a unit suffix.

For example, to allow each PHP script to allocate up to 128 MiB:

clever env set MEMORY_LIMIT 128

If MEMORY_LIMIT exceeds the maximum value for the selected flavor, Clever Cloud keeps the automatically calculated limit and logs a warning during deployment. Clever Cloud also calculates the number of PHP-FPM workers automatically.

On XS and larger flavors, setting CC_CONFIGURATION_PM_MAX_CHILDREN can lower the calculated memory limit. On Nano, the platform always uses six workers. If you also set a valid MEMORY_LIMIT, it takes precedence over the adjustment based on the number of workers.

Session upload progress

Clever Cloud sets session.upload_progress.enabled to Off when it deploys your application, following the PHP security team recommendations. This setting only disables upload progress tracking in sessions: file uploads and multipart/form-data requests keep working.

Configuration reference

Frameworks and CMS

The following is the list of tested CMS by our team.

It’s quite not exhaustive, so it does not mean that other CMS can’t work on the Clever Cloud platform.

Others PHP frameworks tested on Clever Cloud:

  • Prestashop
  • Dokuwiki
  • Joomla
  • SugarCRM
  • Drupal
  • Magento
  • Status.net
  • Symfony
  • Thelia
  • Laravel
  • Sylius

Configure Monolog

A lot of frameworks (including Symfony) use Monolog to handle logging. The default configuration of Monolog doesn’t allow to log errors into the console.

Here is a basic configuration of Monolog to send your application’s logs into our logging system and access them into the Console:

monolog:
  handlers:
    clever_logs:
      type: error_log
      level: warning

You can change the level to whatever level you desire. For Symfony, the configuration file is app/config/config_prod.yml.

Laravel doesn’t need Monolog to retrieve logs via Clever console or Clever CLI. Here, ensure that you have the following line in config/app.php:

return [
    // …
    'log' => env('APP_LOG'),
    // …
];

Then, set APP_LOG=syslog as Clever application environment variable.

Monitor your application with New Relic

You can use New Relic to monitor your application on Clever Cloud.

Please refer to our New Relic documentation to configure it for your application.

Monitor your application with Blackfire

You can use Blackfire to monitor your application on Clever Cloud.

Please refer to our Blackfire documentation to configure it for your application.

ProxySQL

ProxySQL is a tool that acts like a proxy between your application and your MySQL add-on. Instead of connecting to your MySQL add-on, you can connect to the local ProxySQL and it will forward all your requests to your MySQL add-on.

This allows you to let ProxySQL take care of some interesting features like connection pooling or leader / follower setup.

You can learn more about ProxySQL on the dedicated documentation page

Go Further

Last updated on