This tutorial has a new version, check it out!

Start Project

Video not working?

It looks like your browser may not support the H264 codec. If you're using Linux, try a different browser or try installing the gstreamer0.10-ffmpeg gstreamer0.10-plugins-good packages.

Thanks! This saves us from needing to use Flash or encode videos in multiple formats. And that let's us get back to making more videos :). But as always, please feel free to message us.

Well hey guys! You know what? I'm pumped that you're learning Symfony, because it's the hardest framework ever! Relax, I'm kidding. Symfony does have a reputation for being tough to learn, but this is a trap! Or at least, it's an outdated idea.

Look: Symfony can be incredibly simple and will put you in a position to write powerful, well-designed code, whether it's for an API or a traditional web app. And when it does get a bit more difficult, it's usually because you're learning best practices and object oriented goodness that's turning you into a better developer.

Symfony Components & Framework

So what is Symfony? First, it's a set of components: meaning PHP libraries. Actually, it's about 30 small libraries. That means that you could use Symfony in your non-Symfony project today by using one of its little libraries. One of my favorites is called Finder: it's really good at searching deep into directories for files.

But Symfony is also a framework where we've taken all of those components and glued them together for so that you can get things done faster. This series is all about doing amazing things with the Symfony framework.

The Symfony Installer

Let's get our first Symfony project rolling. Head over to Symfony.com and click 'Download'. Our first task is to get the Symfony Installer. Depending on your system, this means running commands from one of these boxes. Since I'm on a mac, I'll copy the curl command and paste it into the terminal:

sudo curl -LsS https://symfony.com/installer -o /usr/local/bin/symfony

Copy the second command and run that to adjust some permissions:

sudo chmod a+x /usr/local/bin/symfony

This gives us a new symfony executable:

symfony

But hold on! This is not Symfony, it's the Symfony Installer: a tiny utility that makes it really easy to start new Symfony projects.

Downloading the Project

Let's start one! Run symfony new and then the name of the project. Call the project aqua_note:

symfony new aqua_note

I'll tell you more about it soon. In the background this is downloading a new Symfony project, unzipping it, making sure your system is configured, warning you of any problems and then dropping the new files into this aqua_note directory. Not bad!

Tip

The project name - aqua_note - is only used to determine the directory name: it's not important at all afterwards.

Move into the directory and check it out.

cd aqua_note
ls

This is also not Symfony: it's just a set of files and directories that form a web app that use the Symfony libraries. Those libraries - along with other third-party code - live in the vendor/ directory.

Before I explain the other directories, let's get this thing working! Run:

php bin/console server:run

to start the built in PHP web server. Yes, you can also use Nginx or Apache: but this is much easier for development. When you're done later, just hit Ctrl+C to stop the server.

As the comment says here, go to http://localhost:8000 in your browser. And boom! Congrats! This is your first page being executed by the Symfony framework. That's right: this is being rendered dynamically from the files inside of your project. At the bottom, you'll see one of the best features of Symfony: the web debug toolbar. This is full of debugging information - more on that later.

Ok, let's start building our own pages!

Leave a comment!

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": ">=5.5.9",
        "symfony/symfony": "3.1.*", // v3.1.4
        "doctrine/orm": "^2.5", // v2.7.2
        "doctrine/doctrine-bundle": "^1.6", // 1.6.4
        "doctrine/doctrine-cache-bundle": "^1.2", // 1.3.0
        "symfony/swiftmailer-bundle": "^2.3", // v2.3.11
        "symfony/monolog-bundle": "^2.8", // 2.11.1
        "symfony/polyfill-apcu": "^1.0", // v1.2.0
        "sensio/distribution-bundle": "^5.0", // v5.0.22
        "sensio/framework-extra-bundle": "^3.0.2", // v3.0.16
        "incenteev/composer-parameter-handler": "^2.0" // v2.1.2
    },
    "require-dev": {
        "sensio/generator-bundle": "^3.0", // v3.0.7
        "symfony/phpunit-bridge": "^3.0" // v3.1.3
    }
}