Managing PHP Web Servers
Last updated January 03, 2025
Table of Contents
Heroku supports Apache HTTPD 2.4 and Nginx as dedicated web servers. For testing purposes, users can also use PHP’s built-in web server, although it’s not recommended. To see available web server versions, see Heroku PHP Support Reference.
In the absence of a Procfile
entry for the “web” dyno type, the Apache Web server will be used together with the PHP runtime.
Apache
Apache interfaces with PHP-FPM via FastCGI using mod_proxy_fcgi
.
To start Apache together with PHP-FPM and correct settings, use the heroku-php-apache2
script:
web: heroku-php-apache2
By default, the root folder of your project will be used as the document root. To use a subdirectory, you can pass the name of a subfolder as the argument to the boot script, for example “public_html”:
web: heroku-php-apache2 public_html
You can use regular .htaccess
files to customize Apache’s behavior, for example for URL rewriting. For additional details on this and other options to customize settings for Apache, refer to the corresponding Dev Center article.
Nginx
Nginx interfaces with PHP-FPM via FastCGI.
To start Nginx together with PHP-FPM and correct settings, use the heroku-php-nginx
script:
web: heroku-php-nginx
By default, the root folder of your project will be used as the document root. To use a subdirectory, you can pass the name of a subfolder as the argument to the boot script, for example “public_html”:
web: heroku-php-nginx public_html
For additional details on different ways of customizing settings for Nginx, refer to the corresponding Dev Center article.
PHP Built-in Web server
For testing purposes, you can start PHP’s built-in Web server by using php -S 0.0.0.0:$PORT
as the entry for “web” in your Procfile
:
web: php -S ‘0.0.0.0:$PORT
The Procfile
must contain $PORT
in the line shown above. It’s used by Heroku at runtime to dynamically bind the web server instance to the correct port for the dyno.
It’s important to bind to all interfaces using 0.0.0.0
, otherwise Heroku’s routing won’t be able to forward requests to the web server!
You can also pass an alternative document root, or use a router script to process requests. For details, refer to the PHP project’s documentation for the built-in Web server.