How can I create a new symfony project with a new directory structure?

Until recently, it was possible to create a new Symfony project with a new (Symfony 3) directory structure . When running composer create-project symfony/framework-standard-edition path/ "2.5.*" , Composer will ask the following question:

Do you want to use the symfony 3 directory structure? [Y / N]

The new structure suggested some improvements, such as console moving from the app directory to the bin directory, and phpunit.xml.dist moving from the app directory to the root directory. The cache and log directories have been moved to the new var directory.

See this answer (written by me) for a complete list of changes.

However, a new installation of the standard distribution no longer offers this option. It seems that the question was deleted on July 16 because the new directory structure created too much confusion, especially for new users. See this issue on GitHub .

Is it possible to create a project using the new directory structure?

+14
symfony
Jul 25 '14 at 13:28
source share
3 answers

You can still ask a question and convert the project into a new directory structure. (but only if you create a new project, i.e. by running composer create-project )

To do this, you need to set the environment variable SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE to true . This can be done by adding SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE=true to the Composer command.

So, to create a new project, run the following command on your computer:

 SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE=true composer create-project symfony/framework-standard-edition path/ "2.5.*" 

and Composer will ask you if you want to create a new directory structure.

Update

As Barius noted in the comments, this feature has been removed from Symfony Standard Edition for version 2.7.5. If you really want to use the Symfony 3 framework, you can get it by installing Symfony in 2 steps:

  • Create a new Symfony project with version restrictions to get version 2.6, which still asks you if you want to use the new directory structure.
  • Then change the version limit for the symfony/symfony package so that you still get the latest version.

So, run the following commands from the command line:

 SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE=true composer create-project symfony/framework-standard-edition project-directory/ "2.6.*" cd project-directory composer require symfony/symfony ^2.7 

Note. I really do not recommend this, as this is not an official recommended way to create a new Symfony project . Therefore, if you really do not know what you are doing, just use the Symfony installer to create new projects.

+17
Jul 25 '14 at 13:28
source share

To create a new symfony3 directory structure in symfony2 (> = 2.5), you must do the following:

open a shell command prompt and run the follwoing command to set the temporary variable :

Linux:

 export SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE=true 

window:

 set SENSIOLABS_ENABLE_NEW_DIRECTORY_STRUCTURE=true 

version 2.5 and 2.6

the question of creating a new symfony3 directory structure is asked out of the box after setting the environment variable

version 2.7 and 2.8

The following steps are required to create a new directory structure from any version 2.7 and 2.8:

install the required version 2.7 and higher (tested with 2.7 and 2.8), which currently installs 2.7.7

 composer create-project symfony/framework-standard-edition myproject "2.7.*" 

then edit composer.json and add update-directory-structure :

composer.json:

 --- snip --- "scripts": { "post-install-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" ], "post-update-cmd": [ "Incenteev\\ParameterHandler\\ScriptHandler::buildParameters", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile", "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::prepareDeploymentTarget" ], "update-directory-structure": [ "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::defineDirectoryStructure" ] }, --- snip --- 

after that just run

 composer run-script update-directory-structure 

answer "y" and you will end:

 > Sensio\Bundle\DistributionBundle\Composer\ScriptHandler::defineDirectoryStructure Would you like to use Symfony 3 directory structure? [y/N] 

The console file, which is now in bin/console , must be adapted:

change

 $loader = require __DIR__.'/autoload.php'; 

to

 $loader = require __DIR__.'/../app/autoload.php'; 

then add the following methods to the AppKernel class in the app/appKernel.php :

 public function getRootDir() { return __DIR__; } public function getCacheDir() { return dirname(__DIR__).'/var/cache/'.$this->getEnvironment(); } public function getLogDir() { return dirname(__DIR__).'/var/logs'; } 

update: add an article on migration to the new directory structure

loans: @davil

+6
Dec 01 '15 at 17:13
source share

Symfony3 BETA1 version is now released,

This way you can use composer directly to install the new version of symfony3.

Follow Install Composer first if you do not already have it.

Then open a terminal and enter the following command:

 composer create-project symfony/framework-standard-edition symfony3 "v3.0.0-BETA1" 

Note: here symfony3 is the name of the project or directory that will be created, you can change this.

Update: Symfony 3.0 is a stable and current version, so it can be installed directly, as indicated in the Official Guide . Follow him to install the latest version.

composer create-project symfony/framework-standard-edition my_project_name

You can check these links,

What is the new symfony 3 directory structure?

Are your favorite packages ready for # Symfony3? sent by @FecaBouffe

+4
Nov 18 '15 at 2:37
source share



All Articles