Configure Laravel environment just once and use it for further app developments - laravel

I am pretty new to Laravel and just started with development of my first application in the framework. I had started learning it a while ago and faced n number of issues while configuring the test application. It had been a long time and I can't find all the notes I had made while I faced issues.
So my problem is this time I want to configure my environment and create a package or a container so that I get it up and running next time when I want to develop more apps in future. Is there any way to achieve it?

If you want a clean and complete development environment for laravel and spare yourself of configuring everything on your local OS and Be able to have the same configuration somewhere else on another machine, I'd recommend using homestead which you can find it's documentation Here.
Steps are easy you basically install vagrant and VirtualBox or VMWare. (I recommend VirtualBox). Then install homestead by following the Per Project Installation section of the docs and you're gonna have a Homestead.yaml file in your laravel installation. Which is going to look something like this :
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
hostname: myhost
name: myhost
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: "/Path/To/Project/myapp"
to: "/home/vagrant/myapp"
sites:
- map: my.app
to: "/home/vagrant/myapp/public"
databases:
- mydatabase
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
Edit this file to your settings and save it for future use. Then just add my.app *Your.Ip.Add.ress* to your OS hosts file which you're gonna find the guide on how to do that in the docs as well.
Finally run vagrant up in your project root and have everything setup!
Just type my.app or whatever you set it up to be and your laravel website comes up.
You can ssh to this virtual server installation with vagrant ssh command.
Database username is homestead and password is secret by default. you can change all of this yourself in the virtual server.

Related

Laravel homestead ignores features to be installed

I want to add Minio to my Homestead VM. I've added the features option to the homestead.yml file, but running vagrant reload --provision doens't change anything and visiting http://homestead:9600/ gives me a ERR_CONNECTION_REFUSED. What am I missing here?
---
ip: "192.168.10.10"
memory: 4096
cpus: 1
provider: virtualbox
name: ausbildungsportal
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: E:\programierung\ausbildungslink
to: /home/vagrant/code/ausbildungslink
- map: E:\programierung\uptimechecker
to: /home/vagrant/code/uptimechecker
sites:
- map: azubi.tested
to: /home/vagrant/code/uptimechecker/public
- map: help.tested
to: /home/vagrant/code/ausbildungslink/public
databases:
- homestead
- azubiportal
- ausbildungslink
features:
- minio: true
I tried it and it didn't work for me. Fixed it by updating to the latest version of homestead
composer require laravel/homestead
I've just faced the same issue, leaving my solution here just in case.
For each feature, a separate script is triggered to manage the installation.
E.g. for docker it is homestead/scripts/features/docker.sh.
Inside it is checking if the feature is already installed (may look slightly different depending on the version):
if [ -f /home/$WSL_USER_NAME/.homestead-features/docker ]
then
echo "docker already installed."
exit 0
fi
So, if the feature is not installed, but still ignored by the Homestead script, you can just delete the needed file inside the VM (e.g. /home/vagrant/.homestead-features/docker for docker feature, similar for other features).

Laravel homestead: "No input file specified"

