How to install Composer on Debian / Ubuntu Linux

I‘m trying to upgrade my Mediawiki installation and I’m getting an error that read as follows:

Error: your composer.lock file is not up to date, run “composer update” to install newer dependencies

How do I install composer command for my PHP installation on Debian or Ubuntu Linux running LAMP or LEMP stack?

How do I Install and use Composer on running Ubuntu Linux server and fix this problem for mediawiki installation and/or manage and install PHP packages and dependencies for my project?

 

Composer is a dependency manager tool for PHP. It installs and updates the libraries for your project. It is not a package manager like yum command or apt-get command.

 

It is desgined to use with each individual project like Mediawiki or your own custom app written in PHP.

There are many open source projects and frameworks written in php use Composer to manage and install their packages and dependencies.

In this tutorial you will learn how to install composer globally on Debian or Ubuntu Linux server. The following instructions should also work with RHEL/CentOS Linux 7.x or any other modern Linux distro.

The problem

When you try to update mediawiki to v1.26.0 using the following command:

[wwwuser@server1.cyberciti.biz:~/wiki]$ php update.php

 

You will will get the following error:

MediaWiki 1.26.0 Updater

composer/semver: not installed, 1.0.0 required.

liuggio/statsd-php-client: 1.0.12 installed, 1.0.16 required.

oyejorge/less.php: not installed, 1.7.0.9 required.

mediawiki/at-ease: not installed, 1.1.0 required.

oojs/oojs-ui: 0.11.3 installed, 0.12.12 required.

wikimedia/assert: not installed, 0.2.2 required.

wikimedia/cdb: 1.0.1 installed, 1.3.0 required.

wikimedia/composer-merge-plugin: 1.0.0 installed, 1.3.0 required.

wikimedia/ip-set: not installed, 1.0.1 required.

wikimedia/utfnormal: 1.0.2 installed, 1.0.3 required.

wikimedia/wrappedstring: not installed, 2.0.0 required.

zordius/lightncandy: 0.18 installed, 0.21 required.

Error: your composer.lock file is not up to date, run  composer update  to install newer dependencies

To fix this problem you need to install the composer tool.

Installation

Make sure curl and php-cli, curl and related tools are installed on your Debian or Ubuntu server (14.04 LTS or older):

$ sudo apt-get install curl php5-cli git

 

Sample outputs:

Reading package lists… Done

Building dependency tree

Reading state information… Done

php5-cli is already the newest version.

The following extra packages will be installed:

git-man libcurl3 liberror-perl patch rsync

Suggested packages:

gettext-base git-daemon-run git-daemon-sysvinit git-doc git-el git-email

git-gui gitk gitweb git-arch git-bzr git-cvs git-mediawiki git-svn ed

diffutils-doc openssh-server

The following NEW packages will be installed:

curl git git-man libcurl3 liberror-perl patch rsync

0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.

Need to get 4,011 kB of archives.

After this operation, 23.4 MB of additional disk space will be used.

Do you want to continue? [Y/n] y

Get:1 http://archive.ubuntu.com/ubuntu/ trusty-updates/main libcurl3 amd64 7.35.0-1ubuntu2.5 [173 kB]

Get:2 http://archive.ubuntu.com/ubuntu/ trusty-updates/main rsync amd64 3.1.0-2ubuntu0.1 [283 kB]

Get:3 http://archive.ubuntu.com/ubuntu/ trusty-updates/main curl amd64 7.35.0-1ubuntu2.5 [123 kB]

Get:4 http://archive.ubuntu.com/ubuntu/ trusty/main liberror-perl all 0.17-1.1 [21.1 kB]

Get:5 http://archive.ubuntu.com/ubuntu/ trusty-updates/main git-man all 1:1.9.1-1ubuntu0.1 [698 kB]

Get:6 http://archive.ubuntu.com/ubuntu/ trusty-updates/main git amd64 1:1.9.1-1ubuntu0.1 [2,627 kB]

Get:7 http://archive.ubuntu.com/ubuntu/ trusty-updates/main patch amd64 2.7.1-4ubuntu2.3 [86.4 kB]

Fetched 4,011 kB in 1s (2,181 kB/s)

Selecting previously unselected package libcurl3:amd64.

