Saturday 15 February 2014

Symfony Project on Ubuntu 13.10, using PhpStorm

This is far more complicated than it should be, and I've not found a reliable guide on it. But this is what we're going to end up with:

A Symfony 2 project running under a puphpet controlled virtual machine using Vagrant. We're going to be able to edit the project and run all the commands via PhpStorm.

Technically you probably don't need the Ubuntu bit ... but there are some specific gotchas in here. I've included the version numbers I've used in parentheses where applicable.


  1. Install Vagrant (1.4.2
  2. Install Virtual Box  (4.3)
  3. Use PuPHPet to create your manifest file. 
    1. Create 2 virtual hosts. One just for flat files to make sure editing our host works fine, and one for Symfony. I call them flathtml.vagrant and symfony.vagrant, so I know what they're referring to. 
    2. The document root for these is /var/www/flathtml/ and /var/www/symfony/ respectively.
    3. These map to the folders /var/www/vagrant/flathtml/ and /var/www/vagrant/symfony/ respectively. 
    4. At least, they will if I run Vagrant from /var/www/vagrant/.
    5. The mapping is taken care of automatically in the PuPHPet manifest, in the "Box Sync" section.
  4. Download those files to wherever it is you want the virtual server to be. I chose /var/www/vagrant/ 
  5. In the Vagrantfile, fine the line that starts with "config.vm.synced_folder" and add ":mount_options => ["dmode=777,fmode=777"]" to the end. Otherwise Symfony will not run.
  6. Using terminal, in /var/www/vagrant/, run "Vagrant Up"
  7. That should work after a while.
  8. Edit your hosts file "sudo gedit /etc/hosts/" and add your two virtual hosts to the file. 
  9. The ip address is your Local VM IP Address. Most likely you left it as 192.168.56.101
  10. Get a test site with flat html working within Vagrant. This ensures that your Virtual server works.
    1. I ran into a problem here once of not being able to get the flat html site working, because the IP address I was being assigned came from DHCP, or similar. The trick is to change the Vagrantfile networking section. I can't remember the exact details of that fix sorry.
  11. Once that is working, then we can start with Symfony
  12. In Terminal, type "cd /var/www/vagrant/symfony"
  13. Install composer by "curl -s https://getcomposer.org/installer | php"
    1. Personally, I like to install it in a central location, such as /var/www/includes/. 
  14. Now install Symfony by "php composer.phar create-project symfony/framework-standard-edition /var/www/vagrant/symfony/ 2.4.*"
  15. You may have to apt-get install php5-json as well.
  16. Now we can initialise the project in PhpStorm. We couldn't earlier as the create-project command will fail if anything is in the folder.
    1. Set up all your version control stuff now.
    2. I found this guy has some very good tips on setting up as well. In particular, steps 3-8.
  17. In app_dev.php and config.php, remove the lines that stop people on none localhost accessing. This will allow you to get to the configurator and make sure everything is working.
There are a lot more things you should be doing, but this is enough to get you up and running at least. I hope this helps someone.

No comments:

Post a Comment