155

I know that I have downloaded a Symfony2 project and started with but I have updated my vendor several times and I want to know which version of symfony I have

Any idea ?

1
  • sonata-project/core-bundle is at version 2.3.9 and sonata-project/admin-bundle is at version 2.3.7, according to the composer show command. Sep 3, 2018 at 9:01

13 Answers 13

257

Run app/console --version (for Symfony3: bin/console --version), it should give you a pretty good idea. On a random project of mine, the output is:

Symfony version 2.2.0-DEV - app/dev/debug

If you can't access the console, try reading symfony/src/Symfony/Component/HttpKernel/Kernel.php, where the version is hardcoded, for instance:

const VERSION         = '2.2.0';

Just in case you are wondering, console creates an instance of Symfony\Bundle\FrameworkBundle\Console\Application. In this class constructor, it uses Symfony\Component\HttpKernel\Kernel::VERSION to initialize its parent constructor.

5
  • 4
    or just take a look at top left in symfony dev bar ( visible only in dev mod ) !
    – zizoujab
    Aug 9, 2013 at 19:56
  • 1
    Thank you so much, found it /Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php
    – HMR
    Sep 23, 2013 at 10:47
  • 11
    for me it's bin/console --version
    – Black
    Apr 20, 2016 at 13:53
  • @Black that's because that's how you check it in Symfony3. OP's answer is for symfony2
    – iii
    Sep 7, 2017 at 15:31
  • It's helpful to me to know that console is a php file. So, just typing app/console ... etc. at the command line does nothing (for me). But php app/console --version successfully runs the file. (Maybe people often have a PHP interpreter set up for their shell's environment?)
    – GG2
    Dec 7, 2018 at 19:57
43

Although there are already many good answers I'd like to add an option that hasn't been mentioned. Using the command:

php bin/console about

you can get many details about the current project. The first section is about Symfony itself and looks like this:

-------------------- ------------------------------------------- 
 Symfony                                                         
-------------------- ------------------------------------------- 
 Version              4.2.3                                      
 End of maintenance   07/2019                                    
 End of life          01/2020                                    
-------------------- ------------------------------------------- 

I find the other information besides the version number very useful.

There are also other sections providing details about the (framework) Kernel, PHP, Environment.

0
26

Another way is to look at the source for Symfony\Component\HttpKernel\Kernel for where const VERSION is defined. Example on GitHub

Locally this would be located in vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php.

0
20

Use the following command in your Terminal/Command Prompt:

php bin/console --version

This will give you your Symfony Version.

0
9

also you can check the version of symfony and versions of all other installed packages by running

composer show

or

composer show | grep sonata

to get versions of specific packages like sonata etc.

7

If you want to dynamicallly display your Symfony 2 version in pages, for example in footer, you can do it this way.

Create a service:

<?php

namespace Project\Bundle\DuBundle\Twig;

class SymfonyVersionExtension extends \Twig_Extension
{


 public function getFunctions()
 {
 return array(
 //this is the name of the function you will use in twig
 new \Twig_SimpleFunction('symfony_version', array($this, 'b'))
   );
 }

public function getName()
{
//return 'number_employees';
 return 'symfony_version_extension';
}   

public function b()
{
 $symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
 return $symfony_version;
}
}

Register in service.yml

 dut.twig.symfony_version_extension:
    class: Project\Bundle\DutBundle\Twig\SymfonyVersionExtension
    tags:
        - { name: twig.extension }
    #arguments: []

And you can call it anywhere. In Controller, wrap it in JSON, or in pages example footer

 <p> Built With Symfony {{ symfony_version() }} Version MIT License</p>

Now every time you run composer update to update your vendor, symfony version will also automatically update in your template.I know this is overkill but this is how I do it in my projects and it is working.

5

we can find the symfony version using Kernel.php file but problem is the Location of Kernal Will changes from version to version (Better Do File Search in you Project Directory)

in symfony 3.0 : my_project\vendor\symfony\symfony\src\Symfony\Component\HttpKernel\Kernel.php

Check from Controller/ PHP File

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
echo $symfony_version; // this will return version; **o/p:3.0.4-DEV**
5

if you trying with version symfony

please try with

symfony 2 +

cmd>php app/console --version

symfony 3+

cmd>php bin/console --version

for example

D:project>php bin/console --version

Symfony 3.2.8 (kernel: app, env: dev, debug: true)
3

For Symfony 3.4

Check the constant in this file vendor/symfony/http-kernel/Kernel.php

const VERSION = '3.4.3';

OR

composer show | grep symfony/http-kernel
1
  • 1
    Both of these approaches still work in February 2023; most of the other answers to the OP's question don't work any more.
    – Henry
    Feb 25 at 22:14
2

From inside your Symfony project, you can get the value in PHP this way:

$symfony_version = \Symfony\Component\HttpKernel\Kernel::VERSION;
1

Maybe the anwswers here are obsolete... in any case, for me running Symfony 4, it is easy Just type symfony -V from the command line.

enter image description here

1
  • 2
    This gives the version of the Symfony CLI client and not the Symfony PHP components. Apr 1, 2021 at 10:47
1

This page is the top Google result for search which version symfony using, and the top answers probably don't work anymore.

Apparently I'm on Symfony 5, after running symfony new aqua_note (from SymfonyCasts recommendation).

I had to ultimately run grep -r VERSION . | grep Kernel to see ./vendor/symfony/http-kernel/Kernel.php: public const VERSION = '5.4.2';... at least I think that's correct now.

1
  • 1
    bin/console --version still works fine for me.
    – zizoujab
    Jan 10, 2022 at 20:43
0

if you are in app_dev, you can find symfony version at the bottom left corner of the page

1
  • 1
    You might need to open the debug toolbar by clicking on the Symfony logo in the bottom right corner of your screen ;)
    – Nic Wortel
    Jul 4, 2014 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.