LoginSignup
3
2

More than 5 years have passed since last update.

Heroku PHPのドキュメントルートを環境変数から指定する

Posted at

HerokuにてPHP環境を作成する際には、Procfileにて稼働するWebサーバの設定とドキュメントルートの設定を行う。
例:apacheを使ってドキュメントルートをhtdocsにする場合

web: vendor/bin/heroku-php-apache2 htdocs

このドキュメントルートの指定を環境変数から指定することが出来た。

環境変数から取得

Procfileの中で、$を使うと環境変数から取得することが可能。
例えば、DOC_ROOTという環境変数を指定した場合は、以下のようにすれば設定出来た。

web: vendor/bin/heroku-php-apache2 $DOC_ROOT

Heroku側の環境変数に設定しやる。

$ heroku config:set DOC_ROOT=htdocs

これでappごとに環境変数を変更してやるだけで環境変数の切り替えが出来た。

ヘルプ

ちなみに、vendor/bin/heroku-php-apache2 --helpのコマンドでヘルプが確認出来た。
コマンドから実行するにはherokuコマンドで実行してやる。

$ heroku run 'vendor/bin/heroku-php-apache2 --help'

Boots PHP-FPM together with Apache2 on Heroku and for local development.

Usage:
  heroku-php-apache2 [options] [<DOCUMENT_ROOT>]

Options:
   -C <httpd.inc.conf>     The path to the configuration file to include inside
                           the Apache2 VHost config (see option -c below). Will
                           be included inside the '<VirtualHost>' section just
                           after the '<Directory>' & 'ProxyPassMatch' directives.
                           Recommended approach when customizing Apache2's config
                           in most cases, unless you need to set fundamental
                           server level options.
                           [default: $COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/apache2/default_include.conf]
   -c <httpd.conf>         The path to the full VHost configuration file that is
                           included after Heroku's (or your local) Apache2 config
                           is loaded. Must contain a 'Listen ${PORT}' directive
                           and should have a '<VirtualHost>' and likely also a
                           '<Directory>' section (see option -C above).
                           [default: $COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/apache2/heroku.conf]
   -F <php-fpm.inc.conf>   The path to the configuration file to include at the
                           end of php-fpm.conf (see option -f below), in the
                           '[www]' pool section. Recommended approach when
                           customizing PHP-FPM's configuration in most cases,
                           unless you need to set global options.
   -f <php-fpm.conf>       The path to the full PHP-FPM configuration file.
                           [default: $COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/php/php-fpm.conf]
   -h, --help              Display this help screen and exit.
   -i <php.ini>            The path to the php.ini file to use.
                           [default: $COMPOSER_VENDOR_DIR/heroku/heroku-buildpack-php/conf/php/php.ini]
                           exist, it will be created. Wildcards are allowed, but
   -l <tailme.log>         Path to additional log file to tail to STDERR so its
                           contents appear in 'heroku logs'. If the file does not
                           Note: this option can be repeated multiple times.
                           must be quoted and must match already existing files.
   -p <PORT>               Port to listen on for HTTP traffic. If this argument
                           is not given, then the port number to use is read from
                           the $PORT environment variable, or a random port is
                           chosen if that variable does not exist.
   -v, --verbose           Be more verbose during startup.

 All file paths must be relative to '/app'.

 Any file name that ends in '.php' will be run through the PHP interpreter first.
 You may use this for templating although this is less useful than e.g. for Nginx
 where unlike in Apache2, you cannot reference environment variables in config
 files using a '${VARNAME}' syntax.

 If you would like to use the -C and -c or -F and -f options together, make sure
 you retain the appropriate include mechanisms (see default configs for details).

参考

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2