在Mac OS X上使用PHP的Heroku Local [英] Heroku Local with PHP on Mac OS X

查看:81
本文介绍了在Mac OS X上使用PHP的Heroku Local的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当前,除了始终在线的apache代理到php-fpm之外,我仅使用其他终端选项卡来手动启动工作进程和时钟进程.

当我从heroku开始时,我尝试了heroku local,但是它的设置击败了我.

现在我想再尝试一次.

我和homebrew php一起在High Sierra上工作,但至今仍坚持使用Apache内置的Mac OS.看来Brew的apache可能是一个更好的选择,但希望我们会在下面找到.

我从提供的答案中意识到此处(由buildpack贡献最大的人员),必须在启动heroku local时停止heroku local使用的apache.在此处中,来自heroku支持对此也有类似的表述. /p>

我还注意到,我自己的发现是,应该像composer require-dev heroku/heroku-buildpack-php "*"一样使用*在本地安装buildpack,以确保最新版本.

现在,当我使用mac osx的内置apache发行heroku local时,我得到以下信息(我让它监听端口8080来为我的php开发环境提供服务,但是出于此目的,使用sudo apachectl stop停止了它).

 m$ heroku local
[OKAY] Loaded ENV .env File as KEY=VALUE Format
12:21:03 PM horizon.1 |  Horizon started successfully.
12:21:03 PM clock.1  |  [2019-09-20 11:21:03] Calling scheduler
12:21:03 PM clock.1  |  No scheduled commands are ready to run.
12:21:03 PM web.1    |  DOCUMENT_ROOT changed to 'public/'
12:21:04 PM web.1    |  4 processes at 128MB memory limit.
12:21:04 PM web.1    |  Starting php-fpm...
12:21:06 PM web.1    |  Starting httpd...
12:21:06 PM web.1    |  Application ready for connections on port 5000.
12:21:06 PM web.1    |  [Fri Sep 20 12:21:06.155117 2019] [core:emerg] [pid 25867] (2)No such file or directory: AH00023: Couldn't create the mpm-accept mutex (file /private/var/run/mpm-accept-0.25867)
12:21:06 PM web.1    |  (2)No such file or directory: could not create accept mutex
12:21:06 PM web.1    |  AH00015: Unable to open logs
12:21:06 PM web.1    |  Process exited unexpectedly: httpd
12:21:06 PM web.1    |  Going down, terminating child processes...
[DONE] Killing all processes with signal  SIGINT
12:21:06 PM horizon.1 |  Shutting down...
12:21:06 PM clock.1  Exited with exit code SIGINT
12:21:06 PM web.1    Exited with exit code null
12:21:07 PM horizon.1 |  [2019-09-20 11:21:06][1033] Processing: Laravel\Scout\Jobs\MakeSearchable
12:21:07 PM horizon.1 |  [2019-09-20 11:21:06][1032] Processing: Laravel\Scout\Jobs\MakeSearchable
12:21:07 PM horizon.1 |  [2019-09-20 11:21:06][1034] Processing: Laravel\Scout\Jobs\MakeSearchable
12:21:08 PM horizon.1 |  [2019-09-20 11:21:06][1033] Processed:  Laravel\Scout\Jobs\MakeSearchable
12:21:08 PM horizon.1 |  [2019-09-20 11:21:06][1032] Processed:  Laravel\Scout\Jobs\MakeSearchable
12:21:08 PM horizon.1 |  [2019-09-20 11:21:06][1034] Processed:  Laravel\Scout\Jobs\MakeSearchable
12:21:08 PM horizon.1 Exited Successfully
 

我的mac os apache虚拟主机转发到/tmp/php72-fpm.sock.本地浏览器中的apache达到php-fpm的权限就可以了.

我看到实际的错误是(由于没有换行,它在上面的代码中滚动到了右边):Could not create the mpm-accept mutex.我现在知道有几个不同的apache多处理模块,不确定我是否需要了解更多.

但这很可能只是权限?我注意到mac osx apache需要sudo,就像在sudo apachectl start中一样,并且我在没有sudo的情况下运行heroku local.我可以尝试sudo heroku local,但宁愿等到我知道它会做什么之后.

因此,在这里没有更多了解(这会很好),我可能会尝试安装brew apache(httpd24).看来heroku local只会调用httpd,因此,路径中的第一个将被拾取.

部分答案

我意识到,当heroku local启动系统apache时,系统apache当然仍将具有其所有当前配置.这意味着写入我添加的sudo位置,错误日志,虚拟主机.当然,没有sudo将会出错.解决上述问题的第一步是从httpd.conf中删除listen指令,这产生了一个新错误:

 (13)Permission denied: AH00091: httpd: could not open error log file /private/var/log/apache2/error_log.
 

