Install PHP Composer on Rocky Linux 8

|
Last Updated:
|
|

Want to use PHP composer on Rocky Linux 8? Well, this tutorial provides a step-by-step guide on how to install PHP composer on Rocky Linux 8. Follow through to learn how to. “Composer is a tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you”.

Installing PHP Composer on Rocky Linux 8

Prerequisites

Composer requires PHP 5.3.2+ to run.

We are using PHP 7.4 in this guide.

php -v
PHP 7.4.6 (cli) (built: May 12 2020 08:09:15) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
    with Zend OPcache v7.4.6, Copyright (c), by Zend Technologies

You can check how to install PHP on rocky Linux by following the link below;

Install PHP on Rocky Linux 8

There are two ways in which you can install PHP composer.

  1. Locally as part of your project
  2. globally as a system wide executable

Install PHP Composer Locally for Specific Project

Navigate to Program’s directory. To install PHP composer as part of your specific program, navigate to the program’s directory.

Download PHP Composer Installer Script. Run the command below to download PHP composer installer script;

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

Verify the integrity of the installer

To confirm that you are installing the actual composer, you need to verify the integrity of the installer script downloaded above. This can be done by downloading the hash and comparing and validating as follows

php -r "if (hash_file('sha384', 'composer-setup.php') === '$(wget -qO - https://composer.github.io/installer.sig)') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"

If the file is file, you should see an output like Installer verified.

Install PHP Composer

Next, run the installer;

php composer-setup.php

Sample command output;

All settings correct for using Composer
Downloading...

Composer (version 2.1.3) successfully installed to: /home/kifarunix/composer.phar
Use it: php composer.phar

Remove the installer

Remove the installer once Composer is installed.

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

Verify Composer Installation by running the command;

php composer.phar

If you run the command above as root, you will receive a warning on the same:

Do not run Composer as root/super user! See https://getcomposer.org/root for details
Continue as root/super user [yes]? yes
   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.1.3 2021-06-09 16:31:20

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 a short information about Composer.
  archive              Creates an archive of this composer package.
  browse               Opens the package's repository URL or homepage in your browser.
...

Install PHP Composer Globally

To make composer available system wide, run the commands above but while installing composer, use the command, php composer-setup.php --install-dir=/usr/bin --filename=composer instead of php composer-setup.php.

Simply execute the commands below;

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
php -r "if (hash_file('sha384', 'composer-setup.php') === '$(wget -qO - https://composer.github.io/installer.sig)') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
php composer-setup.php --install-dir=/usr/bin --filename=composer
php -r "unlink('composer-setup.php');"

Running Composer:

Now instead of running php composer.phar, use composer.

composer -V
...
Composer version 2.1.3 2021-06-09 16:31:20

And that is how simple it is to Install PHP composer on Rocky Linux 8.

Other tutorials:

Install LAMP Stack on Rocky Linux 8

Install LEMP Stack on Rocky Linux 8

SUPPORT US VIA A VIRTUAL CUP OF COFFEE

We're passionate about sharing our knowledge and experiences with you through our blog. If you appreciate our efforts, consider buying us a virtual coffee. Your support keeps us motivated and enables us to continually improve, ensuring that we can provide you with the best content possible. Thank you for being a coffee-fueled champion of our work!

Photo of author
gen_too
Co-founder of Kifarunix.com, Linux Tips and Tutorials. Linux/Unix admin and author at Kifarunix.com.

Leave a Comment