How to Install Composer on CentOS 8

Installing Composer on CentOS 8

dnf install php php-cli php-zip php-json

Output:

 [root@vps ~]# dnf install php php-cli php-zip php-json
 CentOS-8 - AppStream                            2.0 MB/s | 6.5 MB     00:03
 CentOS-8 - Base                                 1.3 MB/s | 5.0 MB     00:03
 CentOS-8 - Extras                               1.2 kB/s | 4.2 kB     00:03
 Dependencies resolved.
 ================================================================================
  Package          Arch   Version                                Repository
                                                                                                                                                                 Size
================================================================================
Installing:
php              x86_64 7.2.11-2.module_el8.1.0+209+03b9a8ff   AppStream 1.5 M
php-cli          x86_64 7.2.11-2.module_el8.1.0+209+03b9a8ff   AppStream 3.1 M
php-json         x86_64 7.2.11-2.module_el8.1.0+209+03b9a8ff   AppStream  73 k
php-pecl-zip     x86_64 1.15.3-1.module_el8.1.0+209+03b9a8ff   AppStream  51 k
Installing dependencies:
apr              x86_64 1.6.3-9.el8                            AppStream 125 k
apr-util         x86_64 1.6.1-6.el8                            AppStream 105 k
centos-logos-httpd
                                    noarch 80.5-2.el8                             AppStream  24 k
httpd            x86_64 2.4.37-16.module_el8.1.0+256+ae790463  AppStream 1.7 M
httpd-filesystem noarch 2.4.37-16.module_el8.1.0+256+ae790463  AppStream  35 k

Install Composer Locally

To install Composer locally on your current directory, by execute the following script.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php composer-setup.php

php -r "unlink('composer-setup.php');"

Run php composer.phar in order to run Composer.

php composer.phar

Output:

[root@vps ~]# php composer.phar
     ______
    / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                                        /_/
Composer version 1.10.1 2020-03-13 20:34:27

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
            --no-plugins               Whether to disable plugins.
    -d, --working-dir=WORKING-DIR  If specified, use the given directory as working directory.
            --no-cache                 Prevent use of the cache
    -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                Shows the short information about Composer.

Install Composer Globally

To install and access Composer globally system-wide, you need to place Composer PHAR in your system PATH, so that you can execute it without using the PHP interpreter.

To install Composer globally for all users, by excuting the following commands.

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

php composer-setup.php

php -r "unlink('composer-setup.php');"

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

chmod +x /usr/local/bin/composer

composer -V

Output:

[root@vps ~]# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"

[root@vps ~]# php composer-setup.php
All settings correct for using Composer
Downloading...
Composer (version 1.10.1) successfully installed to: /root/composer.phar
Use it: php composer.phar

[root@vps ~]# php -r "unlink('composer-setup.php');"

[root@vps ~]# mv composer.phar /usr/local/bin/composer

[root@vps ~]# chmod +x /usr/local/bin/composer

[root@vps ~]# composer -V
Composer version 1.10.1 2020-03-13 20:34:27