Proper usage of Laravel Homestead - php

I have done few projects with laravel. I also tried to use the good practise such us using only models for all calls and use artisian commands.
In my next project i plan to use still more such as using Homestead.
I read more about Laravel Homestead which actually needs Vagrantup.
But i don't know the actual need of Homestead and how to install it.
Any help would be helpful for me and future readers.

I assume you already install VirtualBox or VMWare. After downloading Homestead from Git, you need to amend Homestead.yaml file
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: /Users/Documents/workspace/myssh.pub #pub path
keys:
- /Users/Documents/workspace/myssh #ssh key
folders:
- map: /Users/Documents/workspace/dev/myProject #My project directory
to: /home/vagrant/code/myProject #Vagrant project directory, no need to change this /home/vagrant/code/
sites:
- map: yourproject.app #you can change whatever you prefer
to: /home/vagrant/code/myProject/public #no need to change this /home/vagrant/code/
variables:
- key: APP_ENV
value: local
Then, we remain one final step to amend. Open hosts file under /etc/. I will use VI to amend this. You can use whatever you like.
vi /etc/hosts
You need to add new line in this file
192.168.10.10 yourproject.app //same with code line 11
Finally, you just only need to run vagrant up. Please don't forgot one thing. If you shutdown your PC without shutdown your vagrant, it's take too long to shutdown your PC. Even your PC is shutdown, vagrant might be crushed when you run again vagrant up. Before your shutdown your PC, you need to run vagrant halt for safe.
Hope this help.

Related

Vagrant "No input file specified."

I am a python developer and my company wanted to do a project in PHP -laravel. Also he wanted me to start with Vagrant. So I came across this simple tutorial and tried to start with it. But still I'm getting error No input file specified.
I have been searching since whole day today for this issue, I have came across many posts which includes same query. I tried almost all the solutions from laravel.io and some stack overflow queries But did not got the exact solution.
Directory Structure:
Git Cloned Homestead - /home/laxmikant/Work/PHPWORK/Homestead
Mapped location - /home/laxmikant/Work/PHPWORK/codebase (totally empty directory)
Folders mapped to : /home/vagrant/codebase (Contains Laravel project)
Here is 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: ~/Work/PHPWORK/codebase #-- The path on my local machine
to: /home/vagrant/codebase #-- The path from the vagrant box
sites:
- map: homestead.app
to: /home/vagrant/codebase/Laravel/public #-- The path from the vagrant box which is mapped with folders
databases:
- homestead
variables:
- key: APP_ENV
value: local
Also I am assuming that,By Vagrant ssh when the project is created using :
composer create-project laravel/laravel Laravel --prefer-dist
It should also get synced with codebase directory of vagrant box
So the queries are:
Is this assumption correct? if so why map and to are not getting synced? and
What is the reason that I am getting the error "No input file specified.?
The assumption is correct whatever is in /home/vagrant/codebase will also end up in your ~/Work/PHPWORK/codebase.
After installing laravel via composer if the "no input file" error persists you probably need to reload configuration via running
vagrant provision
You should probably also add a homestead.app entry on your hosts file.
Thanks for your help.
It worked well with the following solutions:
nginx configured manually for my homestead.app
and changed, Sync locations in Vagrantfile

Using vagrant and homestead for multiple sites and per project installation

