Composer command line interface and commands (part 5)


This is the fifth part of the Composer command line interface and commands.


The status command allows us to check for local changes in the source codes of our dependencies. This is often used in scenarios where the source codes are often modified.

composer status

Using the --verbose command flag, we can have some additional information about what was changed in the source code.

composer status --verbose

#self-update (selfupdate)

This is used to  update or upgrade our composer to the latest version. Simply run the composer self-update command and the composer.phar file will be replaced with a new  version of composer.phar file.

composer self-update

We can update a specific package by including the package name in the “self-update” command as shown:

composer self-update 1.0.0-alpha7

If Composer was installed globally, we could update it using the “sudo” command as shown in the command below:

sudo -H composer self-update

Other optional parameters can also be passed to the “self-update command” :

  • --rollback (-r): This rolls back composer back to the last version installed, restoring some default settings and configurations.
  • --clean-backups: This updates the composer and also delete all the previous backups available.
  • --no-progress: Downloads and update composer without showing the download progress
  • --update-keys: Used to request a user for a key update.
  • --stable: To command update on a stable channel.
  • --preview: To require an update on a preview channel.
  • --snapshot: This command forces an update to the snapshot channel.


The config command allows us to edit composer configuration settings on the local or global config.json file

This also allows edit on most properties in the local composer.json file.

composer config --list


The config parameters can also be used with the following format:

config [options] [setting-key] [setting-value1] ... [setting-valueN]

setting-key is a configuration option name and setting-value1 is a configuration value. For settings that can take an array of values (like github-protocols), more than one setting-value arguments are allowed.

We can also edit the values of the following properties:

description, homepage, keywords, license, minimum-stability, name, prefer-stable, type and version.

The composer config has the following optional parameters:

  • --global(-g): This Operates on the global config file located at “$COMPOSER_HOME/config.json” by default. When this flag is omitted  the local composer.json file or a file specified by --file.”  is affected.
  • --editor (-e): It open the local composer.json file using in a text editor as defined by the EDITOR env variable. When the --global option is specified, it opens the global config file.
  • --auth (-a): Used to affect changes in the auth config file (only used for --editor).
  • --unset: This removes the configuration element named by setting-key.
  • --list (-l): It shows the list of current config variables. With the --global option this lists the global configuration only.
  • --file="..." (-f): Operate on a specific file instead of composer.json. Note that this cannot be used in conjunction with the --global option.
  • --absolute: Returns absolute paths when fetching *-dir config values instead of relative.

#Modifying Repositories

In addition to modifying the config section, the config command also allows making of changes to the repositories section by using the following commands:

composer config repositories.foo vcs https://github.com/foo/bar

If your repository requires more configuration options, you can instead pass its JSON representation :

composer config repositories.foo ‘{
“type”: ”vcs”,
“url”: ”http://svn.example.org/my-project/”,
“trunk-path” : “master”

#Modifying Extra Values

In addition to modifying the config section, the config command also supports making changes to the extra section by using it the following way:

composer config extra.foo.bar value

The dots indicate array nesting, a max depth of 3 levels is allowed though. The above would set "extra": { "foo": { "bar": "value" } }.


We can use Composer to create new projects from an existing package. This is the equivalent of doing a git clone checkout followed by a composer install of the vendors.

The “create-project” has several  applications:

  1. We can deploy application packages.
  2. We can check out any package and start developing on patches for example.
  3. Projects with multiple developers can use this feature to bootstrap the initial application for development.

To create a new project using Composer we can use the create-project command. Passing it a package name, and the directory to create the project in. We  can also provide a version as third argument, hence the latest version is used in creating the project.

If the directory does not currently exist, it will be created during installation. An example format for creating a project is shown below:

composer  create-project doctrine/orm  path 2.2.*

It is also possible to run the command without params in a directory with an existing composer.json file to bootstrap a project.

The “composer create-project “ can be used with the following optional parameters:

  • --stability (-s): The minimum stability of a package. Defaults to stable if not specified.
  • --prefer-source: Install packages from source when one is specified.
  • --prefer-dist: Install packages from dist when specified.
  • --repository: When a custom repository to search for a package is specified, this will be used instead of packagist.
  • --dev: Install packages listed in require-dev  section of the composer.json file.
  • --no-dev: Disables installation of require-dev packages in the composer.json file
  • --no-scripts: Disables the execution of the scripts defined in the root package.
  • --no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters.
  • --no-secure-http: Disable the secure-http config option temporarily while installing the root package. Use at your own risk. Using this flag is a bad idea.
  • --keep-vcs: Skip the deletion of the VCS metadata for the created project. This is mostly useful if you run the command in non-interactive mode.
  • --remove-vcs: Force-remove the VCS metadata without prompting.
  • --no-install: Disables installation of the vendors.
  • --ignore-platform-reqs: ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these.

Previous: Composer command line interface and commands (Part 4)
Next: Composer command line interface and commands (Part 6)

Share this Tutorial / Exercise on : Facebook and Twitter

PHP: Tips of the Day

How do I strip all spaces out of a string in PHP?

Do you just mean spaces or all whitespace?

For just spaces, use str_replace:

$string = str_replace(' ', '', $string);

For all whitespace (including tabs and line ends), use preg_replace:

$string = preg_replace('/\s+/', '', $string);

Ref : https://bit.ly/2Cnb3QZ