Thursday, August 21, 2014

Set up a Symfony2 dev environment in 10 minutes with Vagrant

Let's keep it simple. It is just a quick draft how can you set up a Symfony2 development environment in a few minutes.

I'll use Vagrant (you'll need version 1.5 at least) and my dev box to create the desired environment.

The box main components are: Ubuntu14.04, Nginx1.6, Php5.5Fpm, Xdebug, Composer, MySql5.5, NodeJs0.10.30, Redis and it has PhpMyAdmin, Webgrind and RedisCommander.

So the steps are:
  • Create the Vagrantfile
    # -*- mode: ruby -*-
    # vi: set ft=ruby :
    Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| = "adammbalogh/lemp"
  "private_network", ip: ""
      config.vm.synced_folder "app/", "/var/www/app/"
      config.vm.provider "virtualbox" do |vb|
        vb.customize ["modifyvm", :id, "--memory", "1512"]
        vb.customize ["modifyvm", :id, "--cpuexecutioncap", "85"]
  • mkdir app
  • vagrant up
  • vagrant ssh
  • cd /var/www/app
  • composer create-project symfony/framework-standard-edition . '~2.5'
  • nano app/AppKernel.php (and add these two methods)
    public function getCacheDir()
        return '/tmp/symfony/cache/' . $this->environment;
    public function getLogDir()
        return '/tmp/symfony/log/' . $this->environment;
  • nano web/app_dev.php (and delete these lines)
    if (isset($_SERVER['HTTP_CLIENT_IP'])
        || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
        || !(in_array(@$_SERVER['REMOTE_ADDR'], array('', 'fe80::1',$
    ) {
        header('HTTP/1.0 403 Forbidden');
        exit('You are not allowed to access this file. Check '.basename(__FIL$
  • app/console cache:clear --env=dev (to test it)

Thursday, August 7, 2014

Connect a Usb device through Vagrant

If you want to list your usb devices do this:
$ VBoxManage list usbhost
Host USB Devices:

On a pure VirtualBox setup it says nothing. Usb devices won't work in your virtual machine until you don't see something in the list. So, you'll need to do two things to fix this:

  • Install VirtualBox Extension Pack (from here)
  • You have to be (your currently logged in user) in the vboxusers group
    • sudo usermod -a -G vboxusers <username>
    • and you have to logout/login from your session!

When you have done with these steps, run the list usbhost again:
$ VBoxManage list usbhost
Host USB Devices:

UUID:               55d6661d-dd23-487c-8f97-23d4cd4f7378
VendorId:           0x064e (064E)
ProductId:          0x8125 (8125)
Revision:           40.16 (4016)
Port:               4
USB version/speed:  2/2
Manufacturer:       SuYin
Product:            Laptop_Integrated_Webcam_HD
Address:            sysfs:/sys/devices/pci0000:00/0000:00:1a.0/usb1/1-1/1-1.5//device:/dev/vboxusb/001/004
Current State:      Busy

UUID:               e96c6aef-f8a7-4f18-a67e-07776c7d839e
VendorId:           0x0bda (0BDA)
ProductId:          0x0129 (0129)
Revision:           57.96 (5796)
Port:               2
USB version/speed:  2/2
Manufacturer:       Generic

In Vagrantfile you have to enable the usb option and add a filter based on the desired Manufacturer and Product:
config.vm.provider "virtualbox" do |vb|
  vb.customize ["modifyvm", :id, "--usb", "on"]
  vb.customize ["modifyvm", :id, "--usbehci", "on"]
  vb.customize ["usbfilter", "add", "0", 
    "--target", :id, 
    "--name", "This is the identifier",
    "--manufacturer", "SuYin",
    "--product", "Laptop_Integrated_Webcam_HD"]
You are all set.

Run vagrant up and ssh in your vm with vagrant ssh. In your vm run lsusb and you should see the connected usb device!