0

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.

  1. I downloaded VirtualBox & Vagrant.
  2. 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)

  3. Afterwards I believe I did vagrant init or vagrant init laravel/homestead
  4. 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.
  5. I then followed laravels instructions and created a homestead folder at c:\Jack\Homestead
  6. ran git checkout for v7.19.2
  7. ran init.bat
  8. 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

  1. run composer install
  2. There was an env.example file I had to change to .env and change some setting
  3. run php artisan key:generate
  4. run php artisan migrate --seed
  5. run php artisan passport:install
  6. 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:

  1. 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)

  2. 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.
    
  3. 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:

  1. 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
  2. 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
  3. How do I connect again now that I am getting those errors running vagrant ssh and vagrant up
  4. 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?
  5. I Assume that I should run git init and heroku create inside the myapp folder is this correct?
halfer
  • 18,701
  • 13
  • 79
  • 158
Jack
  • 401
  • 4
  • 18

1 Answers1

1

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.

Arthur Samarcos
  • 3,002
  • 18
  • 24
  • Hi, Thank You very much for your answers I have a couple of questions, in regards to 3) I deleted the VM from VBox and the folder and then vagrant up worked correctly, do I now have to rerun all the commands I had run before again like -composer install, -php artisan key:generate & php artisan migrate --seed???? – Jack Nov 21 '18 at 21:26
  • 4) I dont have php installed, I have something called XAMP or I can install php but then do I have to install apache and other stuff as well???? if so or is there a simpler way ??? – Jack Nov 21 '18 at 21:27
  • 5) you map the file to home/vagrant/code/myapp whereas I had done home/vagrant/myapp does putting it inside a /code folder change something? is it the standard? My host location is C:\Jack\myapp if I cahnge above from to home/vagrant/code/myapp should I also change my host location to c:\Jack\code\myapp???? – Jack Nov 21 '18 at 21:30
  • You won't have to run key:generate again, but certainly will need to run migrate --seed because if you destroyed your machine you'll also have lost your virtual database. You'll only need php. Check this answer for using XAMMP's php to run commands: https://stackoverflow.com/questions/10753024/how-to-access-the-command-line-for-xampp-on-windows – Arthur Samarcos Nov 21 '18 at 21:32
  • Regarding 5, you're good with your path right now, can keep using it like that. The link between the folders is specified in the Homestead.yaml, so you're good. – Arthur Samarcos Nov 21 '18 at 21:34
  • Arthur thanks allot! I am having 1 problem though when I run one of the php artisan commands I am getting: Could not open input file: artisan, do I need to run composer install again should that fix it? – Jack Nov 21 '18 at 21:36
  • Oh and trying to run composer install is doing this: Composer could not find a composer.json file in /home/vagrant To initialize a project, please create a composer.json – Jack Nov 21 '18 at 21:40
  • Looks like your folders are not in sync. Maybe your Homestead.yaml file is not corretly mapped. Try using quotes when referencing windows paths, like: "C:\Jack\myapp". The folder you see inside the machine (when vagrant ssh) must have the same content of the folder in your host machine. – Arthur Samarcos Nov 21 '18 at 21:44
  • Yup you are right the mapping isnt working, quotes arent working either though, ill keep working on it, its odd cause it was working before. Thank You Arthur – Jack Nov 21 '18 at 21:58
  • When you vagrant ssh inside the machine, you'll be in the folder /home/vagrant/. If you mapped your app to: /home/vagrant/myapp, you'll need to cd myapp – Arthur Samarcos Nov 21 '18 at 22:22