带有 Apache 服务器的 Laravel Homestead

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41976235/
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 15:14:28  来源:igfitidea点击:

Laravel Homestead with Apache server

laravelapachevagranthomestead

提问by Wouter C

Last year, after being a long time user of a WAMP stack, I switched over to Homestead on Vagrant. For a non-Laravel development project, I am required to use Apache Server. I know that it is possible to install Apache server on Homestead and then add Virtual Hosts for each site, but this seems a bit impractical. The sites in the Homestead.yaml file work with Nginx but don't seem to work with Apache.

去年,在长期使用 WAMP 堆栈之后,我切换到 Vagrant 上的 Homestead。对于非 Laravel 开发项目,我需要使用 Apache Server。我知道可以在 Homestead 上安装 Apache 服务器,然后为每个站点添加虚拟主机,但这似乎有点不切实际。Homestead.yaml 文件中的站点适用于 Nginx,但似乎不适用于 Apache。

My questions are:

我的问题是:

  • Is there away of creating the Virtual Hosts automatically in Apache?
  • Is there another Vagrant box that would do this or that you can recommend for use with Apache?
  • Am I just missing something?
  • 是否可以在 Apache 中自动创建虚拟主机?
  • 是否有另一个 Vagrant box 可以做到这一点,或者您可以推荐与 Apache 一起使用?
  • 我只是错过了什么吗?

I'm kind of a noob in these things. Any help is greatly appreciated!

我在这些事情上有点菜鸟。任何帮助是极大的赞赏!

回答by yaitloutou

As for now, to make a site entry in Homestead.yaml file works with Apache2, you need to:

至于现在,要使 Homestead.yaml 文件中的站点条目适用于 Apache2,您需要:

1- Add the site to Homestead.yaml, with type: apacheas fellow

1- 将站点添加到Homestead.yamltype: apache作为同伴

sites:
    -
        map: homestead.test
        to: /home/vagrant/code/Laravel/public    
    -
        map: homestead.test
        to: /home/vagrant/code/Apache/public
        type: apache

2- go to the vagrant box directory, and run

2- 进入 vagrant box 目录,然后运行

vagrant destroy

3- then run

3-然后运行

vagrant up

4- shh to the vagrant machine

4-嘘到流浪机器

vagrant ssh

5- flip the server, by running:

5- 翻转服务器,运行:

flip

you'll get this message:

你会收到这条消息:

nginx stopped
apache started

To test

去测试

I've created the directory Apache/public

我已经创建了目录 Apache/public

mkdir -p Apache/public

then inside it, I've created the file index.php

然后在里面,我创建了文件 index.php

echo "<?php phpinfo();" > Apache/public/index.php

Which is accessible using the same IP address of the default homestead negix site

可以使用默认 homestead negix 站点的相同 IP 地址访问

回答by Mike Ritter

I'm still researching and figuring it out myself. The documentation is practically nonexistent, but see https://laravel.com/docs/master/homestead#adding-additional-sites

我仍在研究并自己弄清楚。该文档几乎不存在,但请参阅https://laravel.com/docs/master/homestead#adding-additional-sites

In particular:

特别是:

Site Types

Homestead supports several types of sites which allow you to easily run projects that are not based on Laravel. For example, we may easily add a Symfony application to Homestead using the symfony2 site type:

sites: - map: symfony2.app to: /home/vagrant/Code/Symfony/public type: symfony2 The available site types are: apache, laravel (the default), proxy, silverstripe, statamic, and symfony2.

网站类型

Homestead 支持多种类型的站点,让您可以轻松运行非基于 Laravel 的项目。例如,我们可以使用 symfony2 站点类型轻松地将 Symfony 应用程序添加到 Homestead:

站点: - 映射:symfony2.app 到:/home/vagrant/Code/Symfony/public 类型:symfony2 可用的站点类型有:apache、laravel(默认)、proxy、silverstripe、statamic 和 symfony2。

Also note: https://laracasts.com/discuss/channels/general-discussion/homestead-and-apache

另请注意:https: //laracasts.com/discuss/channels/general-discussion/homestead-and-apache

Will revise as I learn more.

随着我了解更多,将进行修改。