Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where do I put composer.json

I have installed composer.

My project dir tree looks something like this

/home/myproject/public_html/myproject.com

I initially installed it in:

/home/myproject/public_html/myproject.com/bin/composer/

But later moved it to:

/home/myproject/usr/local/bin/composer

Questions:

  1. Where to I create composer.json ?
  2. In the official docs they mention that in order to install new packages I need to write a require key in the json format in that file, does this mean that I dont have to upload the package through ftp?
  3. The docs further say that I can simply install dependencies like ths:

    php composer.phar install

I dont understand the workflow of this process (im fairly new).. what exactly do I need to do to get some packages going (like Respect)

like image 587
Angad Dubey Avatar asked Mar 03 '14 19:03

Angad Dubey


People also ask

Where does the composer json file go?

composer. json is a JSON file placed in the root folder of PHP project. Its purpose is to specify a common project properties, meta data and dependencies, and it is a part of vast array of existing projects.

How do I use composer json file?

To configure Composer for your PHP app json file specifies required packages. Verify that a composer. json file is present in the root of your git repository. Run composer install (on your local machine) to install the required packages and generate a composer.

How do I open composer json?

To run a command for the default composer. json, select Tools | Composer | <command name> from the main menu.

How do I run a composer json in terminal?

json file. open terminal window and head towards your project root folder. run composer install command. this will generate vendor folder with all your project dependencies.


2 Answers

Composer has 2 basic elements for you to consider:

  1. The composer.php file itself - this can be located anywhere on your system - usually it is convenient to have it in you search path so you can invoke it by name (no path) from the command line.

  2. Composer.json - this file is the configuration for your project. This is usually best located at the top level of your project. Ideally this is a directory outside the scope of your web server - so that it will never be exposed or served.

Symfony2 has some great documentation and examples of composer in use.

Also be aware that some packages you reference via composer will themselves have composer files - to ensure they match your required dependancies - and they may also have their own dependancies that need to be considered.

I would install composer.json in the following

/home/myproject/composer.json

It would be out of scope of the web server and could be used to manage many assets e.g.

  public_html/
  libs/
  config/
  docs/
  vendor/
like image 176
BillyBigPotatoes Avatar answered Sep 30 '22 07:09

BillyBigPotatoes


Where to I create composer.json ?

You should create composer.json to your project root like /home/myproject/public_html/myproject.com/composer.json. If all files of your application live inside your myproject.com folder.

In the official docs they mention that in order to install new packages I need to write a require key in the json format in that file, does this mean that I dont have to upload the package through ftp?

Yes as long as you're not in shared hosting because most of them don't allow CLI (SSH).

The docs further say that I can simply install dependencies like this

php composer.phar install

Yes you can simple type the above command and composer.json will install the latest version of your package.

Composer.json (Respect Package)

{
    "require": {
        "respect/validation": "dev-master"
    }
}

Now run composer install will install the require package.

For further packages

{
    "require": {
        "respect/validation": "dev-master",
        "doctrine/orm": "2.*"
    }
}

Now run update composer update it will download the doctrine/orm as well.

like image 36
Rahil Wazir Avatar answered Sep 30 '22 06:09

Rahil Wazir