App on a Vagrant box running Laravel Homestead only displays 'It Works' upon fresh install of Laravel App - laravel

I install a new Laravel app into my /sites folder called 'blog' using the laravel new blog terminal command.
The site builds fine, no errors on the terminal.
Then I used the subl /etc/hosts command to open up the hosts file in Sublime Text 3. Here is the contents of that file.
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
127.0.0.1 laraveltest.app
127.0.0.1 makoto.app
127.0.0.1 modelawiki.app
127.0.0.1 fresher.app
127.0.0.1 blog.app
Right now let's focus on blog.app.
I then use the subl Homestead.yaml command to open and edit the Homestead.yaml file and update the maps. Here's the contents of that file.
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/www/sites
to: /home/vagrant/sites
sites:
- map: blog.app
to: /home/vagrant/sites/blog/public
- map: laraveltest.app
to: /home/vagrant/sites/laravelTest/public
- map: makoto.app
to: /home/vagrant/sites/Makoto
- map: modelawiki.app
to: /home/vagrant/sites/modelawiki
- map: fresher.app
to: /home/vagrant/sites/fresher/public
databases:
- homestead
I then run the homestead provision command which is an alias for vagrant provision to update everything and get the site up and running.
Now before running the vagrant provision command, every other site (laraveltest.app:8000, makoto.app:8000, etc.) worked just fine, and or displayed the Default Laravel Splash screen (laraveltest.app:8000).
When visiting any of the sites mapped in the homestead.yaml file, all I'm getting is the following page displayed...
http://imgur.com/a/6IIkD
Here's the HTML output.
<html><body><h1>It works!</h1></body></html>
I'm confused on what I did wrong. I'm a newer user going through the Laravel Tutorials on LaraCasts. I followed CodeCourses videos on YouTube to help me install the Vagrant Box onto my machine.
I've also tried to see what was out there on the net for this issue and all i could find is this article on laravel valet... but it seems as though this isn't the tutorial I need.
https://laracasts.com/discuss/channels/laravel/valet-v112-update-just-keep-getting-the-it-works
Edit: I'm currently in the process of uninstalling the vagrant box running laravel/homestead. I did the vagrant destroy <id> command and the vargrant box remove. I then edited the /etc/hosts file and removed all the edited custom app names. I then also deleted my Homestead folder containing my homestead.yaml file. I'm hopefully starting with a fresh install here soon.

(Posted answer on behalf of the OP).
I reinstalled everything including the Vagrant box, and Homestead. Everything runs as normal. Don't know what happened. However the only way I can connect to my sites are to actually type the port in the URL. i.e. blog.app:8000. If i visit blog.app by itself, then the "It Works!" header comes back up and the laravel site goes away.
I'm thinking this might be an issue with nginx, and port forwarding? Since this is the case and the original question has been answered by myself, I'll be asking a new question about port forwarding and Laravel homestead.

Have you configured your sites-available ? try this line inside the virtual machine (after command vagrant ssh):
serve blog.app ~/sites/blog/public

It seems that you have already solved the problem, as you made an edit to your original question and linked to a new question. However, one thing I noticed that may have been causing your problem is the IP in your /etc/hosts file is does not match the IP in your Homestead.yaml file. When I use Laravel Homestead, I make sure that my /etc/hosts and Homestead.yaml files have identical IPs. I always get the Laravel splash page when I do this. Hopefully this is useful for future Vagrant boxes.

Related

Laravel homestead 502 bad gateway