I have been using XAMPP for quite a time, and after discovering Laravel and finding out, that I quite like it, I also wanted to use Homestead. The problem I'm having is, that I can't seem to be able to run multiple sites.
I have tried various things, but the main problem currently is, that one project works, while all the others are getting a connection timeout, when trying to access their webpage.
These are the steps I've taken to use Homestead
Installing VirtualBox
Installing Vagrant
Adding homestead with vagrant box add laravel/homestead
Clonging the repository git clone https://github.com/laravel/homestead.git Homestead
Create Homestead.yaml file in the Homestead directory with the bash init.sh script
Create a new project laravel new projectA
Require homestead composer require laravel/homestead
Generate Vagrantfile php vendor/bin/homestead make
Modify the Homestead.yaml to have an IP that ends with 10
Create another project laravel new projectB
Require homestead composer require laravel/homestead
Generate Vagrantfile php vendor/bin/homestead make
Modify the Homestead.yaml to have an IP that ends with 11
Adding those two sites to the hosts file sudo nano /etc/hosts => xxx.xx.xx.10 projecta.app & xxx.xx.xx.11 projectb.app
Starting vagrant from one of the two directories vagrant up
Now, I'm having the problem, that only one of the projects is reachable. It's always the one from where I called vagrant up. So if I call vagrant up from Project A I can access http://projecta.app and http://projectb.app times out. The same the other way around, sadly.
This is my vagrant global-status
id name provider state directory
------------------------------------------------------------------------
fc6fadb default virtualbox running /Users/mknb/work/projectA
I thought I would just do another vagrant up from the projectB directory but that doesn't work of course.
I don't want to use the global Homestead, because Laravel said, that it is possible to have a per project installation, so how do I achieve it? Do you need more information?
I didn't modify the Homestead.yaml except of the IP and the domainname homestead.app => projecta.app
It seems like a global installation is fairly easy with Homestead, since I would just have to add more sites to the Homestead.yaml, but as I said I'd like to have a per project installation. Can anybody help?
Starting vagrant from the Homestead directory doesn't work of course.
By using Homestead in your way, you create a virtual machine for each projects. Therefore, the VirtualBox cannot forward the HTTP request from your host machine for all of virtual machine. You can only run one machine (so, one project) each time.
To run multiple projects with Homestead, you can do as follow:
Clone Homestead git clone https://github.com/laravel/homestead.git Homestead
Inside the Homestead folder, run bash init.sh
Edit the folders property of ~/.homestead/Homestead.yaml to share your code of both projects with VM:
folders:
- map: ~/pj1
to: /path/to/project1
- map: ~/pj2
to: /path/to/project2
Edit the sites property of ~/.homestead/Homestead.yaml to make Nginx enable the domain of both site:
sites:
- map: project1.local
to: /home/vagrant/pj1/public
- map: project2.local
to: /home/vagrant/pj2/public
Edit your hosts file to forward these domain fo localhost
127.0.0.1 project1.local
127.0.0.1 project2.local
Run vagrant up at the folder that you cloned the Homestead code inside it (which contains the init.sh file).
Now, you can run as many project as you want with just one Homestead virtual machine.
There are some important steps missing in the accepted answer although it helped me lot. I have added those necessary steps. Thanks #Hieu Le for answer.
I assume you have correctly installed your fist site as by the instructions of Laravel docs. Now you have another laravel site which you want to shift on vagrant. Follow the following steps.
cd into the directory of new Laravel project which you want to add. I assume you have all laravel files in it and its working using MAMP or any non-vagrant solution.
run vagrant init laravel/homestead. This command will add the necessary VagrantFile in this new project.
open the directory of your first original project file and open its
Homestead.yaml file in editor.
Now follow the steps defined by #Hieu Le in accepted answer to
modify .yaml file
folders:
- map: ~/pj1
to: /path/to/project1
- map: ~/pj2
to: /path/to/project2
sites:
- map: project1.local
to: /home/vagrant/pj1/public
- map: project2.local
to: /home/vagrant/pj2/public
Edit your hosts file to forward these domain fo localhost
127.0.0.1 project1.local
127.0.0.1 project2.local
On terminal cd into your first original original project
directory.
Run command vagrant reload --provision. This will reload the
vagrant machine so that the changes which we made in .yaml file come in effect. You database of original project will remain intact.
Run vagrant ssh
Run ls and make sure you can see the folder of your new project. If its there
you have configured your new site correctly.
Hit the url of new site with addition of http:// and your are
DONE.
Like how here says, you can install Homestead directly into your project, require it using this composer require laravel/homestead --dev at root directory of each project you have. Now by make command you can generate Vagrantfile and Homestead.yaml file into your project's root directory.
Mac/Linux:
php vendor/bin/homestead make
Windows:
vendor\bin\homestead make
On each project root you will have a Homestead.yaml file to edit:
Project-A
ip: "192.168.10.10"
...
folders:
- map: "~/Code/projecta"
to: "/home/vagrant/projecta"
sites:
- map: project.a
to: "/home/vagrant/projecta/public"
Project-B
ip: "192.168.10.10"
...
folders:
- map: "~/Code/projectb"
to: "/home/vagrant/projectb"
sites:
- map: project.b
to: "/home/vagrant/projectb/public"
Add this to /etc/hosts:
192.168.10.10 project.a
192.168.10.10 project.b
Then you have to cd to each project's root and vagrant up.
Now if you vagrant ssh from each project, you will have that project in your VM environment.
there is a short cut command to proxy the sites you want to add..
without having to messed up your Homestead.yaml file and provision your vagrant box all over again...
This applies to BOTH GLOBAL AND PER PROJECT INSTALLATION
Just Make sure if you are adding another project...
You add it the (whole project) on your Shared Folder
Declared in your Homestead.yaml
Assuming your shared folder is
C:/Users/MYACCOUNT/Codes
Add another project in that Folder
laravel new homestead.app
Then
Assuming your are ssh in your Homestead
Type
a.) if your using nginx
serve homestead.app /home/Vagrant/Code/homestead/public
b.) if your using hhvm
serve-hhvm homestead.app /home/Vagrant/Code/homestead/public
Just change your domain name and path to public folder of your project
Then Edit your etc/hosts file as Administrator
What ever ip address you define in your Homestead.yaml
usually the default is 192.168.10.10
Use it instead of 127.0.0.1
Why? because if you use 127.0.0.1 your url will look like
homestead.app:8000
If you Use the IP address in the Homestead.yaml
192.168.10.10 homestead.app
you can access your site without port 8000
and just use homestead.app
This Solution is Much Better than Provision... And is Faster...
This is what i Do
Step 1: First you just map your other project and database in the homestead.yaml file enter image description here.
Step 2: Create the database you mentioned in the existing workbench connection enter image description here.
Step 3: Mention that database in your project .env file. enter image description here
Step 4: Add another path in your drivers/etc/hosts file and run homestead reload --provision. Your problem is solved. :)enter image description here.

