Search code examples
symfonycomposer-phpdoctrine-migrations

How to install Symfony2 Bundles with Composer


I'm using Windows and I installed composer from its Windows installer. What I want to do is to install DoctrineMigrationsBundle to my project, so I added

"doctrine/doctrine-migrations-bundle": "dev-master"

to the composer.json file in the project and run

cd the project directory
php composer.phar update

but what I get is: Could not open input file: composer.phar

My whole composer.json file is

{
    "name": "symfony/framework-standard-edition",
    "description": "The \"Symfony Standard Edition\" distribution",
    "autoload": {
        "psr-0": { "": "src/" }
    },
    "require": {
        "php": ">=5.3.3",
        "symfony/symfony": "2.1.*",
        "doctrine/orm": ">=2.2.3,<2.4-dev",
        "doctrine/doctrine-bundle": "1.1.*",
        "twig/extensions": "1.0.*@dev",
        "symfony/assetic-bundle": "2.1.*",
        "symfony/swiftmailer-bundle": "2.1.*",
        "symfony/monolog-bundle": "2.1.*",
        "sensio/distribution-bundle": "2.1.*",
        "sensio/framework-extra-bundle": "2.1.*",
        "sensio/generator-bundle": "2.1.*",
        "jms/security-extra-bundle": "1.2.*",
        "jms/di-extra-bundle": "1.1.*",
        "kriswallsmith/assetic": "1.1.*@dev"
        "doctrine/doctrine-migrations-bundle": "dev-master"
    },
    "scripts": {
        "post-install-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ],
        "post-update-cmd": [
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::buildBootstrap",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::clearCache",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installAssets",
            "Sensio\\Bundle\\DistributionBundle\\Composer\\ScriptHandler::installRequirementsFile"
        ]
    },
    "extra": {
        "symfony-app-dir": "app",
        "symfony-web-dir": "web"
    }
}

Can you please help me to fix this?


Solution

  • As said by @AhmedSiouani, the error tells you that they can't find a composer.phar file.

    Some things you can do:

    1. Download the Composer-SetUp.exe and install Composer as told on the downloads page (scroll to 'Windows Installer');
    2. Download the composer.phar file and put that in your project (not recommend);
    3. Download the composer.phar file and put that in a directory which is in your PATH environment variable1;
    4. Download the composer.phar file and create a composer.bat file which executes the composer.phar file. Put the code below in it and save it in a directory which is in your PATH environment variable1.

      @echo off
      php "path\to\composer.phar" %*
      

    1: You can see which directories are in the PATH environment variable by running echo %PATH% in your cmd.
    You can also put the directory where this file lives in the PATH environment. To do that, go to Computer (right click) > Settings > Advanced Settings > Environments Variables (under the 'advanced' tab) and set the PATH variable with your directory path (or add the path to the current PATH variable, by putting a ; between the paths).