153

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 ?

zizoujab
  • 7,603
  • 8
  • 41
  • 72

13 Answers13

255

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.

Jpsy
  • 20,077
  • 7
  • 118
  • 115
Diego Agulló
  • 9,298
  • 3
  • 27
  • 41
  • 4
    or just take a look at top left in symfony dev bar ( visible only in dev mod ) ! – zizoujab Aug 09 '13 at 19:56
  • 1
    Thank you so much, found it `/Symfony/vendor/symfony/symfony/src/Symfony/Component/HttpKernel/Kernel.php` – HMR Sep 23 '13 at 10:47
  • 11
    for me it's `bin/console --version` – Black Apr 20 '16 at 13:53
  • @Black that's because that's how you check it in Symfony3. OP's answer is for symfony2 – iii Sep 07 '17 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 07 '18 at 19:57
42

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.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
cezar
  • 11,616
  • 6
  • 48
  • 84
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.

Adam Elsodaney
  • 7,722
  • 6
  • 39
  • 65
19

Use the following command in your Terminal/Command Prompt:

php bin/console --version

This will give you your Symfony Version.

hcoat
  • 2,633
  • 1
  • 22
  • 29
user2815519
  • 191
  • 1
  • 2
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.

Pavel Alazankin
  • 1,325
  • 1
  • 12
  • 22
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.

cezar
  • 11,616
  • 6
  • 48
  • 84
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**
Snopzer
  • 1,602
  • 19
  • 31
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)
afeef
  • 4,396
  • 11
  • 35
  • 65
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
Yogesh Yadav
  • 4,557
  • 6
  • 34
  • 40
  • 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 '23 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;
redreinard
  • 1,994
  • 1
  • 19
  • 25
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

sea26.2
  • 376
  • 1
  • 5
  • 23
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.

SteveExdia
  • 321
  • 1
  • 3
  • 11
0

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

jef
  • 55
  • 9
  • 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 04 '14 at 13:14