Everytime i go to my project I get a 502 bad gateway. When I refresh, the page works.. If I click a link to another page I get 502 bad gateway again. After the refresh the page loads. What could be the problem here.
Homestead.yaml
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: c:/Users/MyNameHere/.ssh/id_rsa.pub
keys:
- c:/Users/MyNameHere/.ssh/id_rsa
folders:
- map: c:/Users/MyNameHere/Desktop/sites
to: /home/vagrant/code
sites:
- map: spa.test
to: /home/vagrant/code/spa/public
databases:
- homestead
Got the latest version for virtualbox and vagrant.
My spa folder contains the newest version laravel.
Login to Laravel Homestead Server with PuTTY and Private Key File.
then...
cd /etc/php/7.4/mods-available
sudo nano xdebug.ini
Comment out the first line
;zend_extension=xdebug.so
xdebug.remote_enable = 0
xdebug.remote_connect_back = 1
xdebug.remote_port = 9000
xdebug.max_nesting_level = 512
Then restart PHP-FPM
sudo service php7.4-fpm restart
Had the same issue with the latest version of homestead.
After digging in log files and then github issues for homestead, I found this this.
There's an issue with xdebug that they're waiting for a fix for. The solution is to disable xdebug or use php 7.2. I opted for the latter. In that case, make the following change in your homestead.yaml and then running vagrant reload --provision will fix this.
sites:
- map: spa.test
to: /home/vagrant/code/spa/public
php: "7.2"
I was having the same problem and I couldn't change the PHP version or disable xdebug, but I could and did change for the Apache server.
sites:
- map: spa.test
to: /home/vagrant/code/spa/public
type: "apache"
I had a similar issue, got the 502 error. Refreshing the browser or reloading the virtual machine had no effect.
I solved disabling the Xdebug. Found the solution here: https://christattum.com/disabling-xdebug-in-laravel-homestead/
On prompt:
cd /etc/php/7.4/mods-available
sudo vi xdebug.ini
Commented all the lines of the file with ;
Run the vagrant reload --provision command to the Homestead file in the virtual machine, and then after vagrant up, enter with vagrant ssh. Your problem will be solved :)
You can change your ip post adress and write 127.0.0.1 in your host file.
You can enter it by adding 8000 next to the project name in the search engine.
For example spa.test:8000 and then running vagrant reload --provision will fix this.
I lost 3 days trying to solve the same issue.
My mistake was to have defined in my host file something like:
127.0.0.1 spa.test
The solution is to add instead, the same IP you specified in Homestead.yaml.
192.168.10.10 spa.test
to /etc/host (In case of Mac)
to C:\Windows\System32\drivers\etc\hosts (in case of Windows)
Even if you have multiple hosts defined in your global Homestead.yaml file.
For instance
folders:
- map: /Users/davidecasiraghi/Projects/my_laravel_project
to: /home/vagrant/code/my_laravel_project
- map: /Users/davidecasiraghi/Projects/spa
to: /home/vagrant/code/spa
sites:
- map: my_laravel_project.test
to: /home/vagrant/code/my_laravel_project/public
- map: spa.test
to: /home/vagrant/code/spa/public
Then in the host file:
192.168.10.10 spa.test
192.168.10.10 my_laravel_project.test
Then when you will do vagrant up you will be able to access to both of them.
For me this was related to Xdebug, which doesn't seem to yet be compatible with PHP 7.3.
To continue using 7.3, you can turn Xdebug off with
sudo phpdismod xdebug
restart php service
sudo service php7.3-fpm reload
For Chinese,
if you are using Clash for Windows,
then edit "Bypass Domain".
It's not relevant to this question,
but Google lead me here,
Do this inside your Homestead VM vagrant ssh
Check your php version
$ php -v
Edit your website config file
$ sudo nano /etc/nginx/sites-available/<laravel.app>
line
fastcgi_pass unix:/var/run/php/php8.1-fpm.sock;
change according to your php version
mine was php8.2-fpm.sock; then I change it to php8.1-fpm.sock; press ctrl+x to save, then
$ sudo service nginx restart
$ sudo service php<ver>-fpm restart
reload the page

Laravel Homestead with Apache server

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!
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
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
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.

Laravel Homestead No input file specified

at the moment I am having a real nightmare trying to get Laravel Homestead to work. Usually when I have had this issue on my work machine I simply run vagrant provision however on my personal machine when I run vagrant provision nothing really happens it just hangs for a few seconds and then it is ready for another command.
Here is my setup Homestead.yaml:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Projects
to: /home/vagrant/Projects
sites:
- map: helloworld.app
to: /home/vagrant/Projects/HelloWorld/public
databases:
- homestead
My host file:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
192.168.10.10 helloworld.app
When I run vagrant up I get no errors either. I just get No input file specified. when I visit the URL in my browser.
Has anybody had this issue before?
Thanks, Nick
Looks like there is a line break after the sites: parameter. If thats true, get rid of that and run vagrant provision again.
Make your app/storage writeable by your homestead user.
I do not know if this is the case or not but if you are starting / stoping VM via the GUI, it may behave differently. Using vagrant <command> is always better for things like halt etc.
Update:
Make sure nginx config in your VM mirrors what you have on your yaml config file for homestead. I mean the public is also pointed in the nginx configs so check files under etc/ngnx/sites-available/ and make sure root points to where it is supposed to.
Update app/storage permissions with chmod -R 777 app/storage
Try running homestead up --provision it is homestead provision not vagrant.
You can find more information here some of the tutorial vids might require a subscription but I know some stuff is free there. Just in case it might help.

Vagrant Laravel new project set up