因此,我随后注释掉了错误日志以修复该错误日志,从而修复了另一个错误:

 (2)No such file or directory: AH02291: Cannot access directory '/usr/logs/' for main error log
2:17:25 PM web.1    |  AH00014: Configuration check failed
2:17:25 PM web.1    |  This program requires Apache 2.4.10 or newer with mod_proxy and mod_proxy_fcgi enabled; check your 'httpd' command.

 

可以看到前进的方向. 基本上,我将需要删除几乎所有的Mac osx apache配置,以免出错(在没有sudo的情况下启动).

所以,让我们考虑酿造apache ...(如下).

值得注意的是,检查/tmp时,每次我运行heroku local时,都会看到以下文件,例如heroku.xxxxx,写为零字节以下.我注意到,下面的apache日志文件可以作为中buildpack的默认虚拟主机中的Log指令找到,因此它们存在于此.

 mbp:tmp m$ ll
total 8
drwxrwxrwt@ 16 root  wheel   512B 20 Sep 08:54 ./
drwxr-xr-x   6 root  wheel   192B 31 Dec  2017 ../
srwxrwxrwx   1 root  wheel     0B 18 Sep 22:02 .dbfseventsd=
srwxrwxrwx   1 m     wheel     0B 20 Sep 07:59 .s.PGSQL.5432=
-rw-------   1 m     wheel    49B 20 Sep 07:59 .s.PGSQL.5432.lock
srwxr-xr-x   1 m     wheel     0B  8 Sep 21:05 OSL_PIPE_501_SingleOfficeIPC_48607cb6b283d6f2d9ab5973acdb43c=
drwx------   3 m     wheel    96B 27 Aug 17:28 com.apple.launchd.9wuyYAXuof/
drwx------   3 m     wheel    96B 27 Aug 17:28 com.apple.launchd.v9lh33yWhI/
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.apache2_access.5000.log
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.apache2_error.5000.log
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.php-fpm.5000.log
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.php-fpm.5000.www.slowlog
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.php-fpm.www.5000.log
drwxr-xr-x   3 m     wheel    96B 19 Sep 20:23 pear/
srwxrwxrwx   1 m     staff     0B 19 Sep 22:11 php72-fpm.sock=
drwxr-xr-x   2 root  wheel    64B 19 Sep 08:29 powerlog/
 

我还能做些什么来帮助网络进程加速运行?

更新-如何安装heroku本地专用的brew apache?

也许真正有用的是知道安装brew apache的步骤,因为它将仅用于heroku local.它是一些简单的brew命令,并删除了listen指令吗?我在这里非常谨慎,因为在理想情况下,我希望不损害我对内置apache的使用;我认为它们应该能够并排运行,只需要在执行之前一定要有把握就可以了.

Homebrew现在不再支持公式选项,因此brew install homebrew/apache/httpd24 --with-mpm-event解决方案

我在此处发布部分答案,我会在发现更多内容时对此进行更新,而不是将此进一步的信息附加到问题本身.

我将其与Brew apache配合使用,如下所示:

brew install httpd

编辑/usr/local/etc/httpd/httpd.conf:

  • 注释第Listen 8080
  • LoadModule proxy_module lib/httpd/modules/mod_proxy.so 行中的注释 LoadModule proxy_fcgi_module lib/httpd/modules/mod_proxy_fcgi.so 行中的注释
  • 在ServerName中添加注释,我将其设置为ServerName localhost:5000 (这会抑制抱怨,这是ServerName的正确值吗?)

编辑/usr/local/etc/httpd/extra/httpd-ssl.conf如下:

  • 注释Listen 8443

请勿像通常为冲泡服务那样使用brew services start httpd,在这里与我们无关. (现在我们注释掉了Listen指令,无论如何httpd都不会响应, 直到heroku local将其启动并注入 Listen指令).

有一个我还不完全了解的领域. 现在,我在本地运行heroku时,可以通过localhost:5000访问我的站点,但只能访问首页.单击任何子页面将返回:

 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body></html>
 

也许我们以后可以解决这个问题.但是让我们现在考虑php-fpm.

首先,我有一个容易修复的错误,即heroku local使用的是Mac osx的php-fpm(High Sierra上的7.1版),我通过确保php7.2公式(仅桶)来解决此问题.很快就会迁移到php7.3). 现在which php-fpm返回/usr/local/opt/php@7.2/sbin/php-fpm而不是/usr/sbin/php-fpm(内置mac osx).因此,现在我们使用了想要的版本.小而重要的修复程序.

