Beginners Guide to Symfony2.7


In this video we take a look at how we can use the Symfony installer to install a shiny new copy of Symfony 2.7 on our local machine.

We are going to start by looking at the Symfony2.7 demo app. This example uses a Blog as the underlying premise of how a Symfony2.7 site might look after a period of development.

Whilst it's great to have this demo app available to us, it's not necessarily a perfect starting place for learning Symfony in so much as there are lots of files and folders already set up and configured, and this can add to the noise when initially learning the framework.

As such, whilst we cover the demo app in this video, in future videos we will create our own Symfony 2 project and work from there.

Getting Started With Symfony 2.7

If you are using a Mac then - as you will see in the video - you will likely have an issue with your date.timezone setting when first running the installer.

To fix this, do as follows:

sudo cp /etc/php.ini.default /etc/php.ini

You will likely be prompted for your password here.

Next, edit the file to add in your timezone:

sudo vi /etc/php.ini

Feel free to use a different editor to vi, as it's not exactly beginner friendly. This cheatsheet is very useful.

Edit your timezone to one of the accepted PHP timezones.

After making the changes, re-run the check.php script:

php symfony_demo/app/check.php

If you get any further errors / warnings here, Google is your friend. It is very unlikely you are the first to have experienced this issue.

Once that is done, starting a local development server couldn't be easier:

cd symfony_demo
php app/console server:run

The Symfony development server starts up on http://127.0.0.1:3000. Head over to your browser and enter that url.

What's Inside?

It's well worth a look inside the demo application for a number of reasons.

Firstly, you get a good feeling for what a Symfony site can do. Front end - check. Back end - check. View the source code (the big button on each page) and you'll see the code behind that makes this work is also pretty straightforward.

Don't worry if you don't understand the terminology at this point, we will cover all that in this series.

PHPStormy Waters

I strongly recommend you use a dedicated IDE (Integrated Development Environment) for working with Symfony projects. There are a number of reasons for doing so - productivity, inline error checking, awesome Symfony plugins to make development easier - and those are just three of them.

I use PHPStorm, and have only good things to say about it. It works on Mac, Linux, Windows... and if you want to find out more about the cool things it can do, be sure to check out my PHPStorm Shortcuts tutorial series.

Once you have PHPStorm fired up - or whatever editor you're using - be sure to check out the directory contents of your project.

app is where all the Symfony config lives. You will spend a fair amount of time here, whether adding in new Bundles or tweaking some config parameters. There are a number of confusing sounding files in here, but we will cover the important ones in this series.

bin can safely be ignored for now. This holds your projects binaries, which you are unlikely to need to work with directly at this stage.

src is where your project code lives. This is what makes your app actually work. You will spend 90% of your time here.

vendor is where all the third party code lives. This entire folder is handled by composer, the wonderful PHP package manager. Don't worry too much about this folder at this stage, but it is important to know all the code you don't have to write lives in here.

web is the front end of your Symfony site. This is where Symfony will write all your JS, CSS, images and what have you. There's not too much to worry about in here. The most frequently accessed file in here will be the app_dev.php file. We will touch on that later.

Wrap Up

At this stage you have installed and run a standard Symfony2 project. It wasn't hard.

The hard part is wrapping your head around the terminology. That's most of the battle. With a bit of visual assistance (by way of these videos) you can shorten the learning curve and become confident with a Symfony2 installation much more quickly than if all you had to go off was the manual / documentation.

Now that you've seen how a Symfony project is built and structured, we can make our own. That's exactly what we will do in the next video :)

Episodes