8

Obviously, I've Laravel project that really needs the .htaccess rules and Nginx doesn't seem to be the best solution for me,

1- my question is why Laravel didn't provide homestead with Apache! After a small research that I made I found online tool for converting the rules but the output didn't work (was too short), whereas, Apache is more likely known and usable, plus it's easier to define rules for security and pretty URLs ..etc. ( at least for me )

2- Please give me answers explaining why they choose Nginx!, more importantly I need to know what Seniors and Experts will use ( Nginx, Apache )

3- Do you advise me to install Apache on Homestead?

Mohamed Mo Kawsara
  • 4,400
  • 2
  • 27
  • 43
  • 1
    Step by step can be found [here](https://laracasts.com/discuss/channels/general-discussion/homestead-and-apache) – Matt Burrow Feb 24 '15 at 09:57

3 Answers3

8
  1. Laravel homestead is currently able to install apache using your Homestead.yaml file.

Add a key to your sites called type. Set it to apache. like so:

sites:
    - map: laravel.local
      to: "/home/vagrant/laravel"
      type: apache

Make sure you don't mix up apache and nginx, that won't work.

Then run vagrant up and to install apache and provision the right config files.

If it doesn't work, then first make sure to update to the latest version of homestead.

  1. Here is an interesting article on the matter: https://www.nginx.com/blog/nginx-vs-apache-our-view/. TLDR: Nginx is faster.

  2. Only when you have an existing project and you really need to use apache. Or in case your application is going to run on an apache server. Starting fresh? Use nginx.

Martijn Imhoff
  • 918
  • 1
  • 8
  • 22
  • 1
    That problem that was looking really complicated? I can solve it in 12 characters. – Rebecca Nov 22 '17 at 23:28
  • 1
    It boggles my mind that Laravel comes with .htaccess files and Homestead doesn't support them out of the box. This saved my bacon after an hour of searching. – Adam May 16 '19 at 23:04
6

Steps are as follows here.

  1. SSH into vagrant -> vagrant ssh

  2. Stop Nginx -> sudo service nginx stop

  3. Remove it -> sudo apt-get purge nginx

  4. Update you repos -> sudo apt-get update

  5. Install apache -> sudo apt-get install apache2

  6. Restart it -> sudo service apache2 restart

You are now on Apache server, update the apache conf file as your needs.

Matt Burrow
  • 10,477
  • 2
  • 34
  • 38
MartinJH
  • 2,590
  • 5
  • 36
  • 49
  • 1
    After doing this, I managed to configure `sites-available` and the `/home/vagrant/Code` as my Document Root. My problem now is that Apache is showing PHP code instead of executing it. After researching, I discovered it's because PHP is not enabled. Question is: how to enable PHP 5.6 onto Apache 2.4 just installed? – Marco Aurélio Deleu Feb 07 '16 at 01:35
  • @MarcoAurélioDeleu Try following the instructions from [this link.](http://vitalflux.com/php-install-apache-2-4-php-5-6-windows/). Otherwise I'd recommend asking your question as a standard SO question. – MartinJH Feb 07 '16 at 09:54
  • 2
    This answer, although valid, should not be taken as accepted to the question asked! – Brian Dec 22 '17 at 22:02
  • 1
    @BrianVanegasParra You are right. I'm not really answering any of the three questions, only how to configure laravel for apache. So the asker should feel free to give the check mark to any more appropriate answer. – MartinJH Dec 24 '17 at 14:40
  • This is not necessary, specifying "apache" as the server type in the Homestead.yaml file is enough. See @martijn-imhoff 's answer below for more details. – leopinzon Sep 04 '20 at 13:27
2

What exactly are you trying to do and perhaps we can supply a solution to your problem. You shouldn't really need to be rewriting URLs with .htaccess as Laravel's routing handles this.

1) Regardless of software, if you're needing to configure the webserver for each specific project, its probably better to go and configure your own vagrant box that is relevant for that project.

2) Nginx outperforms apache and reduces a lot of the bloat that simply isn't needed. Its also what forge uses and so homestead uses in turn so its mocking the forge environment.

3) See point 1, configure your own vagrant box for this project.

Wader
  • 9,427
  • 1
  • 34
  • 38