(Reading database … 16719 files and directories currently installed.)

Preparing to unpack …/libcurl3_7.35.0-1ubuntu2.5_amd64.deb …

Unpacking libcurl3:amd64 (7.35.0-1ubuntu2.5) …

Selecting previously unselected package rsync.

Preparing to unpack …/rsync_3.1.0-2ubuntu0.1_amd64.deb …

Unpacking rsync (3.1.0-2ubuntu0.1) …

Selecting previously unselected package curl.

Preparing to unpack …/curl_7.35.0-1ubuntu2.5_amd64.deb …

Unpacking curl (7.35.0-1ubuntu2.5) …

Selecting previously unselected package liberror-perl.

Preparing to unpack …/liberror-perl_0.17-1.1_all.deb …

Unpacking liberror-perl (0.17-1.1) …

Selecting previously unselected package git-man.

Preparing to unpack …/git-man_1%3a1.9.1-1ubuntu0.1_all.deb …

Unpacking git-man (1:1.9.1-1ubuntu0.1) …

Selecting previously unselected package git.

Preparing to unpack …/git_1%3a1.9.1-1ubuntu0.1_amd64.deb …

Unpacking git (1:1.9.1-1ubuntu0.1) …

Selecting previously unselected package patch.

Preparing to unpack …/patch_2.7.1-4ubuntu2.3_amd64.deb …

Unpacking patch (2.7.1-4ubuntu2.3) …

Processing triggers for ureadahead (0.100.0-16) …

Setting up libcurl3:amd64 (7.35.0-1ubuntu2.5) …

Setting up rsync (3.1.0-2ubuntu0.1) …

Removing any system startup links for /etc/init.d/rsync …

update-rc.d: warning: default stop runlevel arguments (0 1 6) do not match rsync Default-Stop values (none)

Adding system startup for /etc/init.d/rsync …

/etc/rc0.d/K20rsync -> ../init.d/rsync

/etc/rc1.d/K20rsync -> ../init.d/rsync

/etc/rc6.d/K20rsync -> ../init.d/rsync

/etc/rc2.d/S20rsync -> ../init.d/rsync

/etc/rc3.d/S20rsync -> ../init.d/rsync

/etc/rc4.d/S20rsync -> ../init.d/rsync

/etc/rc5.d/S20rsync -> ../init.d/rsync

Setting up curl (7.35.0-1ubuntu2.5) …

Setting up liberror-perl (0.17-1.1) …

Setting up git-man (1:1.9.1-1ubuntu0.1) …

Setting up git (1:1.9.1-1ubuntu0.1) …

Setting up patch (2.7.1-4ubuntu2.3) …

Processing triggers for libc-bin (2.19-0ubuntu6.6) …

Processing triggers for ureadahead (0.100.0-16) …

If you are using Ubuntu Linux 16.04 LTS or newer and want to use PHP 7.x, run:

$ sudo apt install curl php7.0-cli git

Install composer tool

Next install composer on Debian or Ubuntu Linux in /usr/local/bin/ directory as follows:

$ curl -sS https://getcomposer.org/installer | sudo php — –install-dir=/usr/local/bin –filename=composer

 

Sample outputs:

Fig.01: Installing composer on your server running Ubuntu Linux

Verify composer

To verify installation type:

$ composer

 

OR

$ /usr/local/bin/composer

 

The Sample outputs:

______

/ ____/___  ____ ___  ____  ____  ________  _____

/ /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/

/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /

\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/

/_/

Composer version 1.0-dev (1c525b76f81123af180743d31c208c29351cf931) 2015-12-09 15:47:26

 

Usage:

command [options] [arguments]

 

Options:

-h, –help                     Display this help message

-q, –quiet                    Do not output any message

-V, –version                  Display this application version

–ansi                     Force ANSI output

–no-ansi                  Disable ANSI output

-n, –no-interaction           Do not ask any interactive question

–profile                  Display timing and memory usage information

-d, –working-dir=WORKING-DIR  If specified, use the given directory as working directory.

-v|vv|vvv, –verbose           Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug

 

Available commands:

about           Short information about Composer

archive         Create an archive of this composer package

browse          Opens the package s repository URL or homepage in your browser.

clear-cache     Clears composer s internal package cache.

