Laravel Homestead php-7 "php5-fpm: unrecognized service" on vagrant up

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/33791261/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 12:43:10  来源:igfitidea点击:

Laravel Homestead php-7 "php5-fpm: unrecognized service" on vagrant up

phplaravelhomesteadphp-7

提问by u1581544

Whilst trying to use the php-7 version of Laravel Homestead in a per-project installation, I see this error during vagrant up:

在每个项目安装中尝试使用 Laravel Homestead 的 php-7 版本时,我在以下期间看到此错误vagrant up

php5-fpm: unrecognized service

php5-fpm: unrecognized service

I've tried vagrant destroyand reinstalling the Vagrant box, but it still comes back to this error.

我试过vagrant destroy并重新安装了 Vagrant 盒子,但它仍然回到这个错误。

I didn't get the error when using Homestead globally.

在全球范围内使用 Homestead 时我没有收到错误消息。

How might this be fixed?

如何解决这个问题?

回答by u1581544

The issue was that whilst box: laravel/homestead-7was set correctly in Homestead.yaml, the composer dependency for laravel/homesteadwas still using the php-5 version. This meant that the provisioning scripts for Vagrant in vendor/laravel/homesteadwere those for php-5 and not php-7.

问题是,虽然box: laravel/homestead-7是在正确设置Homestead.yaml,为作曲家的依赖laravel/homestead仍然使用PHP-5版本。这意味着 Vagrant in 的配置脚本vendor/laravel/homestead是用于 php-5 而不是 php-7 的脚本。

That can be fixed by using a specific branch of laravel/homesteadfor the composer dependency.

这可以通过使用laravel/homesteadComposer 依赖项的特定分支来解决。

In composer.json, add a custom repository for laravel/homestead:

在 中composer.json,添加一个自定义存储库laravel/homestead

"repositories": [
    {
        "type": "git",
        "url": "https://github.com/laravel/homestead"
    }
]

And require the php-7branch specifically for laravel/homestead:

并要求php-7分支专门用于laravel/homestead

"require-dev": {
    "laravel/homestead": "dev-php-7"
}

Then composer updateand re-provisioning the Vagrant box will fix the issue.

然后composer update重新配置 Vagrant box 将解决这个问题。

UPDATE

更新

laravel/homesteadnow has PHP 7.0 by default, and the old php-7branch no longer exists. To resolve this issue, you simply need to update to the latest version of laravel/homesteadvia composer.json.

laravel/homestead现在默认有 PHP 7.0,旧php-7分支不再存在。要解决此问题,您只需更新到最新版本的laravel/homesteadvia composer.json

回答by Bluesail20

For a quick fix, I found this answer from laracastsvery helpful:

为了快速修复,我发现laracasts 的这个答案非常有帮助:

cd ~/Homestead && git pull && vagrant destroy && vagrant box update && vagrant up

回答by William Turrell

To elaborate a bit more on the "just destroy it and build again" approach... I favour this over the various instructions for in-place Homestead upgrades from PHP 5.6 to PHP 7 that are floating around the web - it doesn't take very long and also everything feels "cleaner" when you've finished.

详细说明“只是销毁它并重新构建”方法......我更喜欢这一点,而不是在网上漂浮的从 PHP 5.6 到 PHP 7 的就地 Homestead 升级的各种说明 - 它不需要很长,而且当你完成时,一切都感觉“更干净”了。

(Of course, if you've made changes to your php.ini or any of the other software, you'll need to do these again.)

(当然,如果您对 php.ini 或任何其他软件进行了更改,则需要再次执行这些操作。)

Preparation