I am now ready to start a new project with Laravel using Vagrant. My initial project worked fine but I can't seem to get the new project to show in the browser with its unique name loginauth.app.
My very first app was called PaulsApp and if I typed paulsapp.app in the browser the laravel started page showed fine.
I followed the instructions to create a new project using composer create project in my VM in the same directory as my first app. I can see this in both the local and on the VM.
Next I updated the homestead.yaml file to include the new sitemap and run vagrant provision to let the VM know of the updates.
I believe I must be overlooking something as my .yaml file has the map as homestead.app but that does not work only paulsapp.app which is in my etc/hosts file.
Please could somebody explain how the .yaml file and the hosts file are interacting. If I completely remove the mapping to PaulsApp in the yaml file, paulsapp.app in the browser still shows up the correct page.. as such I am a tad confused. I thought one simply added a mapping to the yaml and then could access that mapping through the browser. I want to type loginauth.app in the browser and have it point to the index file in the public directory of /home/vagrant/code/loginauth/ thanks.
homestead.yaml
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/code
to: /home/vagrant/code
sites:
- map: homestead.app
to: /home/vagrant/code/PaulsApp/public
- map: loginauth.app
to: /home/vagrant/code/loginauth/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
etc/hosts
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
192.168.10.10 Paulsapp.app
#127.0.0.1 PaulsApp.dev
OK so thanks to some help from the guys over at #laravel irc channel..
I needed to add the correct line to the hosts file. I tried 192.168.10.10 loginauth.app but got no joy so I used 127.0.0.1 loginauth.app.
Then the key was to vagrant halt the VM, Vagrant UP it again then vagrant provision it so the VM could see the changes.
Now loginauth.app:8000/ brings up the page I was hoping for...

How to setup Laravel Homestead server to run locally without being on a network/internet?

Previously, I manually setup my own VM on VirtualBox and configured it so it would also work when I'm coding offline (no internet/not connected to a router). I did this using settings in the VirtualBox GUI and also in Apache on the VM.
Now I'm interested in learning nginx and I've decided to try and use Laravel's Homestead. The tutorials I'm looking at seem to have the assumption I will be accessing the Homestead VM across the network (even though of course it's on the same PC). What do I need to do to ensure the VM will be accessible when I'm offline (like when I'm coding on a plane or train)? I'd like to still be able to have access to the internet from the VM whenever I do get back on WiFi (ie. for apt-get, etc.).
(note: My host machine is running Windows 7 64-bit)
Download and install fresh copies of Vagrant and Virtualbox.
https://dl.bintray.com/mitchellh/vagrant/vagrant_1.7.2.msi
http://dlc-cdn.sun.com/virtualbox/4.3.22/VirtualBox-4.3.22-98236-Win.exe
Also download laravel/homestead manually
https://vagrantcloud.com/laravel/boxes/homestead/versions/0.2.2/providers/virtualbox.box
to my downloads folder C:\Downloads\homestead-0-2-2.box
After Installing Virtualbox and Vagrant. Installed laravel/homestead by running the following command in git bash (you can download git bash here: http://git-scm.com/downloads).
vagrant box add laravel/homestead /c/downloads/homestead-0-2-2.box
Run this command inside C:\users\yourusername
git clone https://github.com/laravel/homestead.git Homestead
NB: This will create this folder: C:\Users\yourusername\Homestead
With some files.
Still in Git bash, cd into C:\Users\yourusername\Homestead and run this command:
bash init.sh
NB: this will create a folder C:\Users\yourusername\.homestead that contains Homestead.yaml and some other files
Then Generate an SSH key which you will need when you want to login to your VM by running this command:
ssh-keygen -t rsa -C "youremailaddress#youremail.com"
NB: This will ask some question simply hit enter or type yes and hit enter.
This will create your ssh key inside C:\Users\yourusername\.ssh
Then you need to configure homestead by editing for Nginx
C:\Users\digitlimit\Homestead\Homestead.yaml
You can right-click Homestead.yaml file then click open then choose to open with wordpad.
My Homestead.yaml looks this after editing:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /wamp/www
to: /home/vagrant/Code
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
# blackfire:
# - id: foo
# token: bar
NB: To understand the mapping which is a process of sharing a folder between the host and the VM:
My laravel project is located at C:\wamp\www\laravel
This directory /home/vagrant/Code will be inside the VM after installation.
So what am telling VM is, whenever you see /home/vagrant/Code reference this folder C:\wamp\www\laravel
Also in this:
sites:
- map: laravel.dev
to: /home/vagrant/Code/laravel/public
What we are saying here is when i go to my browser and type http://laravel.dev display the content of /home/vagrant/Code/laravel/public which is actually pointing to C:\www\wamp\laravel\public
After editing Homestead.yaml file save your chnages
NB: Before we can use http://laravel.dev in the host web browser to view our laravel project, we need to add this the following to the hosts file located in
C:\Windows\System32\drivers\etc\hosts
Add this ip address under the list of other ip address listed if any:
192.168.10.10 laravel.dev
Finally, go back to your Git bash, ensure you are in
/c/Users/yourusername/homestead and type:
vagrant up
Wait for vagrant to complete its processes. Click yes when you see any dialog box asking for permission to create network adapter on your system
Any VM running on your development machine will be accessible when you're offline. Just make sure you setup your development machine's host file to have the VM's location set.
If you're following the Laravel Homestead Setup:
In scripts/homestead.rb, you'll have a line that has the IP Address of the VM.
# in scripts/homestead.rb
# Configure A Private Network IP
config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10"
Add this IP address into to your hosts file. This is located usually in C:\Windows\System32\drivers\etc\hosts
#in hosts file
192.168.10.10 yourwebsite.dev

Resources