User Tools

Site Tools


installcomposer

If you want to send us your comments, please do so. Thanks
More on comments


Install composer

composer is a Dependency Manager for PHP

This installation is performed on Debian 10.10 Buster

Via aptitude

  • In aptitude do
    • /^composer
    • +
    • /^php-curl
    • +, g
    • If you do not need git, scroll down to git and do -. This will also unselect git-man and liberror-perl
    • g

This installs (without git):

Will install 16 packages, and remove 0 packages.
5142 kB of disk space will be used
========================================
[INSTALL, DEPENDENCIES] jsonlint:amd64 1.7.1-1
[INSTALL, DEPENDENCIES] php-composer-ca-bundle:amd64 1.1.4-1
[INSTALL, DEPENDENCIES] php-composer-semver:amd64 1.4.2-1
[INSTALL, DEPENDENCIES] php-composer-spdx-licenses:amd64 1.5.0-1
[INSTALL, DEPENDENCIES] php-composer-xdebug-handler:amd64 1.3.2-1
[INSTALL, DEPENDENCIES] php-json-schema:amd64 5.2.8-1
[INSTALL, DEPENDENCIES] php-mbstring:amd64 2:7.3+69
[INSTALL, DEPENDENCIES] php-psr-log:amd64 1.1.0-1
[INSTALL, DEPENDENCIES] php-symfony-console:amd64 3.4.22+dfsg-2+deb10u1
[INSTALL, DEPENDENCIES] php-symfony-debug:amd64 3.4.22+dfsg-2+deb10u1
[INSTALL, DEPENDENCIES] php-symfony-filesystem:amd64 3.4.22+dfsg-2+deb10u1
[INSTALL, DEPENDENCIES] php-symfony-finder:amd64 3.4.22+dfsg-2+deb10u1
[INSTALL, DEPENDENCIES] php-symfony-process:amd64 3.4.22+dfsg-2+deb10u1
[INSTALL, DEPENDENCIES] php7.3-mbstring:amd64 7.3.29-1~deb10u1
[INSTALL] php-curl:amd64 2:7.3+69
[INSTALL] composer:amd64 1.8.4-1+deb10u1
========================================

Upgrade to version 2

If aptitude installs version 1 it might be needed to upgrade composer to version 2. You can check with

composer --version
Composer 1.8.4 2019-02-11 10:52:10

Copy the script from the composer How do I install Composer programmatically page and save it to /home/user/composer-downloader.sh. We made a slightly improved version:

  • Changed from sh to bash code
  • Added a path check for /usr/bin, for PHP
  • Added a check (--check) statement
  • Removed --quiet (now you get some feedback)
  • Commented out rm composer-setup.php (so you can run composer-setup.php again if needed (for a new version of composer run composer-downloader.sh again))
  • Added some extra output

composer-downloader.sh:

#!/bin/bash
 
echo 'Checking if /usr/bin is in $PATH'
echo $PATH | grep '/usr/bin' &> /dev/null
exitcode=$?
if [[ $exitcode -ne 0 ]]; then
  echo 'ERROR: Check the PATH. /usr/bin should be incorporated'
  echo "The path is: $PATH"
  exit 1
fi
 
echo -e '\nGetting composer-setup.php'
if [[ -f composer-setup.php ]]; then
  rm composer-setup.php
fi
echo 'Get EXPECTED_CHECKSUM'
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
echo 'Calculate ACTUAL_CHECKSUM'
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
 
echo 'Checking checksums'
if [[ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]]; then
  >&2 echo 'ERROR: Invalid installer checksum'
  rm composer-setup.php
  exit 1
fi
 
echo 'Checking and running composer-setup.php'
if [[ -f composer-setup.php ]]; then
  grep '#! /usr/bin/php' composer-setup.php  2>&1 /dev/null
  exitcode=$?
  if [[ $exitcode -ne 0 ]]; then
    # Add "#! /usr/bin/php" on the first line of composer-setup.php
    sed -i '1 i\#! /usr/bin/php' composer-setup.php
  fi
  chmod 740 composer-setup.php # Make sure the script is executable
  php composer-setup.php --check; # Preform a check
  echo -e '\nRunning composer-setup'
  php composer-setup.php;
  #php composer-setup.php --quiet
  RESULT=$?
  #rm composer-setup.php
  echo Showing the value of RESULT. It should be zero.
  echo The exit status of composer-setup.sh is: $RESULT.
  exit $RESULT
else
  echo 'Error: composer-setup.php not found'
fi

Do as user

./home/user/composer-downloader.sh

The output should look like (the withe text are our added comments):

All settings correct for using Composer
All settings correct for using Composer
Downloading...

Composer (version 2.1.6) successfully installed to: /home/user/composer.phar
Use it: php composer.phar
./composer-setup.php --check;

The output should look like: “All settings correct for using Composer

As root do:

  • mkdir /usr/local/bin/composer
  • cp /home/user/composer.phar /usr/local/bin/composer

Command examples

To see the help page

/usr/local/bin/composer/composer.phar

To self diagnose

/usr/local/bin/composer/composer.phar diagnose

To use composer to install software run

/usr/local/bin/composer/composer.phar require whateverisneededhere

Example

/usr/local/bin/composer/composer.phar require box/spout

Update composer

/usr/local/bin/composer/composer.phar self-update

Update the packages

/usr/local/bin/composer/composer.phar update

Issues

json extension missing

Some settings on your machine make Composer unable to work properly.
Make sure that you fix the issues listed below and run this script again:

The json extension is missing.
Install it or recompile php without --disable-json

Solution: run: phpenmod json

unexpected '--' (T_DEC)

When running composer-downloader.sh this command in it php -r “composer-setup.php --check;” causes

PHP Parse error:  syntax error, unexpected '--' (T_DEC) in Command line code on line 1

Workaround:

  • make sure the first line of composer-setup.php is: #! /usr/bin/php
  • run
    • ./composer-setup.php --help (read the help)
    • ./composer-setup.php --check
    • ./composer-setup.php --2

cURL version: missing

When running /usr/local/bin/composer/composer.phar diagnose this error can occur

cURL version: missing, using php streams fallback, which reduces performance

Solution: run aptitude install php-curl

Deprecating composer 1 support
Get composer
Publick keys and checksums
Command line options


Main subjects on this wiki: Linux, Debian, HTML, Microcontrollers, Privacy

RSS
Disclaimer
Privacy statement
Bugs statement
Cookies
Copyright © : 2014 - 2022 Webevaluation.nl and the authors
Changes reserved.

This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
installcomposer.txt · Last modified: 20-10-2021 20:02 by wim