PHP Symfony and WAMPserver

Over the last few weeks I’ve been investigating some new tools for my coding toolbox, particularly in light of getting to grips a lot more with MVC in .net during my time at the uni – as I’ve started looking at some more modern PHP frameworks, I’ve found that there are some brilliant ones out there that match the structured MVC approach, but in a language I’m a lot more comfortable working in.

In my last post I mentioned Laravel, but the framework I’m actually gravitating more towards is Symfony. I’ve been playing mainly with this for a few days now, porting a flat PHP project I’ve been working on – it’s just a simple database manager, but it’s given me a good understanding of how to slot the different pieces of Symfony together to build an application. One of the things I particularly like is the developer toolbar – lots of really rich stuff coming through there when you run apps.

Getting Symfony running is actually dead easy and I spent my first day tinkering through the initial tutorials, however I have noticed that the PHP server that you can bundle into your projects isn’t entirely reliable, sometimes not working and sometimes causing fatal errors. This is likely to be an environmental issue as I tend to develop on Windows machines using WAMPserver, so I looked into some alternatives such as running in a VM. In all honesty, while I’m happy setting up VM’s, I’ve never used something like Vagrant and really don’t know where to start, so I looked into getting Symfony running better on WAMP. This was, in actuality, dead easy.

1) Install and set up Symfony

Just follow the instructions here. Get Composer installed, set up a new Symfony project within the www folder of your WAMP installation, but don’t run the PHP server. Instead…

2) Install the Apache Module

Instructions are here. This needs to be installed within your new Symfony project so you’ll need to do this on a per-project basis (fact check – if this isn’t correct, please shout up in the comments). This will pop a .htaccess file in the public folder of your project.

3) Hit up your project in a browser

So, with your WAMPserver running, head to http://localhost/{my-project}/public to see your project. It should be an error screen until you get some controllers up and running.

4) Give your project a nice URL

If you want to head to that URL every time you want to access your project, you go right ahead. However, it might be easier to set up a Virtual Host to allow you to access it from a nice url like http://my-project.localhost (not .dev – I told you why not last week!) To do this you need to click on the WAMPserver icon in your system tray, click on Virtual Hosts and Virtual Host management. When setting up your host, make sure you point the path at the /public folder of your project.

And there you go! One of the reasons I’m doing this is that, while the symfony code would run without the Apache module, it was somewhat error prone and didn’t route correctly – moreover, the developer toolbar threw errors which obviously isn’t good. With these extra steps we can get projects running easily on Apache and, it makes sense for me as I’ll be using them to tie into a MySQL database, so I’d need WAMPserver running anyway.

Hope this helps!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s