Flag of Ukraine
SymfonyCasts stands united with the people of Ukraine
This tutorial has a new version, check it out!

The Lovely bin/console Tool

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.

Let's commit our progress so far. I'll clear the screen and run:

git status

Interesting: there are a few new files here that I didn't create. Don't worry: we're going to talk about that exactly in the next chapter. Add everything with:

git add .

Normally... this command can be dangerous - we might accidentally add some files that we don't want to commit! Fortunately, our project came with a pre-filled .gitignore file which ignores the important stuff, like vendor/ and some other paths we'll talk about later. For example, var/ holds cache and log files. The point is, Symfony has our back.

Commit with:

git commit -m "we are ROCKING this Symfony thing"

Hello bin/console Command

You can interact with your Symfony app in two different ways. The first is by loading a page in your browser. The second is with a handy command-line script called bin/console. At your terminal, run:

php bin/console

Woh! This command lists a bunch of different things you can do with it, including a lot of debugging tools. Now, just to demystify this a little, there is literally a bin/ directory in our app with a file called console inside. So this bin/console thing is not some global command that got installed on our system: we are literally executing a physical PHP file.

The bin/console command can do many things - and we'll discover my favorite features along the way. For example, want to see a list of every route in your app? Run:

php bin/console debug:router

Yep! There are our two routes... plus another one that Symfony adds automatically during development.

The bin/console tool already contains many useful commands like this. But the list of commands it supports is not static. New commands can be added by us... or by new packages that we install into our project. That's my "not-so-subtle" foreshadowing.

Next: let's talk about Symfony Flex, Composer aliases and the recipes system. Basically, the tools that makes Symfony truly unique.

Leave a comment!

14
Login or Register to join the conversation
Rizky A. Avatar
Rizky A. Avatar Rizky A. | posted 1 year ago

php bin/console security:check

The web service failed for an unknown reason (HTTP 403).

T_T how to fix it?

Reply
Deeptonabho D. Avatar
Deeptonabho D. Avatar Deeptonabho D. | Rizky A. | posted 1 year ago

Hi Rizky, the sensiolabs/security plugin has been deprecated, you
have to use the php-local-security-checker package,whcih serves the same
purpose. https://github.com/fabpot/l...

1 Reply

Hey Rizky,

It's recommended to use "symfony security:check" command instead. Otherwise, try to upgrade the "sensiolabs/security-checker" package with Composer to the latest, but if you're on a not maintained Symfony version - you would need to upgrade Symfony packages in your project first. So I'd recommend you to go with "symfony security:check".

Cheers!

Reply
Azar A. Avatar

Hey Victor!
Is it possible to run symfony security: check after executing compsoer install as described in the instructions where the author worked with security: check

Reply

Hey Azar,

Good question! Actually, it is possible, for example with this syntax:


{
"scripts": {
"auto-scripts": {
// ...
"symfony security:check": "script"
},
},
}

I.e. you should use "script" instead of "symfony-cmd". But it will also mean that you always have installed symfony CLI on the machine where you run any Composer operations in your project, otherwise it will fail.

Another solution - just add an extra step to your CI to run that "symfony security:check" as a separate step instead of doing this during Composer operations like install or update :)

Cheers!

Reply
Azar A. Avatar

Could you tell in more detail how exactly to do this through CI, or where to read :)

Reply

Hey Azar,

Well, you just need to download that "symfony" CLI on your CI and add a new step to your tests steps that will execute "symfony security:check" - pretty simple if you have a CI :) If you don't, take a look at: https://symfonycasts.com/sc... about a possible example how to configure a CI first. Or read the docs about GitHub Actions.

I hope this helps!

Cheers!

Reply
Nikolay S. Avatar
Nikolay S. Avatar Nikolay S. | posted 2 years ago

Hi,
Is it possible to encode a symfony project with ionCube without breaking it?

Reply

Hey Niki,

I know very little about ionCube, but yes, I suppose it should be possible as long as you warm up the cache before encoding. Basically, Symfony app should generate all the necessary cache and compile all necessary files during the cache:warmup command. After this, you can run Symfony app on read-only filesystem and it should just work. Of course, it also depend on you and your code. I suppose you should avoid writing to the filesystem in your code, only read operations, or probably use a different cache providers like Memcache or Redis, etc.

I hope this helps, unfortunately, I can't say more about it.

Cheers!

Reply

Hi Ryan, totaly unrelated question ... but how do you do to display a dotted line after each instruction in your command line interface ?

This is super useful !

Reply

Finally got something working :)

# ~/.zshrc
# <<< dotted line between command >>>
setopt promptsubst
PS1=$'%F{250}${(r:$COLUMNS::╌:)}%f'$PS1

Reply

Hey Mickael!

Glad you was able to figure it out yourself! Ryan *just* started using this new terminal theme - he's using zsh with ohmyzsh. Inside ohmyzsh, he's using the "af-magic" theme with some customizations. Here's my custom theme file - https://gist.github.com/wea... - it's the "af-magic" theme but (mostly) with a few features *removed* to keep his screen simpler.

I hope that helps :)

Cheers!

Reply
Jason A. Avatar
Jason A. Avatar Jason A. | posted 2 years ago

In Chapter 01 the Symfony executable is downloaded. Is there a reason why in this chapter php bin/console is used instead of symfony console other than that it might be shorter to type?

Reply

Hey Jason Aller!

Excellent question! It is mostly to introduce concepts little-by-little. By showing php bin/console, it's easy to show that you're just executing a normal, boring, physical file. But symfony console looks a bit more "magical", even though it's technically a lot more useful (because you can manage PHP versions through it, run commands un "tunneled" SymfonyCloud environments etc). I'm planning to introduce doing more things with the symfony command little-by-little - it'll especially be important when we talk about databases.

Cheers!

Reply
Cat in space

"Houston: no signs of life"
Start the conversation!

This tutorial also works great for Symfony 6!

What PHP libraries does this tutorial use?

// composer.json
{
    "require": {
        "php": "^7.3.0 || ^8.0.0",
        "ext-ctype": "*",
        "ext-iconv": "*",
        "easycorp/easy-log-handler": "^1.0.7", // v1.0.9
        "sensio/framework-extra-bundle": "^6.0", // v6.2.1
        "symfony/asset": "5.0.*", // v5.0.11
        "symfony/console": "5.0.*", // v5.0.11
        "symfony/debug-bundle": "5.0.*", // v5.0.11
        "symfony/dotenv": "5.0.*", // v5.0.11
        "symfony/flex": "^1.3.1", // v1.17.5
        "symfony/framework-bundle": "5.0.*", // v5.0.11
        "symfony/monolog-bundle": "^3.0", // v3.5.0
        "symfony/profiler-pack": "*", // v1.0.5
        "symfony/routing": "5.1.*", // v5.1.11
        "symfony/twig-pack": "^1.0", // v1.0.1
        "symfony/var-dumper": "5.0.*", // v5.0.11
        "symfony/webpack-encore-bundle": "^1.7", // v1.8.0
        "symfony/yaml": "5.0.*" // v5.0.11
    },
    "require-dev": {
        "symfony/profiler-pack": "^1.0" // v1.0.5
    }
}