但是,我们现在必须考虑在heroku本地调用(即启动)php-fpm时会发生什么.传统上,我会执行brew services start php@7.2,它始终处于(守护程序)状态.但是,在活动监视器打开的情况下,我看到heroku local产生了一个新的父进程和工作进程.也许就是这样.它只是忽略brew services运行的实例,并创建自己的实例.

当我通过按Ctrl-C退出Heroku local时,就会出现一个谜.那是退出它的正确方法吗?如果我按Ctrl-C,则会返回命令提示符,但是,查看活动监视器中生成的php-fpm进程,不会终止php-fpm实例.然后,如果在第一次停止后再次发出heroku local,我会得到:

 5:44:37 PM web.1    |  [20-Sep-2019 17:44:37] ERROR: An another FPM instance seems to already listen on /tmp/heroku.fcgi.5000.sock
5:44:37 PM web.1    |  [20-Sep-2019 17:44:37] ERROR: FPM initialization failed
 

...这是可以理解的.这可以通过在活动监视器中手动终止该过程来解决.但是,我不知道这里发生了什么.终止heroku local的正确方法是什么?

具体来说,Ctrl-C退出具有节点父进程的单个php进程,但不退出五个php-fpm进程,这五个进程之一是其他四个进程的父进程,而其中一个具有一个父进程. bash的父进程.

所以,今天我们走了很长一段路.剩下的问题似乎是;仍有待改进:

  1. 如何正确终止php-fpm进程(Ctrl-C不能执行). 另外,如果我打开了两个终端,一个以前在本地运行过heroku, 然后在另一个窗口中再次运行它,该窗口显示了常规命令 提示等待指令,突然跳回生活,收到新的 信息,这是一个令人惊讶的事情,我想知道它是如何工作的,是否 那被认为是正常的.

  2. 找出为什么如上所述,apache无法提供除root用户之外的任何页面.

它有效!

现在我们在开车!我在/usr/local/etc/httpd/httpd.conf中忽略的一项重要更改是在以下行中进行注释:

LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

我正在使用laravel,它通过index.php服务所有页面.这意味着您希望将不将index.php的每个页面请求改写回index php.因此,laravel中的默认.htaccess具有RewriteRule ^ index.php [L]行,即可完成此操作...

现在,我目前所知道的唯一剩下的问题是Ctrl-C不会终止子进程....但是首先,我将所有本地应用程序都设置为使用fpm 7.3,如我所见,在buildpack中专门针对7.3进行引用,因此想知道这是否有帮助...

Currently I just use additional terminal tabs to manually start worker and clock processes in addition to an always-on apache proxying to php-fpm.

I tried heroku local when I started with heroku but its setup defeated me.

Now I want to give it another try.

I'm on High Sierra with homebrew php but have stuck with the mac os built in apache till now. It appears brew's apache may be a better choice but hopefully we'll find out if so in the following.

I realise from the answer provided here (by the top contributor to the buildpack) that the apache used by heroku local must be stopped at the time heroku local is started. There's a similar apparent quote from heroku support about this in an answer here.

I also note, my own discovery, that one should install the buildpack locally with * as in composer require-dev heroku/heroku-buildpack-php "*" to ensure the latest version.

Right now I get the following when I issue heroku local, using mac osx's built-in apache (I have it listening on port 8080 to serve my php dev environments, but stopped it for the purpose of this, with sudo apachectl stop).

