PHP
PHP language identification strategy
By default, the platform will identify a PHP project based on whether there areindex.php
files or composer.json
files in the source root directory.
Platform compile and run mechanism
- The pre-compilation process will detect whether the startup command configuration file Procfile is defined, if not, the default War package startup configuration file will be generated;
- 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;
- After the compilation is completed, it will check whether the Procfile parameter is set on the platform. If it is configured, the startup command configuration file Procfile will be rewritten.
# Install dependencies and resolve dependencies
composer install --no-dev --prefer-dist --optimize-autoloader --no-interaction
shell hook support
Make shell hook pair calls by configuring composer.json
{
"scripts": {
"pre-install-cmd": ["bash ./pre-install-cmd.sh"],
"post-install-cmd": ["bash ./post-install-cmd .sh"]
},
"require": {
"php": "7.1.21",
"ext-memcached": "*"
}
}
Among them, the definition content of pre-install-cmd
will be executed before install,the definition content of post-install-cmd
will be executed after install, and the definition script must be created in advance and given execution permission
PHP project source code specification
In this step, you need to provide a usable PHP source code program for deployment on the Rainbond platform. This application must at least meet the following conditions:
- Locally working PHP program
- The source code program must be hosted on a related git or svn service such as gitlab
- The php file must exist in the root directory of the source code program
- There must be
composer.json
in the root directory of the source code program, which is used to manage the dependencies of the PHP project and is also a necessary condition for Rainbond to recognize the PHP language. At the same time, the PHP version required by the project must be defined in the file. The definition method is described below. composer.lock
file must exist in the root directory of the source program project- The source program project root directory needs to define
Procfile
to define the program startup method
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 extend, you can customize the Procfile.
Composer file
The default source root directory requires composer.json
and composer.lock
files to exist, even if the application has no 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. Usually, the dependencies are installed in the vendor/
directory, but some projects will redefine this directory. Execute composer config vendor-dir
to configure the correct path.In most cases to avoid the impact of local installation, it is usually necessary to add the Composer vendor
directory to your `When verndor-dir is defined in composer.json, pay attention, you need to define your own Procfile, otherwise the application will fail Normal operation, the Procfile format is similar to
web: /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 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 versions can be specified through the composer.json file
{
"require": { "php": "5.6.35" }
}
The version of PHP supports ~5.5.35, which is 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 the 5.5.35 version will be selected.
Extended support
PHP 5.6
The following built-in extensions are automatically enabled on Rainbond (this list does not include extensions that PHP enables by default, such as DOM,JSON,PCRE or PDO):
- Bzip2
- cURL
- FPM
- mcrypt
- MySQL (PDO) (uses mysqlnd)
- MySQLi (uses mysqlnd)
- OPcache
- OpenSSL
- PostgreSQL
- PostgreSQL (PDO)
- Readline
- Sockets
- Zip
- Zlib
The following built-in extensions have been built as "shared" and can be enabled via composer.json (internal identifier name given in parentheses):
- BCMath (
BCMath
) - Calendar (
Calendar
) - Exif (
Exif
) - FTP (
ftp
) - GD (
gd
; with PNG, JPEG and FreeType support) - GMP (
gmp
) - gettext (
gettext
) - IMAP (
imap
; with SASL and Kerberos support) - intl (
intl
) - LDAP (
ldap
; with SASL support) - mbstring (
mbstring
) - MySQL (
mysql
; note that this extension is deprecated since PHP 5.5, please migrate to MySQLi or PDO) - pcntl (
pcntl
) - Shmop (
Shmop
) - soap (
soap
) - SQLite3 (
sqlite3
) - SQLite (PDO) (
pdo_sqlite
) - XMLRPC (
xmlrpc
) - XSL (
xsl
)
The following 3rd party extensions (internal identifier names given in parentheses) can be enabled via composer.json:
- APCu (
apcu
; provides an apc extension for compatibility with legacy software) - Blackfire (
Blackfire
) - Cassandra (
Cassandra
) - ev (
ev
) - event (
event
) - ImageMagick (
ImageMagick
) - 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 (
Phalcon
) - pq (
pq
) - rdkafka (
rdkafka
) - PHPRedis (
redis
)
PHP 7.0
The following built-in extensions are automatically enabled on Rainbond (this list does not include extensions that PHP enables by default, such as DOM,JSON,PCRE or PDO):
- Bzip2
- cURL
- FPM
- MySQL (PDO) (uses mysqlnd)
- MySQLi (uses mysqlnd)
- OPcache
- OpenSSL
- PostgreSQL
- PostgreSQL (PDO)
- Readline
- Sockets
- Zip
- Zlib
The following built-in extensions have been built as "shared" and can be enabled via composer.json (internal identifier name given in parentheses):
- BCMath (
BCMath
) - Calendar (
Calendar
) - Exif (
Exif
) - FTP (
ftp
) - GD (
gd
; with PNG, JPEG and FreeType support) - GMP (
gmp
) - gettext (
gettext
) - IMAP (
imap
; with SASL and Kerberos support) - intl (
intl
) - LDAP (
ldap
; with SASL support) - mbstring (
mbstring
) - mcrypt (
mcrypt
) - pcntl (
pcntl
) - Shmop (
Shmop
) - soap (
soap
) - SQLite3 (
sqlite3
) - SQLite (PDO) (
pdo_sqlite
) - XMLRPC (
xmlrpc
) - XSL (
xsl
)
The following 3rd party extensions (internal identifier names given in parentheses) can be enabled via composer.json:
- APCu (
apcu
; provides an apc extension for compatibility with legacy software) - Blackfire (
Blackfire
) - Cassandra (
Cassandra
) - ev (
ev
) - event (
event
) - ImageMagick (
ImageMagick
) - 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 (
Phalcon
) - pq (
pq
) - rdkafka (
rdkafka
) - PHPRedis (
redis
)
PHP 7.1
The following built-in extensions are automatically enabled on Rainbond (this list does not include extensions that PHP enables by default, such as DOM,JSON,PCRE or PDO):
- Bzip2
- cURL
- FPM
- MySQL (PDO) (uses mysqlnd)
- MySQLi (uses mysqlnd)
- OPcache
- OpenSSL
- PostgreSQL
- PostgreSQL (PDO)
- Readline
- Sockets
- Zip
- Zlib
The following built-in extensions have been built as "shared" and can be enabled via composer.json (internal identifier name given in parentheses):
- BCmath (
bcmath
) - Calendar (
Calendar
) - Exif (
Exif
) - FTP (
ftp
) - GD (
gd
; with PNG, JPEG and FreeType support) - GMP (
gmp
) - gettext (
gettext
) - IMAP (
imap
; with SASL and Kerberos support) - intl (
intl
) - LDAP (
ldap
; with SASL support) - mbstring (
mbstring
) - mcrypt (
mcrypt
) - pcntl (
pcntl
) - Shmop (
Shmop
) - soap (
soap
) - SQLite3 (
sqlite3
) - SQLite (PDO) (
pdo_sqlite
) - XMLRPC (
xmlrpc
) - XSL (
xsl
)
The following 3rd party extensions (internal identifier names given in parentheses) can be enabled via composer.json:
- APCu (
apcu
; provides an apc extension for compatibility with legacy software) - Blackfire (
Blackfire
) - Cassandra (
Cassandra
) - ev (
ev
) - event (
event
) - ImageMagick (
ImageMagick
) - 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 (
Phalcon
) - pq (
pq
) - rdkafka (
rdkafka
) - PHPRedis (
redis
)
Sample demo program
Examplehttps://github.com/goodrain/php-demo
Recommended reading
Custom Web Server and PHP Environment Procfile File Description