Setting up Symfony2 on a Windows 7 Environment

So, I’ve put it off long enough. I’ve been in this development game for near on 10 years and have yet to delve into the world of full stack MVC frameworks. The closest I have come so far is extensive Silverstripe CMS development, which hinges on it’s own framework dubbed Silverstripe Framework (formally known as sapphire).

Now, in coalition with another personal project, I’ve decided to take the plunge and learn what all the hype is about with this Symfony2 thing. This, of course starts with building a development environment on my Windows 7 machine, so I have documented what I have learned along the way for future reference for others. So here is my environment:

  • XAMPP server stack
  • Symfony2 standard (no vendors)
  • Netbeans IDE

The Server Stack

I’ll start by saying that my server stack of choice for most of my career has been WAMP. This is partially due to ease of use, partially due to laziness in finding an alternative. What I did find during this process is that WAMP is a bit difficult to get running Symfony effectively. To be more exact, I (and others) found that XAMPP worked very well with Symfony straight out of the box, so that’s where we’ll start.

  1. Download the latest version of XAMPP from http://www.apachefriends.org/en/xampp-windows.html#641
  2. Install XAMP on your Windows machine. NOTE: When prompted, do NOT install Apache and MySQL as services. Take note of the path you install XAMPP in. (I installed mine in C:\xampp)

Next, to help us with Symfony2 command line calls later, we need to add the path to XAMPP’s php and mysql binaries to our Windows system path:

  1. Go to Start -> Control Panel -> System
  2. Click the “Advanced system settings” link at the far left
  3. Click the “Environment Variables” button in the dialog that appears
  4. In the lower text area labelled “System variables”, find the “Path” entry in the list and double click it
  5. In the “Variable value” field, add a semi-colon to the very end of the line (if it doesn’t already have one)
  6. Add the path to your XAMPP’s php and mysql binaries after to the end of the line. If you installed XAMPP in the same place as I did, these additions will be as follows:
C:\xampp\php;C:\xampp\mysql

You can test that your System path has been updated by checking your version of PHP in your cmd console (or PowerShell)

  1. Go to Start and in the search box type “cmd” and press enter
  2. At the opening prompt, type “php -v”. Your version of PHP should be displayed in the space below.

 

For the remainder of this tutorial, please make sure that XAMPP is on, and you have started Apache and MySQL.

Symfony2

Get a hold of the latest standard edition of Symfony2. We are going to use this download two-fold: Once to link to Netbeans so it has Symfony support and code completion. And once again (or more) to use as the base library for our first project.

  1. Go to http://symfony.com/download
  2. In the dropdown box, select “Symfony Standard [latest version] without vendors (.zip)”
  3. Click the download button
  4. When download is complete, make a copy of the ZIP file and place it somewhere central without unpacking. E.G. C:\symfony2_source. This will serve as our support library in Netbeans.

The IDE

There are many IDE’s out there, and it usually boils down to personal preference (and cost) for most developers. For me, Netbeans is my weapon of choice, and if you haven’t tried it, I suggest you give it a go.

  1. Download the latest stable release of Netbeans at http://netbeans.org/downloads/start.html?platform=windows&lang=en&option=php (download will start automatically)
  2. Install Netbeans in your directory of choice, the default is usually fine.
  3. When installation is complete, run Netbeans

At the time of writing, Netbeans does not have native support for Symfony2 (although it does support Symfony1.x). So for now, there is a little setup we must do to allow Netbeans to hook into the library and give us code completion goodness. The following setup is done inside the IDE.

  1. Go to Tools -> Plugins
  2. Hit the “Available Plugins” tab
  3. Hit the “Refresh Catalog” button at top left
  4. In the search box at top right, type “symfony2” and press enter
  5. You should see Tomas Mysik’s Symfony2 plugin appear in the result box on the left.
  6. Check the checkbox to the left of this plugin
  7. Hit the “Install” button at bottom left
  8. When installed, restart Netbeans.

After Netbeans restarts, it’s time to link it to the Symfony2 archive you downloaded:

  1. Go to Tools -> Options
  2. Hit the “Symfony2” tab
  3. You will see a file text field at the top of the window. Hit the browse button.
  4. Navigate to where you copied your archive to (in my case, it was C:\symfony2_source) and select the ZIP file
  5. Make sure “Ignore cache Directory by Default” is checked
  6. Hit the “OK” button at the bottom right of the screen.

 

TWIG

TWIG is one of the more popular templating engines available for Symfony2. After using it already, I can see why it is popular. I’ll get into TWIG later in the series, but for now, we need to setup Netbeans to parse and colour code TWIG files for us to make life easier.

  1. Go to https://github.com/blogsh/Twig-netbeans/downloads
  2. Download the latest version of the nbtwig plugin. It should be at the top. These .nbm files are Netbeans plugins.
  3. Open up Netbeans
  4. Go to Tools -> Plugins
  5. Hit the “Downloaded” tab
  6. Hit the “Add Plugins” button at top left
  7. Navigate to where you downloaded the nbtwig file above and double click it