m$ heroku local
[OKAY] Loaded ENV .env File as KEY=VALUE Format
12:21:03 PM horizon.1 |  Horizon started successfully.
12:21:03 PM clock.1  |  [2019-09-20 11:21:03] Calling scheduler
12:21:03 PM clock.1  |  No scheduled commands are ready to run.
12:21:03 PM web.1    |  DOCUMENT_ROOT changed to 'public/'
12:21:04 PM web.1    |  4 processes at 128MB memory limit.
12:21:04 PM web.1    |  Starting php-fpm...
12:21:06 PM web.1    |  Starting httpd...
12:21:06 PM web.1    |  Application ready for connections on port 5000.
12:21:06 PM web.1    |  [Fri Sep 20 12:21:06.155117 2019] [core:emerg] [pid 25867] (2)No such file or directory: AH00023: Couldn't create the mpm-accept mutex (file /private/var/run/mpm-accept-0.25867)
12:21:06 PM web.1    |  (2)No such file or directory: could not create accept mutex
12:21:06 PM web.1    |  AH00015: Unable to open logs
12:21:06 PM web.1    |  Process exited unexpectedly: httpd
12:21:06 PM web.1    |  Going down, terminating child processes...
[DONE] Killing all processes with signal  SIGINT
12:21:06 PM horizon.1 |  Shutting down...
12:21:06 PM clock.1  Exited with exit code SIGINT
12:21:06 PM web.1    Exited with exit code null
12:21:07 PM horizon.1 |  [2019-09-20 11:21:06][1033] Processing: Laravel\Scout\Jobs\MakeSearchable
12:21:07 PM horizon.1 |  [2019-09-20 11:21:06][1032] Processing: Laravel\Scout\Jobs\MakeSearchable
12:21:07 PM horizon.1 |  [2019-09-20 11:21:06][1034] Processing: Laravel\Scout\Jobs\MakeSearchable
12:21:08 PM horizon.1 |  [2019-09-20 11:21:06][1033] Processed:  Laravel\Scout\Jobs\MakeSearchable
12:21:08 PM horizon.1 |  [2019-09-20 11:21:06][1032] Processed:  Laravel\Scout\Jobs\MakeSearchable
12:21:08 PM horizon.1 |  [2019-09-20 11:21:06][1034] Processed:  Laravel\Scout\Jobs\MakeSearchable
12:21:08 PM horizon.1 Exited Successfully

My mac os apache vhosts forward to /tmp/php72-fpm.sock. The permissions there are ok as apache in local browser reaches php-fpm fine.

I see that the actual error is (it scrolls off to the right in the code above due to no linebreak): Could not create the mpm-accept mutex. I now know there are a few different apache multi-processing modules, not sure if I need to know more about that.

But is that likely to just be permissions? I note mac osx apache needs sudo, as in sudo apachectl start and I am running heroku local without sudo. I could try sudo heroku local but would rather not until I know what it would do.

So in absence of more understanding here (which would be nice), I may trying installing brew apache (httpd24). It looks like heroku local will just call httpd, so, the one first in the path will be picked up.

Partial answer

I realised that when heroku local starts system apache, system apache will still have, of course, all of its current config. That means writing to sudo locations, error logs, vhosts which I have added. Of course, that's going to error without sudo. First step to fix the above was remove the listen directive from httpd.conf, which gave a new error:

(13)Permission denied: AH00091: httpd: could not open error log file /private/var/log/apache2/error_log.

So then I commented out errorlog to fix that one, which gave another:

(2)No such file or directory: AH02291: Cannot access directory '/usr/logs/' for main error log
2:17:25 PM web.1    |  AH00014: Configuration check failed
2:17:25 PM web.1    |  This program requires Apache 2.4.10 or newer with mod_proxy and mod_proxy_fcgi enabled; check your 'httpd' command.

Can see where this is going. Basically, I would need to remove almost all of my mac osx apaches configuration for it not to error (when started without sudo).

So, let's consider brew apache instead... (below).

Of note, examining /tmp, each time I run heroku local I see the following files like heroku.xxxxx written as below of zero bytes. I note that the apache log files below can be found as Log directives in the default vhost include in the buildpack, in <buildpack>/conf/apache2/heroku.conf, hence their existence here.

mbp:tmp m$ ll
total 8
drwxrwxrwt@ 16 root  wheel   512B 20 Sep 08:54 ./
drwxr-xr-x   6 root  wheel   192B 31 Dec  2017 ../
srwxrwxrwx   1 root  wheel     0B 18 Sep 22:02 .dbfseventsd=
srwxrwxrwx   1 m     wheel     0B 20 Sep 07:59 .s.PGSQL.5432=
-rw-------   1 m     wheel    49B 20 Sep 07:59 .s.PGSQL.5432.lock
srwxr-xr-x   1 m     wheel     0B  8 Sep 21:05 OSL_PIPE_501_SingleOfficeIPC_48607cb6b283d6f2d9ab5973acdb43c=
drwx------   3 m     wheel    96B 27 Aug 17:28 com.apple.launchd.9wuyYAXuof/
drwx------   3 m     wheel    96B 27 Aug 17:28 com.apple.launchd.v9lh33yWhI/
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.apache2_access.5000.log
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.apache2_error.5000.log
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.php-fpm.5000.log
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.php-fpm.5000.www.slowlog
-rw-r--r--   1 m     wheel     0B 20 Sep 08:54 heroku.php-fpm.www.5000.log
drwxr-xr-x   3 m     wheel    96B 19 Sep 20:23 pear/
srwxrwxrwx   1 m     staff     0B 19 Sep 22:11 php72-fpm.sock=
drwxr-xr-x   2 root  wheel    64B 19 Sep 08:29 powerlog/

