How can I refresh homestead for a new site in my environment? - laravel

I'm running Laravel 4 on my development machine (Mac) with homestead and enjoying it thus far but having trouble when adding a new site. The problem is that I add lines like this for a new site in my ~/.homestead/Homestead.yaml file:
folders:
- map: ~/Sites
to: /home/vagrant/Sites
sites:
- map: listingnaples.dev
to: /home/vagrant/Sites/listingnaples.com/public
- map: videocraftersusa.dev
to: /home/vagrant/Sites/videocraftersusa.com/
Then, my /etc/hosts looks like this:
# MY SITES
192.168.10.10 listingnaples.dev
192.168.10.10 videocraftersusa.dev
192.168.10.10 laneyandchris.dev
If i go in and do a homestead destroy followed by homestead up I can access any of those new sites. That deletes my databases though and really sets me back. How do I "refresh" so to speak? If I add myawesomesite.dev to my /etc/hosts, how can I have homestead pick it up?
I tried homestead --provision but that isn't a recognized command.
For what it's worth, in my ~/.homestead/ directory, I do not have a VagrantFile. Not sure where that's at so I can't run a vagrant provision either.

You can also reload the box and the settings
vagrant reload --provision
This reload the box and see if there are changes, if that's the case it will make the changes while reloading

I just ssh using homestead ssh and then add this line
serve domain.app /home/vagrant/Code/path/to/public/directory
where you replace domain.app to your app name, the same you use on your yaml file and your path to your new public site directory, then just homestead up and you could see it active.

Try run vagrant global-status. You'll see the list of running boxes at this time, like this:
MacBook-Pro-lancedikson:~ lancedikson$ vagrant global-status
id name provider state directory
------------------------------------------------------------------------------------------
9710b02 default virtualbox running /Users/lancedikson/.composer/vendor/laravel/homestead
The above shows information about all known Vagrant environments
on this machine. This data is cached and may not be completely
up-to-date. To interact with any of the machines, you can go to
that directory and run Vagrant, or you can use the ID directly
with Vagrant commands from any directory. For example:
"vagrant destroy 1a2b3c4d"
That's all. Now run vagrant provision 9710b02 and it will be provisioned.

As of Laravel 5 and more importantly Homestead 2.0, just run:
homestead up
Then:
homestead provision

You have to use vagrant provision anyway from the same directory where Homestead.yaml is.

You can run:
homestead up --provision

In my case I had a Homestead.yaml in ~/.homestead/ and in ~/Homestead/.
I am not sure if the default location changed or that I changed it manually (maybe because I did not like the hidden dir), but make sure you don't have multiple Homestead.yaml files. I now symlinked them so I can not confuse myself any further.
But normally, homestead provision or homestead up --provision (when it was turned off) should do.

Related

Laravel Homestead and vagrant don't create the folder inside vagrant box

I use Laravel Homestead for one year it all was good before I had decided change php version.
Firstly I update vagrant. Secondly I executed all commands from updating guide
vagrant destroy
git fetch
git pull origin release
vagrant box update
vagrant up
After vagrant up I saw that my databases were not created and my folder was not mounted (http://joxi.ru/Vm66DpgF410M5m).
I tried to connet via vagrant ssh, but there is not folder "code"
My Homestead.yaml
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: /home/ubuntu/PhpstormProjects/fntr
to: /home/vagrant/code/fntr
schedule: true
sites:
- map: fntr.test
to: /home/vagrant/code/fntr/public
php: "7.4"
databases:
- homestead
- testing
- imports
- prod_copy
I tried use vagrant destroy && vagrant up. I also tried vagrant reload --provision.
I have found the same issues in google and github, but this advices (http://joxi.ru/52a53oGUEBZMZ2 and other) did not help me.
I have the latest versions of vagrant and homestead.
I think that schedule: true not belongs to folders but to sites, try to remove it and run vagrant reload --provision.
I have found solution. But I am not sure that it is solution exactly.
I just reinstalled laravel homestead. Yes, I deleted homestead folder and went via instalation tutorial again.
Then I pasted my old Homestead.yaml and init vagrant box again.
Note if you want to try this method do not forget copy all of your after.sh, homestead.yaml and other files which can be lost

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

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

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.

Homestead Directory Missing After Reboot VM or Computer

Homestead.yaml
folders:
- map: /Applications/MAMP/htdocs/code
to: /home/vagrant/code
Local directory : /Applications/MAMP/htdocs/code
Homestead directory : /home/vagrant/code
Everything is working perfectly beofore I reboot my computer, my homestead directory doesn't seem to sync with my local one anymore. They're missing completely.
I start my homestead VM , and SSH into it.
Then, I go into ~/code, and nothing there.
I tried to research into it, but people seem to have the same issue.
What is going on here ?
How can I fix this ?
In my local homestead directory, I run vagrant reload, I got this
and it works 100% for me.
vagrant reload : restarts vagrant machine, loads new Vagrantfile.
in your terminal Change directory to where your Homestead file was created
and type "VAGRANT UP" lower case.
well it work for me

Vagrant - Homestead Setup Multiple sites

I have mapped the folders etc using the homestead.yaml;
ip: "192.168.10.10"
...
folders:
- map: /Users/User/Desktop/folder/Homestead/First
to: /home/vagrant/First
- map: /Users/User/Desktop/folder/Homestead/Second
to: /home/vagrant/Second
sites:
- map: first.dev
to: /home/vagrant/First/public
- map: second.dev
to: /home/vagrant/Second/public
But when i set up the hosts file, etc/hosts with my second.dev to 192.168.10.10 i find that the mapping goes to first.dev, not the mapping that i have set up for second.dev.
How can i go about making the mapping return the correct site?
EDIT: I am using Mac OS X.
Using Vagrant commands
Run the command vagrant provision within terminal or your command prompt within the folder where homestead files are located.
Another equivalent command is vagrant up --provision this will provision the vagrant machine as well as run it.
Using Global Homestead
You can use the command homestead provision to re-provision the vagrant machine, regardless of the place you call it from within the terminal.
Alternatively, you can use the serve command to add the information to your Homestead.yaml file for you. Like so;
serve domain.app /home/vagrant/Code/path/to/public/directory
But add this to your hosts file so you can access the your app via domain.app in your browser.

Resources