This is the output I get when entering my local site.
I'm using Windows and running Homestead with Vagrant on it. This is my homestead.yaml file:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: D:/web/laravel
to: /home/vagrant/code
sites:
- map: laravel.test
to: /home/vagrant/code/public
databases:
- laravel
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
As you see, I opted for a global homestead installation, in my user folder, mapping Laravel to a path in a secondary drive.
None of these solutions I found worked for me:
vagrant up --provision
vagrant provision
Any help appreciated!
My global Homestead installation did not work, but my per project installations are OK.
Per project set up is preferred; we are able to tweak each project independently if and when we need to.
I lost two weeks due to 'no iput file specified' (at global installation). Yet the per project process is easy.
The following video more than helped me: https://www.youtube.com/watch?v=rs2Hzx4qBm8
Further let me use terms "host" (the machine) and "guest" (Homestead virtual machine, VM).
This sure works as described with versions:
Ubuntu 18.04, Virtualbox 5.2.18, Vagrant 2.1.5, Composer 1.7.2 - host.
Laravel Homestead 7.17.0, Laravel Installer 2.0.1 (Laravel 5.7) - guest.
Have Vagrant, Virtual Box (you can install the two per https://laravel.com/docs/5.7/homestead), as well as Composer installed on the host,
cd where you wish to keep Laravel sites, then mkdir LaravelSites, cd LaravelSites and then
composer create-project --prefer-dist laravel/laravel petrTest (it takes time), to create the project (and add plenty packages), and then cd petrTest and ls to review it; I guess in this step I remember adding mbstring and perhaps one or two more packages per requests on terminal by hand (sudo apt install thePackage) for my first homestead project into my host,
composer require laravel/homestead --dev, to add homestead and yaml packages to the project,
vendor/bin/homestead, to run Homestead, so to install it into your project run vendor/bin/homestead make, and view your project (note you have just added Vagrantfile and mainly Homestead.yaml),
nano Homestead.yaml, review, and exit keeping it intact for your first project,
ssh-keygen -t rsa -C "madeUp#email.com", Enter, file (keep_suggested_file): Enter, Overwrite the current file?: y, passphrase: Enter, passphrase again: Enter,
vagrant up (it takes time and computing resources), then vagrant ssh to switch to your guest (VM), cd code, then ls; and in /home/vagrant/code of your guest you can see those same files that are in /home/petr/LaravelSites/petrTest of your host (the two directories are synced),
logout to leave the guest for the host, sudo nano /etc/hosts, then append 192.168.10.10 homestead.test to the bottom and make sure to Write Out the changes. Then in the browser: homestead.test, Enter. You should see the Laravel web.
Alternatively you can follow the nice and easy video, too.

Windows 10 Hosts file not working Laravel Homestead

I am trying to get windows to redirect homestead.localhost to the site i have setup in Laravel Homestead. But its not letting me access the page. i can access the site i setup by going to 192.168.10.10 but going to http://homestead.localhost in my browser brings up:
ERR_CONNECTION_REFUSED
My windows host file, the only line in it, has
192.168.10.10 homestead.localhost
And 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: C:/Users/jarro/Documents/Sites
to: /home/vagrant/Sites
sites:
- map: homestead.localhost
to: /home/vagrant/Sites/homestead
databases:
- homestead
# blackfire:
# - id: foo
# token: bar
# client-id: foo
# client-token: bar
# ports:
# - send: 50000
# to: 5000
# - send: 7777
# to: 777
# protocol: udp
So the question is, why is my windows 10 host not working.
I have did the following:
Cleared IP Config, Restarted computer, deleted and created a new vagrant, and reloaded the vagrant.
What am i missing?
sites:
- map: homestead.localhost
to: /home/vagrant/Sites/homestead
You have to map your site to the "public" folder of your Laravel Project! Something like:
to: /home/vagrant/Sites/myLaravelProject/public
Homestead doesn't have any index.php which could be referenced.
So after about a week of giving up, i decided to go back and try again. Found a post on Laracasts:
https://laracasts.com/discuss/channels/general-discussion/homestead-windows-10-need-to-specify-port-8000
All you have to do to fix what i am having done is add :8000 on the url and the site loads. Its not working on port 80 for some reason. I am gonna go fix this now so i can rest in peace.
:D
This is an old question but in the Hosts file I find it much easier to just use:
127.0.0.1 myapp.local
It works everytime. I have always had minor problems with using 192.168.10.10

My Laravel Homestead doesn't work

I'm having problem to understand how to run my website using vagrant and Laravel Homestead environment.
I added laravel/homestead box without any problems. Then I ran vagrant init laravel/homestead and it worked too.
I managed to create Homestead.yaml and here's what it contains:
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/www
to: /home/vagrant/code
sites:
- map: project.dev
to: /home/vagrant/code/project
databases:
- homestead
variables:
- key: APP_ENV
value: local
vagrant up runs correctly, but I don't know how to access my website. I added 192.168.10.10 project.dev to my /etc/hosts.
I want to keep my project at ~/www/project. First thing that I didn't understand from the docs is, what is the folder at sites / map / to setting supposed to be? My local folder or a folder in the virtual environment?
The next thing I don't understand is why when I do vagrant ssh and then ls, I don't see any files, even though there's index.php at my ~/www/project. I thought they are going to be synchronized automatically.
When I go to project.dev in the browser, it timeouts. I tried project.dev:8000 as well and 192.168.10.10, but nothing works.
Please help me.
You are forgetting the folders parameter, also your indentation should be with spaces and not with tabs, thats the way yaml works, everything else seems to be fine but try to make it with something similar to this one
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
provider: virtualbox
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/www/project
to: /home/vagrant/code
sites:
- map: project.dev
to: /home/vagrant/code/project/public
databases:
- homestead
variables:
- key: APP_ENV
value: local
you're missing the folder share settings in you're homestead.yaml file.
Try adding
folders:
- map: ~/www/project
to: /home/vagrant/code
Look at the docs here
http://laravel.com/docs/5.1/homestead#configuring-homestead under Configuring Shared Folders
I think this is the common issue that someone new to Laravel Homestead is facing.
Laravel Homestead basically provides an image that gets a VM ready for Laravel development. The yaml config on "sites" is basically use to configure Nginx - it does not install a Laravel project on the path specified.
So for a new homestead VM, you just have to ssh into your Homestead VM, and type and run this:
composer global require "laravel/installer=~1.1"
Once done, on you /home/vagrant/code folder (in the VM, not your host), type and run this:
laravel new project
Where the "project" is the name given to your new project. Since your yaml is already configured to "project", the above command will work fine. Obviously, this is clearly not the only way to get Laravel as you can use composer create-project to install Laravel directly.
Once done, you should be able to visit http://project.dev on your host's browser, if your host file is configured with this added entry:
192.168.10.10<tab>project.dev
Alternatively, you can configure your host file to be
127.0.0.1<tab>project.dev
Which you can then view on your host's browser via http://project.dev:8000
Hope the above explains clear enough. Enjoy!

Laravel Homestead 2.0 Adding New Sites

Homestead 2 is awesome, but I can't seem to get new sites to work without going through the following process.
I do homestead edit to setup the new site paths and domains etc
I edit hosts to set up the domain
I do homestead halt then homestead up to restart
This is when I think things should be working... but they don't. I have to run the additional step of
Running vagrant global-status getting the id and running vagrant provision <id>.
Everything works except running provision again wipes out all the databases! How do I add new sites without having to provision again?
Instead of step 3 use vagrant provision in your homestead directory (~/.composer/vendor/laravel/homestead/).
As I know Taylor is already planning a "provision" flag, until that you can feel free to use vagrant commands.
this works for me
homestead halt && homestead up --provision
Here is my ~/homestead/.Homestead.yaml file, it contains a configuration for two apps, one with HHVM enabled and one with HHVM disabled(default in homestead).
Homestead will create the database for you in MySQL and PostgreSQL server, when running homestead up.
---
ip: "192.168.10.10"
memory: 2048
cpus: 1
authorize: ~/.ssh/id_rsa.pub
keys:
- ~/.ssh/id_rsa
folders:
- map: ~/Projects
to: /home/vagrant/Projects
sites:
- map: jobs.app
to: /home/vagrant/Projects/jobs/public
- map: messages.app
to: /home/vagrant/Projects/messages/web
hhvm: true
databases:
- jobs
- messages
variables:
- key: APP_ENV
value: local
You can now run:
$ homestead up
and then:
$ homestead ssh
and then run byobu(for tmux):
$ byobu
and cd into the project:
$ cd Projects/jobs
and run composer:
$ composer update

Resources