天天看點

如何把你的檔案挂載到虛拟機上

  Sometimes I need write code in working computer which is window 10 operate system,but run Php scripts in Linux environment.I don't ensure every code that wrote by me is completely correct.So I want to test in Linux environment.Maybe you can upload codes to your server,but I don't like that.maybe use virtual machine is the best solution for me.

The benefits of using Virtual Machine

  • If you are newbie,Don't worried about the crush of real server.Do everything you want even if Virtual Machine broken,we can fix it immediately through backup or snapshots
  • run Php script immediately without upload that is very convenient for debugging
  • you don't buy a real server or cloud server only just for testing your php scripts

Blow is my steps for configuring Virtual Machine

  • Install Oracle VM virtualBox from here
  • Install Linux operate systems (e.g. Ubuntu,CentOS,RedHat......) they are siblings of each others(I choose the Ubuntu 14.04 as my server operate system)
  • Install Apache 2 server
  • the key step to mounting your file to Virtual Machine is that install virtualbox-guest-utils
sudo apt-get install virtualbox-guest-utils      

Note:if virtualbox-guest-utils not be installed,"unknown filesystem type 'vboxsf''" will be occurred.

  • Find "rc.local" file in /etc directory and add blow command in the file
mount -t vboxsf -o uid=1000,gid=1000 Name PATH      

just like this:

如何把你的檔案挂載到虛拟機上

Name is the Folder Name in the virtual box,please checked Auto-mount and Make Permanent checkboxs. e.g.

如何把你的檔案挂載到虛拟機上

PATH is the "DocumentRoot"  in your Apache configuration file.

If you don't familiar with DocummentRoot,please google it.

The last key step is make a network map during local machine and Virtual Machine.just like this:

如何把你的檔案挂載到虛拟機上

Ok,All key steps we have already done,restart the Virtual Machine and any PHP script you write in windows can run immediately in window's browsers.

If you have any questions or don't understand any steps.Please tell me through the Email or comment 

 by the way, if shared directory is in mac and you want to set privileges. first set privileges in your mac.because mac have more priority than Linux,

  All rights reserved by Richard

繼續閱讀