What else can I do to help the web process spin up?

Update - how to install brew apache for exclusive use of heroku local?

Perhaps what could be really useful is to know steps to install brew apache given that it'll be only used for heroku local. Is it a few simple brew commands and remove the listen directive? I'm cautious here as I would like ideally not to harm my current use of built in apache; these should be able to run alongside one another I think, just need to be reasonably sure before I do it.

Also

Homebrew now no longer supports options on formulae, so the brew install homebrew/apache/httpd24 --with-mpm-event as given at the link above doesn't seem an option anymore. It is possible to do brew edit httpd24 to edit the formula directly; is that necessary? What are the correct install steps?

解决方案

I'm posting a partial answer here which I'll update as I find out more rather than append this further information to the question itself.

I got it working with brew apache as follows:

brew install httpd

Edit /usr/local/etc/httpd/httpd.conf:

  • comment out line Listen 8080
  • comment in line LoadModule proxy_module lib/httpd/modules/mod_proxy.so
  • comment in line LoadModule proxy_fcgi_module lib/httpd/modules/mod_proxy_fcgi.so
  • comment in ServerName, I set it to ServerName localhost:5000 (this suppresses a complaint it will make - is that a correct value for ServerName?)

Edit /usr/local/etc/httpd/extra/httpd-ssl.conf as follows:

  • comment out Listen 8443

Don't do brew services start httpd, as you normally would for a brew service, that isn't relevant to us here. (Now that we commented out the Listen directives, httpd won't respond anyway, until heroku local starts it up and injects a Listen directive).

There is one area I don't fully understand yet. When I run heroku local now, I can access my site at localhost:5000, but only the front page. Clicking on any subpage returns:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL was not found on this server.</p>
</body></html>

Perhaps we can fix that later. But let's consider php-fpm now.

Firstly, I had one easily fixable error, which is that heroku local was using mac osx's php-fpm (version 7.1 on my High Sierra), which I fixed by ensuring my php7.2 formula (which is keg only; I'll shortly move to php7.3) comes first in path. Now which php-fpm returns /usr/local/opt/php@7.2/sbin/php-fpm and not /usr/sbin/php-fpm (mac osx built in). So, now we got it using the version we intend. Small but important fix.

However, we now must consider what happens when heroku local calls (i.e. starts up) php-fpm. Traditionally, I do brew services start php@7.2, which is always on (daemon). However, with Activity Monitor open, I see that heroku local spawns a new parent process and workers. Perhaps that's how it should be. It simply ignores the instance which is run by brew services, and creates its own.

The mystery arises though when I exit Heroku local by pressing Ctrl-C. Is that the correct way to exit it? If I do Ctrl-C, I get the command prompt back, but, looking at the spawned php-fpm processes in Activity Monitor, the php-fpm instances are not terminated. Then, if I issue heroku local a second time after stopping it the first, I get this:

5:44:37 PM web.1    |  [20-Sep-2019 17:44:37] ERROR: An another FPM instance seems to already listen on /tmp/heroku.fcgi.5000.sock
5:44:37 PM web.1    |  [20-Sep-2019 17:44:37] ERROR: FPM initialization failed

... which is quite understandable. That is fixable by manually terminating the process in Activity Monitor. However, I wonder what's happening here; what's the correct way to terminate heroku local?

To be specific, Ctrl-C quits a single php process which has a parent process of node, but does not quit five php-fpm processes, one of those five being the parent of the other four, and that one having a parent process of bash.

So, we've come a long way today; remaining issues seem to be; still to improve upon:

  1. How to correctly terminate the php-fpm process (Ctrl-C doesn't do it). Also if I have two terminals open, one which previously ran heroku local, and I run it again in another window, the window which showed a regular command prompt waiting for an instruction, suddenly jumps back to life, receives new information, which is a but surprising, I wonder how that's working and if that's considered normal.

  2. Find out why apache isn't serving any page other than root as noted above.

It works!

Now we are motoring! The one important change I ommited in /usr/local/etc/httpd/httpd.conf was to comment in the line:

LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so

I'm using laravel which serves all pages via index.php. That means you want to rewrite every page request that is not to index.php back to index php. Thus, the default .htaccess in laravel has the line RewriteRule ^ index.php [L] which does just that...

Now the only problem remaining that I'm currently aware of is that Ctrl-C doesn't terminate child processes.... but first I'm gonna set all my local apps to use fpm 7.3, as I saw a reference in the buildpack specifically to 7.3, so wondering if that might help...

这篇关于在Mac OS X上使用PHP的Heroku Local的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