PHP
The Deploio PHP build environment uses the Paketo PHP buildpack on the paketo stack, and the Heroku PHP Cloud Native Buildpack on the heroku stack. See Buildpack Stacks for more information.
Example App
We have a basic Symfony app in our examples
repository. You can deploy it
with nctl:
- Heroku Stack
- Paketo Stack
nctl create application symfony \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=heroku-stack/php/symfony
nctl create application symfony \
--buildpack-stack=paketo \
--git-url=https://github.com/ninech/deploio-examples \
--git-sub-path=paketo-stack/php/symfony
Using Extensions
Paketo Stack
The Paketo PHP buildpack includes the Paketo php-dist buildpack which provides the PHP binary distribution. The built PHP binary distribution includes quite some extensions which can be used in your PHP application on Deploio. All of them are defined in separate yaml files per PHP version in the Paketo php-dist buildpack.
Currently it is not possible to use extensions which are not defined in the above mentioned files.
It is important to mention that none of the pre-built extensions gets loaded by
default (due to memory usage optimizations). You will either have to load them
via requirements in Composer or via custom *.ini files. Both approaches will
be explained in the following sections.
Loading Extensions via Composer
If you are using Composer as a package manager, you can specify extensions to
load through the composer.json file. For example, to load the bz2, curl and
zip extensions you can use the following content:
{
"require": {
"php": ">=8.1",
"ext-bz2": "*",
"ext-curl": "*",
"ext-zip": "*"
}
}
This is also documented in the official Composer documentation.
Loading Extensions via Custom .ini Files
If you are not using Composer, you can load extensions via custom *.ini files
located at <APP-ROOT>/.php.ini.d/*.ini in your application source code
repository. For example, to load the bz2, curl and zip extensions you could
create a file <APP-ROOT>/.php.ini.d/custom-extensions.ini with the following
content:
extension=bz2.so
extension=curl.so
extension=zip.so
Composer Platform Requirements
As the build and runtime containers are different on Deploio you may run into issues where you cannot build a project successfully due to platform requirements not being fulfilled by the build-time container. You can ignore these requirements using either
--build-env=BP_COMPOSER_INSTALL_OPTIONS="--ignore-platform-reqs"
which will ignore all build requirements, or you can scope it to specific extensions:
--build-env=BP_COMPOSER_INSTALL_OPTIONS="--ignore-platform-req=ext-mysqli"
When doing this you will see from the logs that the buildpack will still validate that the extensions you require are available in the runtime image, but that the build will no longer fail due to the build container missing extensions.
Heroku Stack
Extensions are declared in composer.json using the ext- prefix in the
require section. See the Heroku documentation on managing PHP
extensions for
the full reference.
{
"require": {
"ext-bcmath": "*",
"ext-gmp": "*"
}
}
Paketo Stack Configuration
The build process offers a few env variables to adjust it to your use-case. See the how to section of the documentation for all available variables.
Select a Web Server
By default, the PHP built-in web server will be used. For production use-cases we recommend using Apache or NGINX:
-
PHP Built-in Web Server
--build-env=BP_PHP_SERVER=php-server -
Apache HTTPD Web Server
--build-env=BP_PHP_SERVER=httpd -
NGINX Web Server
--build-env=BP_PHP_SERVER=nginx
Additionally, if required, the web server can be customized further by providing your own server-specific config file.
Configure the Web Directory
Some frameworks put the index.php in a separate directory like public
instead of the repository root. When the web server is HTTPD or NGINX, the web
directory defaults to htdocs. In any case, you can override the web directory
with a build env variable:
--build-env=BP_PHP_WEB_DIR=public
Heroku Stack Web Server Configuration
On the heroku stack, the web server is configured via a
Procfile in the root of your repository. See
the Heroku
documentation
for details.
Symfony
Paketo Stack
For Symfony to build without failure, the auto-scripts currently have to be disabled:
--build-env=BP_COMPOSER_INSTALL_OPTIONS=--no-scripts -o