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:
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)
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.
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.
To run a command for the default composer. json, select Tools | Composer | <command name> from the main menu.
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.
Composer has 2 basic elements for you to consider:
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.
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/
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With