Docs menu

PHP on Primcloud

How Primcloud detects a PHP app, builds it with Composer, and serves it with Apache or nginx.

On this page

Detection#

Primcloud builds your app as PHP when the root of your repo has a composer.json. Even an empty {} counts.

To use a different file, set the COMPOSER secret to its path (COMPOSER=app/composer.json); the lockfile is expected beside it (app/composer.lock).

If composer.json has dependencies in require, a composer.lock must be committed beside it, or the build fails. See Troubleshooting.

The build#

The build installs the PHP version and extensions your php and ext-* requirements ask for (see Runtime versions), along with Composer, Apache, and nginx. It then runs:

Terminal
composer install --no-dev --no-progress --no-interaction --optimize-autoloader

require-dev packages aren't installed, so tools like phpunit or phpstan don't ship with your app. Composer's own scripts, such as post-install-cmd, run as part of it; see Customizing the build.

Composer downloads and the installed PHP version are reused from your previous build when they haven't changed, so later builds skip most of the downloading.

Serving your app#

With no Procfile, Primcloud runs:

web: heroku-php-apache2

That serves your app with Apache and PHP-FPM from the repo root. Most apps set a document root in a Procfile:

Procfile
web: heroku-php-apache2 public/

To use nginx instead, change the command:

Procfile
web: heroku-php-nginx public/

Apache and nginx are both supported. Both listen on $PORT for you, size PHP-FPM to your formation's memory, and use index.php as the directory index. To add rewrites, headers, or other server config, see Customizing the build.

PHP-FPM logs a warning to stderr for any request that takes over 3 seconds, and stops any request still running after 30 seconds.

Workers and other processes go in the Procfile too, each becoming its own formation:

Procfile
web: heroku-php-nginx public/
worker: php artisan queue:work

php, composer, and anything in vendor/bin are on the PATH for every process. Your secrets are set as environment variables, along with PORT (5000) on web. A custom entrypoint in place of heroku-php-apache2 or heroku-php-nginx has to listen on $PORT itself.