准备

  • your projects should in a directory on your host computer that's shared with the Vagrant box, not on Vagrant box only, as that's about to be wiped
  • vagrant ssh into your VM and put a mysqldump of each site's database in the site directory, e.g. mysqldump -u root -p [dbname] > [dbname]-backup.sql(the default homestead MySQL root pw is secret.)
  • take a backup of everything (e.g. Mac Time Machine and/or do what I do and keep your projects in a Dropbox folder). You've got your git repository stored somewhere safely too, of course?
  • Virtualbox users: no harm in exporting the entire box in case you get stuck and want to go bac to it (taking a snapshot isn't enough as any will also be wiped when the VM is destroyed.)
  • 您的项目应该在与 Vagrant box 共享的主机上的目录中,而不是在 Vagrant box 上,因为它即将被擦除
  • vagrant ssh 进入您的 VM 并将每个站点的数据库的 mysqldump 放在站点目录中,例如mysqldump -u root -p [dbname] > [dbname]-backup.sql(默认的 homestead MySQL 根密码是secret.)
  • 备份所有内容(例如 Mac Time Machine 和/或做我所做的并将您的项目保存在 Dropbox 文件夹中)。当然,您的 git 存储库也安全地存储在某个地方吗?
  • Virtualbox 用户:导出整个盒子没有坏处,以防万一你卡住了并想回到它(拍摄快照是不够的,因为当 VM 被破坏时,任何也会被擦除。)

Process

过程

  • vagrant halt(if you haven't already)
  • vagrant destroy [VM id]Adding the ID is a precaution against destroying the wrong box. Use vagrant global-statusto get a list of your boxes; use 7-character hex code in first column.
  • in ~/Homestead on your host PC/Mac git pull origin master(as mentioned in the other answer, there's no separate PHP7 branch now)
  • you canre-run the bash script to create a clean Homestead.yaml file etc. - bash init.sh, but the files it copies are all templates, so you can also not do this and keep your previous versions.
  • vagrant box add laravel/homestead(now we're back on the standard installation instructions. This'll take about 10 minutes on a VDSL connection.
  • edit ~/.homestead/Homestead.yaml on your Mac/PC.
  • vagrant halt(如果你还没有)
  • vagrant destroy [VM id]添加 ID 是防止损坏错误框的预防措施。使用vagrant global-status让您的邮箱的列表; 在第一列中使用 7 个字符的十六进制代码。
  • 在主机 PC/Mac 上的 ~/Homestead 中git pull origin master(如另一个答案中所述,现在没有单独的 PHP7 分支)
  • 可以重新运行 bash 脚本以创建一个干净的 Homestead.yaml 文件等 - bash init.sh,但它复制的文件都是模板,因此您也可以不这样做并保留以前的版本。
  • vagrant box add laravel/homestead(现在我们回到标准安装说明。在 VDSL 连接上这大约需要 10 分钟。
  • 在 Mac/PC 上编辑 ~/.homestead/Homestead.yaml。

Here's an example of the folder mapping if you're confused by the docs:

如果您对文档感到困惑,这里有一个文件夹映射示例:

folders:
    - map: ~/Dropbox/websites-homestead
      to: /home/vagrant/sites

sites:
    - map: site1.app
      to: /home/vagrant/sites/site1/public
    - map: site2.app
      to: /home/vagrant/sites/site2/public

databases:
    - site1
    - site2

So... my actual code lives in ~/Dropbox/websites-homestead/site1 and /site2 on my computer, and I've mapped their common parent directory to /home/vagrant/sites on the VM. Homestead will create empty databases with the name(s) you list.

所以...我的实际代码位于我计算机上的 ~/Dropbox/websites-homestead/site1 和 /site2 中,并且我已将它们的公共父目录映射到 VM 上的 /home/vagrant/sites。Homestead 将使用您列出的名称创建空数据库。

  • vagrant up(this'll provision it)
  • vagrant ssh
  • cd sites(you should be able to see your code)
  • restore databases with `mysql -u root -p site1 < site1-backup.sql
  • Providing you have /etc/hosts entries on your computer, you should be able to view your site. Check the .env file if it can't connect to the database.
  • vagrant up(这将提供它)
  • vagrant ssh
  • cd sites(你应该能够看到你的代码)
  • 使用`mysql -u root -p site1 < site1-backup.sql 恢复数据库
  • 如果您的计算机上有 /etc/hosts 条目,您应该能够查看您的站点。如果无法连接到数据库,请检查 .env 文件。

You should now be able to do this:

你现在应该能够做到这一点:

$sudo service php7.0-fpm status
* php-fpm7.0 is running

$php -v
PHP 7.0.2-4+deb.sury.org~trusty+1 (cli) ( NTS )
[...]

回答by Reynaldo Roselló Nú?ez

open /etc/nginx/sites-available/your_site_confthen change this line:

打开/etc/nginx/sites-available/your_site_conf然后更改这一行:

fastcgi_pass: /var/run/php5-fpm.sock;

to:

到:

fastcgi_pass: /var/run/php/php7.0-fpm.sock;

And then restart nginx.

然后重启nginx。

Note: This is not a permanent solution, if you run provision command vagrant will try to setting up by itself and will overwrite with the first line.

注意:这不是一个永久的解决方案,如果您运行配置命令 vagrant 将尝试自行设置并覆盖第一行。