Sunday 9 December 2012

PhpStorm, Symfony 2 and GIT

I've recently started a new job, and after 2 years of using Ubuntu I'd had enough and wanted to try out Windows 7. Basically, I got sick of running two operating systems, and as my macbook is getting a bit long in the tooth I decided to try and get everything working under Windows 7. These instructions worked for me.
  • Install wampserver2
  • Download and install Composer using the Windows Installer option.
  • Download and install GIT (only if you're using it, but at some point in your development life you will be, so you may as well install it now
  • When installing GIT, make sure to select the middle option, that allows GIT to be run from the command line (the cli in some documentation)
  • Download and install the trial version of PhpStorm. You may not like it so no point paying until you have trialled it.
At this point you should have a working version of everything you need. Here's how to test it, to make sure everything actually works. 
  1. Use Composer to install the Symfony 2 framework. I'd highly recommend that you do this in the wamp/www folder to save yourself time.
    • On the Symfony website, they say to use composer.phar . It should be updated to read "composer". Composer installed a .bat file that will do all the hard work for you.
    • The "path/" in the command is the folder to install it into. If you're in the www folder, use "symfony" or something similar.
    • The full command to run from the c:\wamp\www\ folder is now "php compose create-project symfony/framework-standard-edition symfony/ 2.1.4"
  2. If you have yet to install GIT, you won't be able to install Ascetic. If GIT is installed correctly, then we also know that GIT is installed and working correctly!
    • If it failed at this point, then go back and install GIT. Then from the command line, run "composer update" in the c:\wamp\www\symfony\ folder.
    • This will read the composer.json file and download/update components. Most importantly, it will add in the missing components such as Ascetic as the git command is now available.
    • If for some reason that didn't work, close the command prompt window and try this again in a new one.
  3. Open PhpStorm
  4. Create a project, from existing sources, where we just installed Symfony 2 to. Select the bottom option, as the files are local and we don't yet have a server set up. 
  5. You should get a few "error" messages, as this is the first time you've worked with PhpStorm. It'll prompt you to say you're using the Symfony 2 framework. Follow the prompts to fix this.
  6. It will probably also say GIT is not installed. It's wrong, but click fix button.
  7. In the dialog, you'll see it's looking for "git.cmd". Change that to "git". Click the test button to prove it worked.
  8. Now, open the .gitignore file in PhpStorm
  9. At the bottom, add the lines ".idea/*". This folder is where PhpStorm keeps a record of stuff about the project, and we do not want this committed.
  10. Right click the name of the project in the left hand panel, and select GIT -> Add. This should add our entire directory to GIT. I like to do this so I can always tell what files I have played around with whenever I'm doing anything.
  11. Next, right click again, GIT -> Commit Directory. Now that we've added the files to the list of files to be indexed by GIT, we need to commit the files to the repository. (note, that is a very simple explanation of what a VCS does)
  12. Double check the .idea folder is ignored (i.e. There are no files to be committed from that directory)
  13. Mouseover the commit button, and select commit.
  14. I tend to ignore the review option but you may want to have a look to see what errors/todo's have been left in the code.
One last thing that you may find useful. Run a "composer update" from the root directory of the project. Changes are the version of Symfony 2 you've downloaded is slightly out of date, and this will go through and check everything.

That's it. I've assumed you're comfortable with the command line. If you're not, well, there's no time like the present to learn!

Leave a comment if I've missed a step or something isn't clear :)

No comments:

Post a Comment