Laravel Homestead: 403 forbidden on nginx - laravel

I just installed Laravel Homestead according to their instructions. When I open http://homestead.app:8000 I get the nginx 403 forbidden HTTP Response.
I have tried setting app/storage permissions to 755, but that didn't work, so I reloaded Vagrant. With no further result.
I also tried changing the nginx configuration, but with no success.

I had the same problem and for me the cause was that in the Homestead.yaml file, I have incorrectly put this:
sites:
- map: homestead.app
to: /home/vagrant/Code
Instead of the correct syntax:
sites:
- map: homestead.app
to: /home/vagrant/Code/path/to/public

Another reason for this response can be duplicating your routing with folders in public directory. For example you might have homestead.app/lists GET route and lists folder in your /public directory. This will cause the same 403 error (server will assume you are trying to access /public/lists directory instead of your /lists route).

OK, i got the answer to the question after few hours of searching and debugging.
The problem:
I've got GET route /admin
Also i've got /public/admin/ folder with assets inside.
And i've got 403 access denied from nginx cause of this duplication;
So, if you don't want to rename route or assets folder, all you need to do is replace
location / {
try_files $uri $uri/ /index.php?$query_string;
# ^^^^^
}
with this:
location / {
try_files $uri /index.php?$query_string;
}
If you could rename your route or assets folder without any refactor then you could do this without nginx config fixing.
Hope this will be helpful.

I have been banging my head against the wall dealing with this very same problem, and I just solved it for my case.
I was sure I'd set up the yaml file correctly, but I kept getting the 403 error, and when experimenting with some routes I was getting "input file not specified".
My solution came from http://laravel.com/docs/4.2/homestead and it involved using the serve command. I wasn't adding any additional sites, just trying to anything to get the first site running.
SSH'ing into my vagrant box and using the command "serve my_app_name.app /home/vagrant/Code/path/to/public" did the job. Note that I had already put an entry into my hosts file for this app.
Hope this helps someone.

For some people this may be as simple as having git cloned in an existing public folder, e.g:
- map: hello-world.dev
to: /home/vagrant/Code/Laravel/public/hello-world
The correct folder structure is:
- map: hello-world.dev
to: /home/vagrant/Code/hello-world/public
Another good note is ignoring the laravel docs on editing hosts file, using git shell, or cygwin (windows) to install vagrant hostsupdater, and simply adding entries for hosts and aliases to ~/.homestead/Homestead.yaml file.

I would suggest checking the nginx logs - use sudo tail /var/log/nginx/homestead.app-error.log

Here's the full solution steps:
run homestead edit
add /public to the end of your directory
sites:
- map: homestead.app
to: /full/path/to/the/laravel-app/public
run homestead halt && homestead up --provision

Change the config of Nginx
Put that line in 'location /' section:
try_files $uri $uri/public/index.php?$query_string;
If its not working then replace your 'public' with the folder name that content 'index.php',
That worked great with me using ServerPilot,
Good luck!.

In my case, for testing purposes I had only phpinfo.php file in the public directory. The server kept showing 403 errors until I placed a file named index.php into the public folder!

In your case, you are getting nginx 403 forbidden HTTP Response because of improper configuration of sites in Homestead.yaml,
if you configure it properly it should work.
How to solve the issue step by step:
1) Goto your vagrant box and create the laraval app
$vagrant ssh
$cd ~/code
$#lets create basic blog
$laravel new blog
Crafting application...
Loading composer repositories with package information
........
$cd blog
$ll
# You should be able to see public folder in this dir.
# this is the entry point for your application.
# this is your public dir: ~/code/blog/public
# more explicitly: /home/vagrant/code/blog/public
$exit # exit ssh
2) Update the Homestead.yaml with proper site info
- map: homestead.app
to: /home/vagrant/code/blog/public # should be same as in step1
3) Re-provision your vagrant
$vagrant reload --provision
You should be able to access it now using http://homestead.app
Thank you!