Homestead "No input file specified" laravel 5

Been trying this for days! I am aware there are other Qs about this, which I have checked over an over. I have one site working and the other not.
I'm using Homestead with Laravel 5 and OSX 10.10.3
I have this .yaml file:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Sites/LaraCode
to: /home/vagrant/LaraCode
sites:
- map: myapp.app
to: /home/vagrant/LaraCode/myapp/public
- map: newapp.dev
to: /home/vagrant/LaraCode/newapp/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
Both are Laravel 5 apps in these folders:
/Users/USERNAME/Sites/LaraCode/myapp
/Users/USERNAME/Sites/LaraCode/newapp
myapp.app works fine but newapp.dev gives an error:
No input file specified
in the browser.
I have chmod777 the storage folder. There is an index.php in the public folder. I vagrant provision after changes.
Homestead seems to have been a horrible waste of time.
For me homestead destroy and another homestead up worked. Also I guess you added the new url to you hosts file, correct?
Although I agree that the docs for homestead are a little lacking.
Ok,I finally found an answer for this. I believe I had two homesteads set up, so I had to remove a homestead from the VM
I also had to do update my bash_profile so I could use the homestead commands.
Afterwards, in the homestead folder I ran:
homestead provision
To ensure the yaml file was up-to-date.
All is good now. Both sites are running. Server set-ups are always a nightmare for the less computer techie developers. Where I was caught out was the lack of clear folder guidance on where to execute command lines, hence the conflicting homesteads.

how can i add a new laravel site in homestead without destroying environment?

