Setting up PHP Development environment in a Virtual Machine

Leave a Reply

Comment as a guest.

  1. I prefer using sshfs instead of samba though. This way there is no need for extra samba server and all communications are encrypted.

    1. Interesting trick with the vhost_alias but a bit un-practical in the sense that local dev env should be completely “local”. A dependency on external DNS defeats that purpose (for situations when you don’t have access to internet, yes that has happened to all of us at one point or another).

      As for SSHFS, you actually don’t need to do it since you’re mounting a folder present on your host machine into the VM – VirtualBox will do it for you if you just specify the folder in your VM settings. See my updated guide – no Samba or SSHFS needed in there. 🙂

  2. Thanks for the how-to, another solution is to use turnkey lamp stack, then just do the network part, however, this gets you whatever PHP version you want / need 🙂

    1. Never tried TurnKey LAMP Stack but I think using PHP version of choice would be possible there as well since its just a linux VM, so you should be able to upgrade/downgrade to any PHP version. :tup:

  3. Hey, great step by step tutorial. So far I have always programmed under windows before deploying to production, so sometimes it was rather difficult to adapt tutorials written for linux to windows.
    maybe you’d like to integrate your tutorial for windows users on the specific step of hooking up the samba share.
    for windows, open up a cmd interface and type
    net use z: \\ubuntu-vm\www [user password you entered in step 17] /USER:[username entered in step 17]

    There are 2 items I was unable to get to work.
    Most important, php does not speak to mysql. I can connect to mysql server via CLI with mysql -uroot with no problem, but php does not connect to mysql. Error reported is “Connect Error (2002) No such file or directory”.
    Googling, it seems to involve mysql.sock, but I don’t seem to be able to make it work.
    I followed your tutorial step by step … any suggestions on where to look? ❓ much appreciated!

    1. This is one issue that a number of people reported, compiling PHP & installing MySQL on your own, the MySQL socket file needs to be found & either symlink needs to be created where PHP is looking for it or PHP config needs to be modified to look for the sock file in right place. For this & some other reasons (apache user config, dir permissions become a bitch) I wrote another step by step which is much easier & works smoothly. Perhaps you should check that out. 🙂

    2. maybe you’d like to integrate your tutorial for windows users on the specific step of hooking up the samba share.

      The new step by step I mentioned above doesn’t require you to setup samba share at all. You use shared folders for your web apps you want to run in apache & for accessing any system files in host OS, just use ssh. So thats one less daemon to run & worry about. 😉

      But if you do want to run samba then map it as a network drive in Windows, its pretty easy. 🙂

  4. Hey Amit, thanks for the quick feedback. Checking your new tut now (if connection stabilizes)
    BTW, I am not really proficient with apache and stuff – the other “issues” I encountered with the old tutorial that maybe the new tut addressed are:
    1) found no way to make xdebug run
    2) a problem with installing the Laravel framework through Composer – it seems curl wrappers get in the way of a proper install. so I recompiled php without the curlwrappers and was able to proceed with the install. Just wanted to give a heads-up that maybe has already been addressed.

    3) question – did I get something wrong or old tutorial seemed to be running mysql instead of mysqli?

    Thanks again .. trying to make a new VM right now! 😎

    1. found no way to make xdebug run

      You mean you weren’t able to install it or use it to debug your app? Installing it is quite straight forward; clone the git repo, compile it & then load it up in php.ini (with correct path to xdebug.so).

      a problem with installing the Laravel framework through Composer – it seems curl wrappers get in the way of a proper install. so I recompiled php without the curlwrappers and was able to proceed with the install. Just wanted to give a heads-up that maybe has already been addressed.

      In the new version of the tut, LAMP stack is installed as default when installing ubuntu, so it works out of the box. Curl is installed afterwards & you will need to enable it for PHP yourself. 😉

Sliding Sidebar