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.
- Download the latest version of XAMPP from http://www.apachefriends.org/en/xampp-windows.html#641
- 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:
- Go to Start -> Control Panel -> System
- Click the “Advanced system settings” link at the far left
- Click the “Environment Variables” button in the dialog that appears
- In the lower text area labelled “System variables”, find the “Path” entry in the list and double click it
- In the “Variable value” field, add a semi-colon to the very end of the line (if it doesn’t already have one)
- 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:
You can test that your System path has been updated by checking your version of PHP in your cmd console (or PowerShell)
- Go to Start and in the search box type “cmd” and press enter
- 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.
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.
- Go to http://symfony.com/download
- In the dropdown box, select “Symfony Standard [latest version] without vendors (.zip)”
- Click the download button
- 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.
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.
- Download the latest stable release of Netbeans at http://netbeans.org/downloads/start.html?platform=windows&lang=en&option=php (download will start automatically)
- Install Netbeans in your directory of choice, the default is usually fine.
- 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.
- Go to Tools -> Plugins
- Hit the “Available Plugins” tab
- Hit the “Refresh Catalog” button at top left
- In the search box at top right, type “symfony2” and press enter
- You should see Tomas Mysik’s Symfony2 plugin appear in the result box on the left.
- Check the checkbox to the left of this plugin
- Hit the “Install” button at bottom left
- When installed, restart Netbeans.
After Netbeans restarts, it’s time to link it to the Symfony2 archive you downloaded:
- Go to Tools -> Options
- Hit the “Symfony2” tab
- You will see a file text field at the top of the window. Hit the browse button.
- Navigate to where you copied your archive to (in my case, it was C:\symfony2_source) and select the ZIP file
- Make sure “Ignore cache Directory by Default” is checked
- Hit the “OK” button at the bottom right of the screen.
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.
- Go to https://github.com/blogsh/Twig-netbeans/downloads
- Download the latest version of the nbtwig plugin. It should be at the top. These .nbm files are Netbeans plugins.
- Open up Netbeans
- Go to Tools -> Plugins
- Hit the “Downloaded” tab
- Hit the “Add Plugins” button at top left
- Navigate to where you downloaded the nbtwig file above and double click it
This will install TWIG support for Netbeans.
There are few final tweaks you can make to Netbeans that will make life a lot easier down the track:
- Go to Tools -> Options
- Hit the PHP icon at the top of the dialog (not a tab)
- In the General tab, you will see a file text field for “PHP 5 Interpreter”
- 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:
- Go to File -> New Project
- Select “PHP Application” in the “Projects” textarea to the right.
- Hit the “Next” button
- In the next window, call your project “FirstSymfonyProject”
- 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.
- Hit the “Next” button
- Leave the run configuration as default and click the “Next” button
- In the final Frameworks screen, tick the check box beside “Symfony2 PHP Web Framework”
- 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:
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.