PHP

PHP Language Recognition Strategy

By default, the platform will recognize it as a PHP project based on whether there is a index.php file or composer.json in the source root directory.

Platform Compilation and Operation Mechanism

  1. The pre-compilation process will detect whether the startup command configuration file Procfile is defined, and if not defined, it will generate the default War package startup configuration file;
  2. After the pre-compilation process is completed, the PHP buildpack will be selected according to the language type to compile the project. During the compilation process, the defined PHP version will be installed and related dependency packages will be installed;
  3. After the compilation is completed, it will be checked whether the Procfile parameter is set on the platform, and if it is configured, the startup command configuration file Procfile will be overwritten.
# Install dependency packages and resolve dependencies
composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction

PHP Project Source Code Specification

In this step, you need to provide a usable PHP source code program for deployment on the Kato platform. This application must at least meet the following conditions:

  1. Local PHP programs that can run normally
  2. The source code program must be hosted on related git or svn services such as gitlab
  3. A php file must exist in the root directory of the source code program
  4. composer.json must exist in the root directory of the source code program, which is used to manage the dependencies of the PHP project. It is also a necessary condition for Kato to recognize as the PHP language. At the same time, the PHP version required by the project must be defined in the file.
  5. The composer.lock file must exist in the root directory of the source code program project
  6. Procfile needs to be defined in the root directory of the source code program project to define the program startup mode
Procfile Specification

If the project does not define a Procfile file, the platform will generate a default Procfile to run PHP by default.

# apache (default)
web: vendor/bin/heroku-php-apache2
# nginx 
web: vendor/bin/heroku-php-nginx

The above is the default Procfile, if you need to expand, you can customize the Procfile.

Composer File

The default source code root directory needs to have composer.json and composer.lock files, even if the application does not have Composer dependencies, it must contain at least one empty ({}). composer.lock which can be generated by the following command

composer update --ignore-platform-reqs

PHP applications can use the dependencies installed by Composer. The dependencies are usually installed in the vendor/ directory, but some projects will redefine this directory and execute composer config vendor-dir to configure the correct path. In most cases, to avoid the impact of local installation, you usually need to add the Composer vendor directory to your .gitignore

Note that when vendor-dir is defined in composer.json, you need to define the Procfile yourself, otherwise the application will not run normally. The format of the Procfile is similar to web: <vendor-dir>/heroku/heroku-buildpack-php/bin/heroku -php-apache2

   "config" : {
        "vendor-dir": "lib/composer",
        "optimize-autoloader": true
    },

Compile and Run Environment Settings

The platform provides different PHP versions. You can use PHP, HHVM (PHP Code Compiler), or both at the same time to improve PHP performance through HHVM.

PHP Version Support
  • PHP 5.5.38 (5.5.38)
  • PHP 5.6.35 (5.6.35)
  • PHP 7.0.29 (7.0.29)
  • PHP 7.1.16 (7.1.16)

The above supported PHP or HHVM version can be specified through the composer.json file

{
	"require": {"php": "5.6.35"}
}

The PHP version supports ~5.5.35 in the form of Semantic Versioning. If the user specifies ~5.5.35, the system will select the highest version of the 5.5 branch from the platform, so it will choose Version 5.5.35.

Extended Support

PHP 5.6

The following built-in extensions are automatically enabled on Kato (this list does not include extensions enabled by PHP by default, such as DOM, [JSON](http://php .net/manual/book.json), PCRE or PDO):

The following built-in extensions have been built as “shared” and can be enabled via composer.json (the internal identifier name given in brackets):

The following third-party extensions can be enabled via composer.json (internal identifier names given in parentheses):

  • APCu (apcu; provides an apc extension for compatibility with legacy software)
  • Blackfire (blackfire)
  • Cassandra (cassandra)
  • ev (ev)
  • event (event)
  • ImageMagick (imagick)
  • memcached (memcached; built against a version of libmemcached with SASL support)
  • Mongo (mongo)
  • MongoDB (mongodb)
  • New Relic (newrelic; will automatically be enabled when the New Relic Add-On is detected during a build)
  • OAuth (oauth)
  • [Phalcon] (https://phalconphp.com/) (phalcon)
  • pq (pq)
  • rdkafka (rdkafka)
  • PHPRedis (redis)
PHP 7.0

The following built-in extensions are automatically enabled on Kato (this list does not include extensions enabled by PHP by default, such as DOM, [JSON](http://php .net/manual/book.json), PCRE or PDO):

The following built-in extensions have been built as “shared” and can be enabled via composer.json (the internal identifier name given in brackets):

The following third-party extensions can be enabled via composer.json (internal identifier names given in parentheses):

  • APCu (apcu; provides an apc extension for compatibility with legacy software)
  • Blackfire (blackfire)
  • Cassandra (cassandra)
  • ev (ev)
  • event (event)
  • ImageMagick (imagick)
  • memcached (memcached; built against a version of libmemcached with SASL support)
  • MongoDB (mongodb)
  • New Relic (newrelic; will automatically be enabled when the New Relic Add-On is detected during a build)
  • OAuth (oauth)
  • [Phalcon] (https://phalconphp.com/) (phalcon)
  • pq (pq)
  • rdkafka (rdkafka)
  • PHPRedis (redis)
PHP 7.1

The following built-in extensions are automatically enabled on Kato (this list does not include extensions enabled by PHP by default, such as DOM, [JSON](http://php .net/manual/book.json), PCRE or PDO):

The following built-in extensions have been built as “shared” and can be enabled via composer.json (the internal identifier name given in brackets):

The following third-party extensions can be enabled via composer.json (internal identifier names given in parentheses):

  • APCu (apcu; provides an apc extension for compatibility with legacy software)
  • Blackfire (blackfire)
  • Cassandra (cassandra)
  • ev (ev)
  • event (event)
  • ImageMagick (imagick)
  • memcached (memcached; built against a version of libmemcached with SASL support)
  • MongoDB (mongodb)
  • New Relic (newrelic; will automatically be enabled when the New Relic Add-On is detected during a build)
  • OAuth (oauth)
  • [Phalcon] (https://phalconphp.com/) (phalcon)
  • pq (pq)
  • rdkafka (rdkafka)
  • PHPRedis (redis)

Sample Demo Program

Example https://github.com/gridworkz/php-demo