I ran into this when I tried manually creating my first site. #GregD's answer helped me discover the problem! Vagrant/Homestead/Laravel will typically get everything running smoothly on its own if you use the built-in features.
Homestead's configuration file comes preconfigured for one site, located in /Code/Laravel/. Some steps to get this test bed up and running:
Install Homestead (remember to set your hosts file)
vagrant up and connect to your virtual machine via ssh (Chrome Secure Shell is great if you don't have a terminal on your machine already)
Download and set up the PHAR package
cd ~/Code
laravel new Laravel.
Browse to http://homestead.app:8000
This will create your first site with appropriate permissions. You can model future sites after the permissions on this one, or just use the "sites" node of Homestead.yaml and laravel new <site> to make new sites in the future.

Access in your browser
homestead.app/public
Before installation of laravel/laravel with composer within /home/vagrant/Code/Laravel/public

Configuring Nginx Sites :
sites:
- map: homestead.test
to: /home/vagrant/project1/public

To fix, ssh into your homestead, then do :
nano /etc/nginx/sites-available/the-name-of-your-project.test
After that all you need to do is get rid of $uri/ that you will find in the location object , then do vagrant reload and error should be fixed.

My solution was to move the address in the host file to the bottom of the file. It happend to me twice.

Check nginx error in you vagrant box
vagrant ssh
sudo cat var/log/nginx/yoursite.tld-error.log
"*1 FastCGI sent in stderr: "Unable to open primary script: /home/vagrant/code/public/index.php (No such file or directory)" "
Change in Homestead.yaml
nano Homestead.yaml
to
map: homestead.app
to: /home/vagrant/code/Laravel/public
then..
vagrant reload --provision

Related

Laravel new project with vagrant/homestead

I just followed the manual at the laravel website and installed homestead.
When running vagrant up it runs fine and I can connect using vagrant ssh.
There is only one step I can not find, how do i start a new laravel project using the vagrant installation.
I can ssh to the vargant machine so I assume I should run laravel new someproject somewhere on the vagrant environment?
In my Homestead.yaml I have:
folders:
- map: D:/Documents/repos/someproject
to: /home/vagrant/someproject
sites:
- map: someproject.test
to: /home/vagrant/someproject/public
Where someproject is currently empty as i want to start a new project and not work on an existing one. I do not have composer/php/mysql on my windows machine but I assume the benefit of the vargant box is that it has all the needed dependencies and I should run it in vagrant.
I tried running it in /home/vagrant but i got:
laravel new someproject
In NewCommand.php line 110:
Application already exists!
new [--dev] [--auth] [-f|--force] [--] []
'
So how do I start the new laravel project after installing vagrant?
The message says that the application someproject already exists. Does the folder already exists in /home/vagrant?
Make sure to add the domain to your hosts file. For Ubuntu, this would be in/etc/ folder. If you want to access your website through someproject.test add
192.188.10.10 someproject.test
to your hosts file.
The site link has to be mention in you Homestead.yaml
sites:
- map: someproject.test
to: /home/vagrant/somneproject/public
Make sure to call
vagrant reload --provision
after saving the changes.
Now if you type someproject.test into the browser you should see the default page (assuming you have generate the key for your laravel application, otherwise you may get an error).

Homestead.test default file gives [No input file specified] Ubuntu

I just installed Ubuntu 17.10 and I want to try create a website using Laravel, but I hit a rock, I followed the instructions. step by step on the official website. But I think something is missing,
Because I haven't touch / edit anything in Homestead.yaml, so basically it would working right?
I already use vagrant up --provision. already create the ssh key. I already googled it and try several ways but it doesn't fix it, I already turn on my XAMPP as well
Sorry but I never touched Ubuntu before, so I'm very blind using this OS
Here is my Homestead.yaml file
Homestead.yaml
and the directories of /home/workspace/ and /home/workspace/Homestead/
~ Dir
Homestead Dir
my Hosts file
Hosts File
EDITED:
I just create a new project in ~/Homestead/Projects/[it goes here] because the default laravel installation is working already, so now I want to create a new project in Projects folder inside Homestead, but why it redirect the url to https?
The folders
in this screenshot: https://i.stack.imgur.com/4cxGy.png Your ~/code folder appears to not exist, which means Homestead will not map it. Create that folder in your Host OS (Ubuntu 17) and then run vagrant destroy && vagrant up If you still have issues post the entire output here for us to check.
For my last question, why when I tried to open my new projects is always giving me this error your internet connection is not private. it's because I'm using .app or .dev in the of the site name, the problem is from google chrome, so I need changed it to .test then it's working perfectly.
I got the answer from this site
https://laracasts.com/discuss/channels/laravel/chrome-blocked-localhost-with-error-your-connection-is-not-private

'No input file specified' - Laravel Homestead

I'm having this message when trying to access to my app in Laravel 5. I have been trying to solve it following different ideas I have seen in this forum and others. It seems like is a problem in my Homestead.yaml file, but I cannot find where my error is. That is what I have in my Homestead.yaml:
folders:
- map: ~/Code
to: /home/vagrant/Code
sites:
- map: testing1.app
to: /home/vagrant/Code/testing1/public
I also added this line to my 'hosts':
192.168.10.10 testing1.app
Any idea what could I do?
Thanks in advance!!
At First, please make sure your local directory is: Code which is in /home, where you will keep all of your Laravel app and it's mapping to VM's directory /home/vagrant/Code
Now, make sure your Laravel app inside testing1 and it's inside Codedirectory.
Now command: vagrant reload --provision
During configure Homestead.yaml never use tab key for space, instead use spacebar
Finally, Please let me know which OS you are using?

Setting up Laravel Homestead with existing project - Laravel commands not recognized

I am setting up homestead on my mac.
I have made sure that the settings are right on my storage folder.
I have installed composer on the vagrant box.
If I navigate to /home/vagrant/Code then my code is there.
Here is my yaml file:
folders:
- map: ~/Sites/MYAPP/
to: /home/vagrant/Code
sites:
- map: my.app
to: /home/vagrant/Code/public
The output is just the standard "Something went wrong"
The console log shows a 500 error with a failure to load resource.
Am I doing something wrong?
I want to see the errors, so where is the .env file to turn those on?
Do I need to touch the Homestead.yaml file on vagrant?
What level of the structure does the "folders" portion of the yaml file need to be set to? Is the folder level that houses the entire laravel application? The public folder?
Is there a full explanation somewhere of all the parameters involved in setting this up? - Especially a postgres database?
Update :
Echoing out a "here" in the index.php function worked, but using a dd() produced an error - Call to undefined function dd().
It appears that the vagrant machine is not recognizing Laravel commands. Any suggestions?
Second Update:
Well, I got it working. How? I am not sure. The .env file was misnamed to .env.example so I changed that, but it didn't seem to do anything. I added homestead to the composer file - as that was mentioned in some forums but no in the install docs - and nothing seemed to happen. Then, it just started working. Frustrating.
Thanks
You should try to restart your Vagrantbox with the --provision flag and see if that helps.
If not, try changing the APP_DEBUG to true in your .env if you haven't already to see if you get some kind of stack-trace that can help you further.
Otherwise you should try placing dd() och log in the public/index.php to see how far it's running and if you can locate what's failing that way.
Your yaml is wrong. Should look like this..
folders:
- map: ~/Sites
to: /home/vagrant/Sites
sites:
- map: my.app
to: /home/vagrant/Sites/MYAPP/public

Laravel Homestead vhost configuration

I am using Laravel homestead. For a project I need a special vhost configuration, where should I define this?
You add a new folder mapping into the "sites" block of Homestead.yml, like so:
- map: myapp.com
to: /home/vagrant/Code/myapp/public
That's all there is to adding a new vhost. To modify it, edit the appropriate file in /etc/nginx/sites-available. In the above case, this would be /etc/nginx/sites-available/myapp.com
See here for example customization of a newly added vhost. Note that the quick tip linked here uses Homestead Improved, a slightly enhanced version of Homestead, as described here.
More Homestead related posts can be found on our site via the Homestead tag.
I have been looking for a solution for customizing nginx vhosts. You want to do it in provisioning, or better: after provisioning otherwise Homestead will overwrite any changes you have done manually to the vhost files.
One solution is the one I found here:
https://laracasts.com/discuss/channels/requests/homestead-provision-deletes-custom-nginx-settings
Basically you create configuration files in a folder in the host machine, map that extra folder to the vagrant machine, then in your after.sh file (which is run by homestead after the normal provisioning is finished) you just copy all of them to nginx's sites_available folder.

Resources