clearcache      Clears composer s internal package cache.

config          Set config options

create-project  Create new project from a package into given directory.

depends         Shows which packages depend on the given package

diagnose        Diagnoses the system to identify common errors.

dump-autoload   Dumps the autoloader

dumpautoload    Dumps the autoloader

global          Allows running commands in the global composer dir ($COMPOSER_HOME).

help            Displays help for a command

home            Opens the package s repository URL or homepage in your browser.

info            Show information about packages

init            Creates a basic composer.json file in current directory.

install         Installs the project dependencies from the composer.lock file if present, or falls back on the composer.json.

licenses        Show information about licenses of dependencies

lint            Run the lint script as defined in composer.json.

list            Lists commands

phpcs           Run the phpcs script as defined in composer.json.

remove          Removes a package from the require or require-dev

require         Adds required packages to your composer.json and installs them

run-script      Run the scripts defined in composer.json.

search          Search for packages

self-update     Updates composer.phar to the latest version.

selfupdate      Updates composer.phar to the latest version.

show            Show information about packages

status          Show a list of locally modified packages

suggests        Show package suggestions

test            Run the test script as defined in composer.json.

update          Updates your dependencies to the latest version according to composer.json, and updates the composer.lock file.

validate        Validates a composer.json and composer.lock

How does composer work?

To use Composer you need to create or use composer.json file supplied by your vendor such as mediawiki. This file defines the dependencies of php app or project. Here is sample file from mediawiki project:

{

name :  mediawiki/core ,

description :  Free software wiki application developed by the Wikimedia Foundation and others ,

keywords : [ mediawiki ,  wiki ],

homepage :  https://www.mediawiki.org/ ,

authors : [

{

name :  MediaWiki Community ,

homepage :  https://www.mediawiki.org/wiki/Special:Version/Credits

}

],

license :  GPL-2.0+ ,

support : {

issues :  https://bugs.mediawiki.org/ ,

irc :  irc://irc.freenode.net/mediawiki ,

wiki :  https://www.mediawiki.org/

},

require : {

composer/semver :  1.0.0 ,

cssjanus/cssjanus :  1.1.1 ,

ext-iconv :  * ,

liuggio/statsd-php-client :  1.0.16 ,

oyejorge/less.php :  1.7.0.9 ,

mediawiki/at-ease :  1.1.0 ,

oojs/oojs-ui :  0.12.12 ,

php :  >=5.3.3 ,

psr/log :  1.0.0 ,

wikimedia/assert :  0.2.2 ,

wikimedia/cdb :  1.3.0 ,

wikimedia/composer-merge-plugin :  1.3.0 ,

wikimedia/ip-set :  1.0.1 ,

wikimedia/utfnormal :  1.0.3 ,

wikimedia/wrappedstring :  2.0.0 ,

zordius/lightncandy :  0.21

}

}

How do I install dependencies defined in composer.json file?

Simply type the following command to download and install all dependencies for your app/project:

$ composer install

 

OR switch to core project directory such as /var/www/html/wiki and run:

$ cd /var/www/html/wiki && composer install –no-dev

 

Sample outputs:

Loading composer repositories with package information

Installing dependencies from lock file

Warning: The lock file is not up to date with the latest changes in composer.json. You may be getting outdated dependencies. Run update to update them.

– Removing composer/semver (1.0.0)

– Removing oyejorge/less.php (v1.7.0.9)

– Removing mediawiki/at-ease (v1.1.0)

– Removing wikimedia/avro (v1.7.7)

– Removing nmred/kafka-php (v0.1.4)

– Removing wikimedia/ip-set (1.0.1)

– Removing firebase/php-jwt (v2.1.0)

– Removing symfony/process (v2.7.3)

– Removing ruflin/elastica (2.2.0)

– Removing wikimedia/wrappedstring (v2.0.0)

– Removing monolog/monolog (1.14.0)

– Removing kzykhys/pygments (v1.0.0)

– Removing wikimedia/assert (v0.2.2)

– Removing wikimedia/composer-merge-plugin (v1.3.0)

– Installing wikimedia/composer-merge-plugin (v1.0.0)

Downloading: 100%

 

– Removing liuggio/statsd-php-client (v1.0.16)

