I got a php project which is already done and for starters I have to put it up on a server (planning to use Heroku). I am new to PHP virtual boxes, Laravel, etc. The person who made the project recommended to use Laravel so I started to get things going that way. I am running on Windows 10 and using cmder as my terminal.
I downloaded VirtualBox & Vagrant.
Then using commander I added the Laravel/Homestead box
by doing:
vagrant box add laravel/homestead
in the folder c:\Users\Jacky\vagrant\ubuntu (At least I think that is where I added it)
Afterwards I believe I did
vagrant init
or vagrant init laravel/homestead
whatever I did afterwards I was able to run
vagrant ssh
and get into the system. There I was able to check and I had php and composer installed.
I then followed laravels instructions and created a homestead folder at c:\Jack\Homestead
ran git checkout for v7.19.2
ran init.bat
and configured the Homestead.yaml file
I made the following folder map
- map: C:\Jack\myapp\public
to: /home/vagrant/myapp
and the following site map
- map: myapp.test
to: /home/vagrant/myapp/public
I am a bit confused with the directory structure of this whole thing and not sure if I was supposed to put the myapp directory inside c:\Jack\Homestead\myapp or if just doing it like i did in c:\Jack\myapp is fine.
Anyways that still worked and I could see it in my web browser. So far all was good.
Then the project instructions told me to do the following
run composer install
There was an env.example file I had to change to .env and change some setting
run php artisan key:generate
run php artisan migrate --seed
run php artisan passport:install
run php artisan storage:link
At this point I got an error that the Symlink could not be created, so I googled and found in Stack Overflow to restart as admin. I ran cmder as admin and have been having a heart attack for the last 30 minutes since it told me I had to vagrant up and when I did so it couldnt find my box and even doing vagrant box list
I would get no results and it wanted to redownload which takes over 3 hours.
I just restarted without admin and I do find that my Laravel/Homestead box is listed so I assume it was installed for my user and not admin so I guess I cant run cmder as admin.
So now I am trying to connect again, I am not sure in which folder I should be running the vagrant commands but I only seem to have a VagrantFile in my C:\Jack\Homestead folder so if I run a vagrant command anywhere else it gives me an error that a vagrant environment is required, etc.
So I tried the following inside my homestead folder:
vagrant ssh - I get:
VM must be running to open SSH connection. Run `vagrant up to start the virtual machine.
(In my VirtualBox Manager i see my homestead-7 VM running though)
vagrant up - I get:
Bringing machine 'homestead-7' up with 'virtualbox' provider...
==> homestead-7: Importing base box 'laravel/homestead'...
==> homestead-7: Matching MAC address for NAT networking...
==> homestead-7: Checking if box 'laravel/homestead' is up to date...
A VirtualBox machine with the name 'homestead-7' already exists.
Please use another name or delete the machine with the existing
name, and try again.
vagrant ssh 'homestead-7' I also get
VM must be running to open SSH connection. Run vagrant up
to start the virtual machine.
And the problem is once I do connect I assume I will still have the same problem running:
php artisan storage:link
So my questions are as follows:
Where should I have my projects myapp folder, should it be where it is at C:\Jack\myapp or am I supposed to put it in C:\Jack\Homestead\myapp
Is the VagrantFile supposed to be only in my Homestead folder and is that where I should be running all my Vagrant commands from? Like vagrant ssh and vagrant up
How do I connect again now that I am getting those errors running vagrant ssh and vagrant up
Once I connect I assume I will get the same error running php artisan storage:link since to run as administrator seems to not work what do I do?
I Assume that I should run git init and heroku create inside the myapp folder is this correct?
1) I always keep my apps folders outside of the Homestead folder. Your Homestead folder contains a git project, so if you put your apps inside you should include the folder in the .gitignore file. I think it's easier if you just put your apps elsewhere.
2) Vagrantfile is suposed to only be inside of your Homestead folder ( c:\Jack\Homestead). You should run all your vagrant commands inside the Homestead folder.
3) I used to get this error when I tried to run 'vagrant up' to a project that used the same box name 'homestead-7'. If you have version control, check if the file c:\Jack\Homestead\.vagrant\machines\homestead-7\virtualbox\id has been changed. If so, try restoring the old value and running 'vagrant up' again.
4) You are running in a windows environment, right? Windows can be a little temperamental with symlinks inside vagrant. You'll get the same problem if you try to npm install something. What I do to solve this is to run npm (and php artisan storage:link) outside of the virtual machine, in the host pc, inside the root of the app folder. Just a reminder: to do that you will need php installed in your host machine.
5) All commands related to the app (and not the virtual machine) should be run inside the virtual machine, in the folder app (ex: /home/vagrant/code/myapp) or inside the app folder of your host machine. Those two folders are in sync, thanks to vagrant.
Related
I have followed the steps on Laravel's website, to install Homestead, through VirtualBox.
Install Virtual Box (through their package)
Install Vagrant (through their package)
Run vagrant box add laravel/homestead
Within my application's directory, run composer require laravel/homestead --dev
Run php vendor/bin/homestead make
All of the console output shows a success for the above. I can see the Homestead.yml and Vagrantfile files within the app's directory.
When I run vagrant up, I then get this error:
The VirtualBox VM was created with a user that doesn't match the
current user running Vagrant. VirtualBox requires that the same user
be used to manage the VM that was created. Please re-run Vagrant with
that user. This is not a Vagrant issue.
The UID used to create the VM was: ** Your UID is: **
I'm unsure why this has happened, as I haven't used sudo, nor switched between.
Also, within Virtual Box's preference, it shows the default install location of boxes to be in: /Users/AccountName/VirtualBox VMs, but that directory doesn't exist.
However, Vagrant will list laravel/homestead as a box that's installed.
I'm unsure what exactly the problem is.
Please help!
You have to run vagrant up command into ~/Homestead directory.
I tried setting up a virtual machine using Homestead box. I followed documentation on Laravel site for setting up Homestead.
When I ran the command vagrant up, it seemed to work in setting a VM. Then it asked to run vagrant provision, which I did.
I can't get pass red text 'You are already using composer version 1.1.3 (stable channel)'. I don't know what to do next.
Update: here is Homestead.yaml file:
Needed to edit the file at
~/.homestead/Homestead.yaml
instead of
~/Homestead/Homestead.yaml
after that reload it as usual
vagrant reload --provision
Add
~/.composer/vendor/bin
to Your PATH on host machine (not inside vm).
After restart terminal You can use homestead command.
I know this might sound really silly, but I'm kinda stuck and need help. I'm trying to use Laravel 5.3 and use Homestead as my IDE. I have previously worked on PHP using NetBeans and XAMPP, but the installation has always been a pain. I have no formal training and have learnt and used basic PHP on my own for my webpages.
I'm running a Windows 8-32Bit OS & here's what I've done so far:
I have downloaded Laravel using Composer.
I have installed Virtual Box & Vagrant.
I have installed Git Bash and ran vagrant box add laravel/homestead (Homestead.yaml was not found in my Homestead folder after running bash init.sh command. I downloaded it from Github and added there).
Set SSH Key.
Ran vagrant up in Homestead folder (the installation was complete).
Issues:
If I just type http://localhost:8000 in my browser, nothing happens. I have to run php artisan serve in the command prompt inside laravel directory and keep the prompt window open for the default Laravel 5 page to open.
If I type http://127.0.0.1:8000 in my browser, nothing happens at all.
So how do I use Homestead then for my development everyday ?
you can try
localhost/project-name/public
if you dont want to run php artisan serve
Whilst trying to use the php-7 version of Laravel Homestead in a per-project installation, I see this error during vagrant up:
php5-fpm: unrecognized service
I've tried vagrant destroy and reinstalling the Vagrant box, but it still comes back to this error.
I didn't get the error when using Homestead globally.
How might this be fixed?
The issue was that whilst box: laravel/homestead-7 was set correctly in Homestead.yaml, the composer dependency for laravel/homestead was still using the php-5 version. This meant that the provisioning scripts for Vagrant in vendor/laravel/homestead were those for php-5 and not php-7.
That can be fixed by using a specific branch of laravel/homestead for the composer dependency.
In composer.json, add a custom repository for laravel/homestead:
"repositories": [
{
"type": "git",
"url": "https://github.com/laravel/homestead"
}
]
And require the php-7 branch specifically for laravel/homestead:
"require-dev": {
"laravel/homestead": "dev-php-7"
}
Then composer update and re-provisioning the Vagrant box will fix the issue.
UPDATE
laravel/homestead now has PHP 7.0 by default, and the old php-7 branch no longer exists. To resolve this issue, you simply need to update to the latest version of laravel/homestead via composer.json.
For a quick fix, I found this answer from laracasts very helpful:
cd ~/Homestead && git pull && vagrant destroy && vagrant box update && vagrant up
To elaborate a bit more on the "just destroy it and build again" approach... I favour this over the various instructions for in-place Homestead upgrades from PHP 5.6 to PHP 7 that are floating around the web - it doesn't take very long and also everything feels "cleaner" when you've finished.
(Of course, if you've made changes to your php.ini or any of the other software, you'll need to do these again.)
Preparation
your projects should in a directory on your host computer that's shared with the Vagrant box, not on Vagrant box only, as that's about to be wiped
vagrant ssh into your VM and put a mysqldump of each site's database in the site directory, e.g. mysqldump -u root -p [dbname] > [dbname]-backup.sql (the default homestead MySQL root pw is secret.)
take a backup of everything (e.g. Mac Time Machine and/or do what I do and keep your projects in a Dropbox folder). You've got your git repository stored somewhere safely too, of course?
Virtualbox users: no harm in exporting the entire box in case you get stuck and want to go bac to it (taking a snapshot isn't enough as any will also be wiped when the VM is destroyed.)
Process
vagrant halt (if you haven't already)
vagrant destroy [VM id] Adding the ID is a precaution against destroying the wrong box. Use vagrant global-status to get a list of your boxes; use 7-character hex code in first column.
in ~/Homestead on your host PC/Mac git pull origin master (as mentioned in the other answer, there's no separate PHP7 branch now)
you can re-run the bash script to create a clean Homestead.yaml file etc. - bash init.sh, but the files it copies are all templates, so you can also not do this and keep your previous versions.
vagrant box add laravel/homestead (now we're back on the standard installation instructions. This'll take about 10 minutes on a VDSL connection.
edit ~/.homestead/Homestead.yaml on your Mac/PC.
Here's an example of the folder mapping if you're confused by the docs:
folders:
- map: ~/Dropbox/websites-homestead
to: /home/vagrant/sites
sites:
- map: site1.app
to: /home/vagrant/sites/site1/public
- map: site2.app
to: /home/vagrant/sites/site2/public
databases:
- site1
- site2
So... my actual code lives in ~/Dropbox/websites-homestead/site1 and /site2 on my computer, and I've mapped their common parent directory to /home/vagrant/sites on the VM. Homestead will create empty databases with the name(s) you list.
vagrant up (this'll provision it)
vagrant ssh
cd sites (you should be able to see your code)
restore databases with `mysql -u root -p site1 < site1-backup.sql
Providing you have /etc/hosts entries on your computer, you should be able to view your site. Check the .env file if it can't connect to the database.
You should now be able to do this:
$sudo service php7.0-fpm status
* php-fpm7.0 is running
$php -v
PHP 7.0.2-4+deb.sury.org~trusty+1 (cli) ( NTS )
[...]
open /etc/nginx/sites-available/your_site_conf then change this line:
fastcgi_pass: /var/run/php5-fpm.sock;
to:
fastcgi_pass: /var/run/php/php7.0-fpm.sock;
And then restart nginx.
Note: This is not a permanent solution, if you run provision command vagrant will try to setting up by itself and will overwrite with the first line.
I did a global install of Laravel homestead, edited my ~/.homestead/Homestead.yaml-file and spun up the VM with homestead up. Everything worked fine, but then I needed to add another site. I edited Homestead.yaml to contain the new project, the tried to run homestead provision to apply the changes to the VM. The only thing that outputs is:
==> default: VM not created. Moving on...
I interpret that as the VM is not running, but it is. The only thing working here is homestead destroy followed by homestead up, but that (by its nature) detroys the VM's saved state. I though that vagrant commands was applicable to homestead as well, but vagrant suspend && vagrant up --provision doesn't help.
So.. How do I apply my new config to an already-existing homestead VM?
I found the answer at Laracasts. Copied directly from there:
Try doing this... You should see a vagrant box that is listed that is linked to your composer/vendor...
vagrant global-status
Example Output:
$ vagrant global-status
id name provider state directory
-----------------------------------------------------------------------------------------------------
1ace413 default virtualbox running (...)/laravel/homestead
Then go ahead and run:
vagrant provision {ID}
Example input:
vagrant provision 1ace413
ID being the id of the vagrant instance in the above step.
You should then be good to go!
I recently change my laptop from 32 bit to 64 bit and have to redo installation and setup of my Homestead again.
After setup everything I run below command
vagrant reload --provision
and I get the same feedback which is
==> default: VM not created. Moving on...
After that I try this command and all works well.
vagrant up
I think for first time running Homestead, no need to reload --provision.
You can run vagrant provision to update homesteads websites. However you have to find where the Vagrantfile for the Homestead VM is. If you did the global install it should be in .composer/vendor/laravel/homestead/ directory. You need to change into that directory
cd ~/.composer/vendor/laravel/homestead
Then you need to provision the VM
vagrant provision
Your homestead box should then reflect the changes in the Homestead.yml file.
Edit: I am not at my mac right now so the directory path is a guess of what I remember it being the last time I provisioned my box so please take that into consideration but I am very sure that path should be correct.
I had my VM provision vertualbox running
so i had to exit first