This will install TWIG support for Netbeans.

 

Final Tweaks

There are few final tweaks you can make to Netbeans that will make life a lot easier down the track:

  1. Go to Tools -> Options
  2. Hit the PHP icon at the top of the dialog (not a tab)
  3. In the General tab, you will see a file text field for “PHP 5 Interpreter”
  4. Hit the “Browse” button and navigate to your XAMPP php binary. If you installed XAMPP in the same place as me, this will be located in C:\xampp\php\php.exe

 

Create your first Symfony2 project!

Now for the good stuff. Let’s make a project that includes the base Symfony libary to get us started. For this, you want to make sure that XAMPP, MySQL and Apache are all running (see XAMPP instructions above). Because of the setup we have done, we can do all of this direct from Netbeans:

  1. Go to File -> New Project
  2. Select “PHP Application” in the “Projects” textarea to the right.
  3. Hit the “Next” button
  4. In the next window, call your project “FirstSymfonyProject”
  5. In the sources text field, click the “Browse” button. Navigate to your XAMPP installation’s “htdocs” directory and create a new folder called “first_symfony_project”. Hit the “Open” button.
  6. Hit the “Next” button
  7. Leave the run configuration as default and click the “Next” button
  8. In the final Frameworks screen, tick the check box beside “Symfony2 PHP Web Framework”
  9. Hit the finish button

This action, because of the setup we have done above, will create a base Symfony site for you to start working on. But don’t take my word for it, check out your new project by opening a browser and heading over to http://localhost/first_symfony_project/web/app_dev.php (assuming XAMMP is on and you have followed the above directions exactly)

Boom! All going well, you should see something like this:

 

First Symfony project on Windows 7

You now have a starting platform for beginning on Symfony. In following posts, I will go deeper into actual development using this monster, so stay tuned. If you have any problems or corrections with the above, let me know in the comments.

16 thoughts on “Setting up Symfony2 on a Windows 7 Environment

  1. I also need some help. Xampp is simple and I like it. I put my weistbe files in wwwroot on my server 2003 R2 and after many days of errors and problems I finally installed php and phpinfo opens correctly. My last problem is about the contact form that asks for name, email and comment. Everything works as it should according to my browser, thankyou page etc. but I never get an email on my predefined email in php script.How can someone help me here, can I get someone’s mail address to send my php?

    • Hi Richard. I hope you’ve sorted this problem by now, but I would say the issue here is that you have a misconfigured mail setting in your php and the email is simply being lost locally on Windows Server’s own SMTP server.

      It could be code related, but it’s just not possible to tell without seeing the code.

      If you are still having problems, try this on a blank PHP script:

      mail('my@emailaddress.com', 'Test Subject', 'This is test content');

      Obviously replace that email address with your own and run the script in a browser.

      If you get an email, you probably have a code problem. But I am picking that you won’t get and email, which means your PHP.ini or your Windows SMTP setup is misconfigured.

      I’m afraid sending your code to someone won’t help until you’ve worked this part. In which case, you’ll find lots of help over at http://stackoverflow.com/

      Good luck!

  2. Hi there,
    I have finished all the steps properly but I got some problem when I tried to browse it…
    Warning: require(C:\xampp\htdocs\first_symfony_project\app/../vendor/autoload.php): failed to open stream: No such file or directory in C:\xampp\htdocs\first_symfony_project\app\autoload.php on line 5

    Fatal error: require(): Failed opening required ‘C:\xampp\htdocs\first_symfony_project\app/../vendor/autoload.php’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\first_symfony_project\app\autoload.php on line 5

    what will I do now…??

  3. I had trouble installing using composer, which gave error warnings when downloading the package.

    I fixed it by running ‘composer update’ immediately after ‘composer create-project…’

  4. Hi i have window7 os , i getting this msg time to time . is any solution for that problem
    UnexpectedValueException: The stream or file “D:/wamp/www/webapp/app/logs/dev.log” could not be opened: failed to open stream: Permission denied

    • Hey thanks very much for this. The post is a bit old now and it’s good to have alternatives for everyone to check out. I’ll give Bitnami a try and update this post if I find it circumvents most of the steps. Thanks again, Steven.

  5. Hello Sir am having error when i run ,which is
    Warning: require(C:\xampp\htdocs\first_symfony_project\app;C:\xampp\php\PEAR): failed to open stream: Invalid argument in C:\xampp\htdocs\first_symfony_project\app\autoload.php on line 9

    Fatal error: require(): Failed opening required ‘C:\xampp\htdocs\first_symfony_project\app;C:\xampp\php\PEAR’ (include_path=’.;C:\xampp\php\PEAR’) in C:\xampp\htdocs\first_symfony_project\app\autoload.php on line 9

    and when i run config.php,this is what it bring as a major problem.

    Vendor libraries are missing. Install composer following instructions from http://getcomposer.org/. Then run “php composer.phar install” to install them.

    How can i solve this problem please help

Leave a Reply to Jones03 Cancel reply

Your email address will not be published. Required fields are marked *