– Installing liuggio/statsd-php-client (v1.0.12)

Downloading: 100%

 

– Removing oojs/oojs-ui (v0.12.12)

– Installing oojs/oojs-ui (v0.11.3)

Downloading: 100%

 

– Removing wikimedia/cdb (1.3.0)

– Installing wikimedia/cdb (1.0.1)

Downloading: 100%

 

– Removing wikimedia/utfnormal (v1.0.3)

– Installing wikimedia/utfnormal (v1.0.2)

Downloading: 100%

 

– Removing zordius/lightncandy (v0.21)

– Installing zordius/lightncandy (v0.18)

Downloading: 100%

 

– Installing leafo/lessphp (v0.5.0)

Downloading: 100%

 

Generating optimized autoload files

The above will also create composer.lock file which can be used to update the dependencies later on to the latest version.

How do I update composer.lock file?

If there is no .lock file, this tool will create one based on the dependencies from the .json file. To fetch the dependent libraries to newer versions, run the following command i.e. if you have an existing composer.lock file you will need to run it as follows:

$ composer update

 

OR switch to core project directory such as /var/www/html/wiki and run:

$ cd /var/www/html/wiki/ && composer update –no-dev

 

Sample outputs:

ComposerHookHandler::onPreUpdate

Deprecation Notice: The Composer\Package\LinkConstraint\VersionConstraint class is deprecated, use Composer\Semver\Constraint\Constraint instead. in phar:///usr/local/bin/composer/src/Composer/Package/LinkConstraint/VersionConstraint.php:17

Deprecation Notice: The Composer\Package\LinkConstraint\LinkConstraintInterface interface is deprecated, use Composer\Semver\Constraint\ConstraintInterface instead. in phar:///usr/local/bin/composer/src/Composer/Package/LinkConstraint/LinkConstraintInterface.php:17

 

Updating dependencies

 

– Removing leafo/lessphp (v0.5.0)

– Removing wikimedia/composer-merge-plugin (v1.0.0)

– Installing wikimedia/composer-merge-plugin (v1.3.0)

Downloading: Connecting…

Downloading: 100%

 

– Removing liuggio/statsd-php-client (v1.0.12)

– Installing liuggio/statsd-php-client (v1.0.16)

Downloading: Connecting…

Downloading: 100%

 

– Installing mediawiki/at-ease (v1.1.0)

Downloading: 100%

 

– Removing oojs/oojs-ui (v0.11.3)

– Installing oojs/oojs-ui (v0.12.12)

Downloading: 100%

 

– Removing wikimedia/cdb (1.0.1)

– Installing wikimedia/cdb (1.3.0)

Downloading: 100%

 

– Removing wikimedia/utfnormal (v1.0.2)

– Installing wikimedia/utfnormal (v1.0.3)

Downloading: 100%

 

– Removing zordius/lightncandy (v0.18)

– Installing zordius/lightncandy (v0.21)

Downloading: 100%

 

– Installing composer/semver (1.0.0)

Downloading: 100%

 

– Installing oyejorge/less.php (v1.7.0.9)

Downloading: 100%

 

– Installing wikimedia/assert (v0.2.2)

Downloading: 100%

 

– Installing wikimedia/ip-set (1.0.1)

Downloading: 100%

 

– Installing wikimedia/wrappedstring (v2.0.0)

Downloading: 100%

 

Writing lock file

Generating optimized autoload files

Finally updating mediawiki to version 1.26.0

Now mediawiki will be updated without any problem as composer already fetched required libs for your php app:

$ cd /var/www/html/wiki/

$ php update.php

Command summary

This tutorial described how to install the composer and update mediawiki. But, if you just need the composer tool for your own project, just run the following commands:

$ sudo apt-get install curl php5-cli git

$ sudo curl -sS https://getcomposer.org/installer | sudo php — –install-dir=/usr/local/bin –filename=composer

$ composer

 

Now create your own .json file:

$ cd /my/cool/project/

$ vi composer.json

 

Install the dependencies for your project from composer.json, enter:

$ composer install

 

To update the dependencies for your project:

$ composer update

 

And, there you have it composer installed and working for your LAMP project. For further information please see the official composer project documentation here.

 

 

Leave a Reply

Your email address will not be published. Required fields are marked *