Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Heroku PHP “Getting Started” doesn’t run locally on OSX

Tags:

php

macos

heroku

I’m trying to get this repository to run locally on OSX 10.11.1 (Capitan)

https://github.com/heroku/php-getting-started.git

with the following command

$ sudo heroku local web

but I only get so far

[OKAY] Loaded ENV .env File as KEY=VALUE Format
[OKAY] Trimming display Output to 151 Columns
17:30:30 web.1 |  DOCUMENT_ROOT changed to 'web/'
17:30:30 web.1 |  4 processes at 128MB memory limit.
17:30:30 web.1 |  Starting php-fpm...
17:30:32 web.1 |  Starting httpd...
17:30:32 web.1 |  Application ready for connections on port 8080.
17:30:32 web.1 |  (13)Permission denied: AH00072: make_sock: could not bind to address [::]:80
17:30:32 web.1 |  (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
17:30:32 web.1 |  no listening sockets available, shutting down
17:30:32 web.1 |  AH00015: Unable to open logs
17:30:32 web.1 |  Process exited unexpectedly: httpd
17:30:32 web.1 |  Going down, terminating child processes...
[DONE] Killing all processes with signal  null
17:30:32 web.1 Exited Abnormally

Any ideas what could cause the permission denied errors on setting :80 even though I sudo? Or why does heroku local try to use port 80 anyway?

When deployed to heroku everything runs fine.

Here is the full tutorial: https://devcenter.heroku.com/articles/getting-started-with-php

edit

When I try to set a port manually with

$ heroku local web -p 5000

it just changes the default 8080 to 5000 ...

[OKAY] Loaded ENV .env File as KEY=VALUE Format
[OKAY] Trimming display Output to 151 Columns
08:06:33 web.1 |  DOCUMENT_ROOT changed to 'web/'
08:06:33 web.1 |  4 processes at 128MB memory limit.
08:06:33 web.1 |  Starting php-fpm...
08:06:35 web.1 |  Starting httpd...
08:06:35 web.1 |  Application ready for connections on port 5000.
08:06:35 web.1 |  (13)Permission denied: AH00072: make_sock: could not bind to address [::]:80
08:06:35 web.1 |  (13)Permission denied: AH00072: make_sock: could not bind to address 0.0.0.0:80
08:06:35 web.1 |  no listening sockets available, shutting down
08:06:35 web.1 |  AH00015: Unable to open logs
08:06:35 web.1 |  Process exited unexpectedly: httpd
08:06:35 web.1 |  Going down, terminating child processes...
[DONE] Killing all processes with signal  null
08:06:35 web.1 Exited Abnormally
like image 716
perelin Avatar asked Feb 08 '23 08:02

perelin


1 Answers

Because "heroku local" depends on predictable environments, it's not supported for PHP applications. Unlike with Ruby, Python, Node, Java etc, where the web server that listens for traffic is written in each of these respective languages, PHP applications start PHP-FPM (which already rules out e.g. Windows) together with Apache or Nginx.

A config to make that work is injected dynamically at start time, so you need a very standard PHP and Nginx (Debian etc will not work, for instance, since it doesn't even have working "nginx" or "httpd" binaries one can start). Only Nginx 1.8 is compatible; Apache needs a few modules (mod_proxy_fcgi mostly) enabled and must not bind to a local port.

That means there'd be a myriad of different customer-specific local setups Heroku would have to provide support for, so the best answer is "just set up a vhost for your app like you've always done and use e.g. https://packagist.org/packages/josegonzalez/dotenv for your env vars". That is, unfortunately, the state of web server setups in PHP at the moment.

In your specific case, Apache is starting, and it then loads its /etc/apache2/httpd.conf config, where it binds to port 80. This is not something the heroku-php-apache2 boot script can prevent, as it would have to ship a config that matches your specific environment, which is not possible, since it can't know all the aspects of your local system config, e.g. what modules to load, or where they even are - do they reside in /usr/libexec/apache2/, or /usr/local/apache2/modules/, or somewhere else? (Apache supports a multitude of directory layouts).

Solution

You can still try and get this working; it's fairly easy on Mac OS actually. I always use Apache from https://github.com/Homebrew/homebrew-apache (brew install homebrew/apache/httpd24 --with-mpm-event). In the global config (in /usr/local/etc/apache2/), enable mod_proxy and mod_proxy_fcgi, and comment out the Listen directive.

like image 85
dzuelke Avatar answered Feb 10 '23 10:02

dzuelke