How can i add a new site without running ?
homestead destroy
homestead up
Im using Laravel Homestead version 2.0.13
When i add a new site, i add the following to my homestead.yaml file
folders:
- map: ~/web/code
to: /code/websites
sites:
- map: laravel5.dev
to: /code/websites/laravel5/public
- map: anothersite.dev
to: /code/websites/anotherproject/public
I've added to my hosts file :
192.168.10.10 laravel5.dev
192.168.10.10 anothersite.dev
I then proceed to check the status of my machine using:
vagrant global-status
90be623 default virtualbox running /Users/user/.composer/vendor/laravel/homestead
I run vagrant provision 90be623 to provision my new site but sadly anothersite.dev still points to laravel5.dev
The only way i solve this is running homestead destroy and then homestead up.
But this destroys my database.
When i run vagrant provision 90be623 i notice alot of times the appearance of:
==> default: stdin: is not a tty (In red)
Versus when i do homestead destroy and homestead up where everything is in green..
Thank you for reading this and helping :)
Ok, so i've found that if i want to add a new site, all i got to do is
homestead halt
homestead edit
Homestead edit will open the homestead.yaml file
Here i add the mapping for the site
Edit the hosts file /etc/hosts and add url i want for example app.dev and save
homestead up --provision
It worked like a charm without me having to destroy my machine or databases.
In Laravel 5.2, there is no need of halting and then starting.
After adding the new site inside the ".yaml" and "hosts" files, you only need to perform one command in the terminal, from within the Homestead directory:
vagrant reload --provision
See here: https://laravel.com/docs/5.2/homestead#adding-additional-sites

Homestead: Folder mapping to the wrong document root

I'm using Laravel Homestead to VM into my dev environment. I recently created a new mapping (the /Website/Site/ directory) in my Homestead.yaml whenever I go to site.app page , I'm redirected to the /tasks page which was set in another project (/Laravel). (This results in an error, since the page isn't there). Here is my Homestead.yaml file:
folders:
- map: /Users/me/Homestead/Code/Laravel
to: /home/vagrant/Code/Laravel
- map: /Users/me/Homestead/Code/Larabook
to: /home/vagrant/Code/Larabook
- map: /Users/me/Homestead/Code/Website/Site
to: /home/vagrant/Code/Website
sites:
- map: homestead.app
to: /home/vagrant/Code/Laravel/public
- map: larabook.app
to: /home/vagrant/Code/Larabook/public
- map: site.app
to: /home/vagrant/Code/Website/public
variables:
- key: APP_ENV
value: local
The Laravel contains the route where the index page is redirected and the Website directory is the new project that is just a fresh install of Laravel and nothing else. Here is some of the Server/Request Data error output:
SCRIPT_FILENAME /home/vagrant/Code/Laravel/public/index.php
SCRIPT_NAME /index.php
REQUEST_URI /tasks
DOCUMENT_URI /index.php
DOCUMENT_ROOT /home/vagrant/Code/Laravel/public
Here is the route.php for the project in Laravel/ (i.e. the old project)
Route::get('/', function(){
return Redirect::to('tasks');
});
Why is a fresh install of Laravel being redirected by a project in a different directory?
SOLUTION
vagrant reload --provision
or, more drastically
from ~/Homestead run vagrant destroy then vagrant up
I ran into this issue too.
Presumedly, the changes in Homestead.yaml file are being ignored. So, I resolved to refresh it.
! REVISED SOLUTION THAT DOES NOT DESTROY YOUR MACHINE
My solution below is inadequate because it destroys your existing machine. See this solution first!
Once your Homestead environment is provisioned and running, you may want to add additional Nginx sites for your Laravel applications. You can run as many Laravel installations as you wish on a single Homestead environment. There are two ways to do this: First, you may simply add the sites to your Homestead.yaml file and then run vagrant provision.
Alternatively, you may use the serve script that is available on your Homestead environment. To use the serve script, SSH into your Homestead environment and run the following command...
http://laravel.com/docs/homestead#daily-usage
Per the Laravel.io forum the better solution is to run vagrant reload --provision.
See also
*Vagrant Docs
OLD SOLUTIONS: USE AS LAST RESORT
Try these solutions:
from ~/Homestead run vagrant reload then vagrant up
or, more drastically
from ~/Homestead run vagrant destroy then vagrant up
OPTION 2 DESTROYS YOUR SERVER AND ITS DATABASES
Note: I resorted to step 2.
You can run homestead up --provision to force the reload of the Homestead.yaml file.
If you have a running homestead instance, simply issue the command homestead provision from your local machine.
I could fix that issue using the serve command provided with the homestead box.
When you're connected to the VM run:
serve personal.local /home/vagrant/projects/personal/personal-site/public
without the need to reboot the VM.
I've tried vagrant reload --provision and it reloads the yaml file but seems not the ngnix configuration.

Categories