zizoujab
zizoujab

Reputation: 7800

How to know which version of Symfony I have?

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 ?

Upvotes: 158

Views: 212041

Answers (14)

ajay_full_stack
ajay_full_stack

Reputation: 554

This can be done in many ways. here are the some of them

if you are a console lover ( this will give you all the files having symfony version hard coded in files)

grep -r VERSION . | grep  ./vendor/symfony/http-kernel/Kernel.php

There are other solution using composer (which will give minor details also)

 composer info symfony/yaml

If you don't have access the console, read file, there is hard coded version

HttpKernel/Kernel.php

For shorter details

php bin/console --version

For Details (e.g. Symfony & PHP versions, Log directory, End of Life.... )

php bin/console about

Upvotes: 0

SteveExdia
SteveExdia

Reputation: 349

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.

Upvotes: 1

sea26.2
sea26.2

Reputation: 382

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

Upvotes: 0

user2338925
user2338925

Reputation:

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.

Upvotes: 8

cezar
cezar

Reputation: 12012

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.

Upvotes: 51

user2815519
user2815519

Reputation: 221

Use the following command in your Terminal/Command Prompt:

php bin/console --version

This will give you your Symfony Version.

Upvotes: 22

Yogesh Yadav
Yogesh Yadav

Reputation: 4745

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

Upvotes: 3

Pavel Alazankin
Pavel Alazankin

Reputation: 1395

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.

Upvotes: 9

Diego Agull&#243;
Diego Agull&#243;

Reputation: 9576

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.

Upvotes: 260

afeef
afeef

Reputation: 4696

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)

Upvotes: 5

Snopzer
Snopzer

Reputation: 1692

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**

Upvotes: 5

redreinard
redreinard

Reputation: 2044

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

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

Upvotes: 2

Adam Elsodaney
Adam Elsodaney

Reputation: 7808

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.

Upvotes: 26

jef
jef

Reputation: 55

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

Upvotes: 0

Related Questions