How to setup a Symfony 2 project under Windows

I’ve decided to write this short tutorial on how to setup a Symfony 2 project in Windows mainly because all the good tutorials (including the Symfony website) display most of the info for Linux environments. While this is perfectly justified, there are still people who prefer Windows (or who are using multiple OS at a time). In this case (Windows), there are some slight differences.

Prerequisites:

  • WAMP or XAMPP. Either stack will do. I used to be a WAMP fan mostly due to its site having much better organization, but now I stick with XAMPP due to much better installer and better control panel.
  • Composer. By default, composer will install the executable in the Windows path. During setup, it will also ask you to point it to the php.exe (path depending on which stack you’ve chosen).
  • cURL: use the download wizard.

Project setup:

  • unlike linux, you only need to run one command as you don’t need to complicate yourself with cURL-ing a phar or anything like that.
  • the command to run is:

    composer create-project symfony/framework-standard-edition <path-to-webroot>project-folder 2.4.*
    

Replace the path-to-webroot with the proper path to webroot according to the stack you installed (usually ends with some htdocs folder inside the wamp or xampp folder created during installation – unless you’ve set a different path in your .htdocs apache config file).
Also, feel free to specify different versions of the framework (example states 2.4.* as it’s the latest at this time).
By default, the command will download all the necessary vendors for your project, but in case something happens, please refer to the Symfony 2 official installation manual.

It is also a good idea to create a virtual host for your Symfony 2 project by adding the following at the end of your httpd.conf file. If unsure where to find it, just search inside the folder of your xampp/wamp installation folder:

NameVirtualHost 127.0.0.1

<VirtualHost 127.0.0.1>
      ServerName <project-folder>
      DocumentRoot "<path-to-webroot>/<project-folder>/web"
      DirectoryIndex app.php
      <Directory "<path-to-webroot>/<project-folder>/web">
        AllowOverride All
        Allow from All
      </Directory>
</VirtualHost>

You will also need to edit a file located at %systemroot%system32driversetc (the Windows hosts file – usually c:WindowsSystem32driversetchosts). Just make sure the program you use to open and edit the file is run as Administrator. Once the file is opened, add the following:

127.0.0.1     <project-folder>

If all went well (and after restarting the Apache webserver) visiting

http://<project-folder>/app_dev.php

will greet you with the Symfony 2 default welcome page. To get you started on Symfony 2, here is the best tutorial I found. Another good Symfony 2 tutorial can be found here.

Happy coding!