Symfony 4: Our Micro-App and PhpStorm Setup

Video loading...

  • 0:03
    Symfony 4: Our Micro-App and PhpStorm Setup with Ryan Weaver
  • 0:08
    Our mission: To boldly go where no one has gone before…
  • 0:12
    by checking out our app.
  • 0:15
    I already opened the new directory in PHPStorm.
  • 0:18
    So, fire up your tricorder and let’s explore.
  • 0:22
    There are only 3 directories you need to think about.
  • 0:26
    First, public is the document route,
  • 0:29
    so it will hold all publicly accessible files.
  • 0:33
    And, there's just 1 right now – index.php –
  • 0:37
    this is the front controller –
  • 0:40
    a fancy word programmers invented that means that
  • 0:45
    this is the file that’s executed whenever you go to any URL.
  • 0:49
    But really, you almost never need to worry about it.
  • 0:53
    In fact, now that we’ve talked about this directory,
  • 0:56
    stop thinking about it.
  • 0:58
    Yeah, I lied.
  • 1:00
    There are truly only 2 directories you need to think about,
  • 1:05
    config and source.
  • 1:08
    Config holds some, you know, config files.
  • 1:12
    And source is where you’ll put all your PHP code.
  • 1:17
    It’s just that simple.
  • 1:20
    Where is Symfony?
  • 1:22
    As usual, when we created the project,
  • 1:24
    Composer read our composer.json file
  • 1:27
    and downloaded all the third-party libraries,
  • 1:30
    including parts of Symfony,
  • 1:32
    into the vendor directory.
  • 1:35
    Go back to your terminal and find the original tab.
  • 1:40
    Check this out,
  • 1:41
    at the bottom it says that we can get a better web server
  • 1:45
    by running, composer require server.
  • 1:48
    I like better stuff,
  • 1:50
    so let’s try it.
  • 1:52
    Press CTRL+C to stop the existing server
  • 1:54
    and then run, composer require server.
  • 1:59
    If you're familiar with Composer,
  • 2:02
    that package name should look funny…
  • 2:05
    really wrong.
  • 2:07
    Normally, every package name is something/something,
  • 2:12
    like Symfony/console.
  • 2:15
    So, server just should not work, but it does.
  • 2:22
    This is part of a cool new system called Flex.
  • 2:25
    More about that soon.
  • 2:27
    When this finishes, you can now run ./bin/console server:run.
  • 2:33
    This does basically the same thing as before, but the command is shorter.
  • 2:38
    And, when we refresh, it still works.
  • 2:42
    By the way,
  • 2:43
    this bin/console command is going to be our new robot sidekick.
  • 2:48
    But it’s not magic.
  • 2:50
    Our project has a bin directory with a console file inside.
  • 2:55
    Windows users should say
  • 2:57
    php bin/console because it’s just a PHP file.
  • 3:02
    So, what amazing things can this bin console robot do?
  • 3:06
    Find your open terminal tab and just run, ./bin/console
  • 3:11
    Yes! This is a list of all of the bin/console commands.
  • 3:17
    Some of these are debugging gold.
  • 3:20
    We’ll talk about them along the way.
  • 3:23
    OK, we are almost ready to start coding,
  • 3:27
    but we need to talk about our spaceship.
  • 3:30
    I mean, Editor.
  • 3:32
    Look, you can use whatever you want,
  • 3:35
    but I highly recommend PHPStorm.
  • 3:39
    Seriously, it makes developing in Symfony a dream.
  • 3:43
    And no, those nice guys and gals
  • 3:46
    at PHPStorm aren’t paying me to say this,
  • 3:49
    but they can if they want to.
  • 3:51
    If you do use it, which would be awesome for you,
  • 3:55
    there are 2 secrets you need to know to trick out your spaceship…
  • 4:00
    uh, Editor.
  • 4:01
    Clearly I was in hyper-sleep too long.
  • 4:04
    Go to Preferences,
  • 4:07
    Plugins, then click Browse repositories.
  • 4:12
    There are 3 must-have plugins.
  • 4:15
    Search for Symfony.
  • 4:18
    First, the Symfony plugin.
  • 4:20
    It has over 2 million downloads for a reason.
  • 4:24
    It will give you tons of ridiculous auto-completion.
  • 4:29
    You should also download PHP Annotations and PHP Toolbox.
  • 4:34
    I already have them installed.
  • 4:36
    If you don’t,
  • 4:37
    you'll see an Install button right at the top of the description.
  • 4:41
    Install those and restart PHPStorm.
  • 4:44
    Then, come back to Preferences, search for Symfony,
  • 4:49
    and find the new Symfony section.
  • 4:52
    Click the Enable Plugin checkbox.
  • 4:55
    You need to enable the Symfony plugin for each project.
  • 4:59
    It says you need to restart, but I think that’s a lie.
  • 5:03
    It’s space, what could go wrong?
  • 5:07
    So, that’s PHPStorm trick #1.
  • 5:10
    For the second, search Composer,
  • 5:13
    and click on the Composer section.
  • 5:16
    Click to browse for the path to composer.json,
  • 5:19
    and select the one in our project.
  • 5:21
    I’m not sure why this isn’t automatic, but, whatever.
  • 5:26
    Thanks to this,
  • 5:27
    PHPStorm will make it easier to create classes in source.
  • 5:31
    You'll see this really soon.
  • 5:34
    OK, our project is set up and it’s already working.
  • 5:38
    Let’s start building some pages
  • 5:39
    and discovering more cool things about our new app.

Symfony 4: Our Micro-App and PhpStorm Setup

Loading...

In this tutorial, we'll get oriented with our app and set up PhpStorm for Symfony 4 development.

Downloads: 
Log in or sign up to download companion files.
Additional resources: