11

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.

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?

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

yaitloutou
  • 1,691
  • 19
  • 23
Wouter C
  • 533
  • 1
  • 6
  • 21

3 Answers3

26

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

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

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

vagrant destroy

3- then run

vagrant up

4- shh to the vagrant machine

vagrant ssh

5- flip the server, by running:

flip

you'll get this message:

nginx stopped
apache started

To test

I've created the directory Apache/public

mkdir -p Apache/public

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

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

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

yaitloutou
  • 1,691
  • 19
  • 23
  • 11
    are you sure it will not be enough to run `$ vagrant reload --provision`? – Yevgeniy Afanasyev Jul 25 '18 at 04:36
  • 2
    last time when I tested, it wasn't necessary to `destroy`/`up` after editing Homestead.yaml. but I'm not sure fore the current version of vagrant – yaitloutou Jul 25 '18 at 08:23
  • You are right. It is still needed `destroy / up` I tried both ways last night. – Yevgeniy Afanasyev Jul 25 '18 at 23:11
  • Unfortunately, the `flip` command doesn't do anything in my case. – markus Apr 01 '19 at 18:09
  • I had to install apache in the box myself then it worked – user163831 Apr 17 '20 at 23:27
  • Don't forget that ```destroy``` will remove all databases. Back them up first. Later versions of Homestead have an auto backup on destroy. https://laravel.com/docs/8.x/homestead#database-backups It's easy to miss this in the heat of the moment as the `Code` directory is on the 'real' machine. – liamvictor Aug 25 '21 at 17:15
3

Add type: apache to your homestead.yaml sites configuration, then realod the vagrant machine using vagrant reload --provision

sites:
    - map: homestead.test
      to: /home/vagrant/code/{path/to/laravel}/public
      type: "apache"

Learn more in laravel doc

jking
  • 194
  • 2
  • 9
2

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

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.

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

Will revise as I learn more.

Mike Ritter
  • 71
  • 1
  • 5