How To Set up PHP Composer on Centos 7

In this article, we want to teach you How To Set up PHP Composer on Centos 7.

Composer is a dependency/package manager for PHP. It can be used to install, keep track of, and update your project dependencies. The composer also takes care of autoloading the dependencies that your application relies on, letting you easily use the dependency inside your project without worrying about including them at the top of any given file.

Set up PHP Composer on Centos 7

Before you start to install PHP Composer on Centos 7, you need to log in to your server as a non-root user with sudo privileges. To do this, you can follow our article the Initial Server Setup with Centos 7.

Now you can follow the steps below to install PHP Composer on Centos 7.

Install Dependencies on Centos 7

First, you need to update your local package index with the following command:

sudo yum -y update

Then, you need some dependencies for Composer installed on your server. To do this, run the following command:

sudo yum install php-cli php-zip wget unzip

Install Composer on Centos 7

At this point, you need to download the Composer installer script. To download the installer run the following command:

php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Now install Composer on Centos 7 in the /usr/local/bin directory with the command below:
php composer-setup.php --install-dir=/usr/local/bin --filename=composer

In your output you will see:

Output
All settings correct for using Composer
Downloading...
Composer (version 2.1.14) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
Then, you can test that your Composer is working correctly on Centos 7 by typing composer in your command line:
composer
In your output you will see:
Output
  ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.1.14 2021-11-30 10:51:43
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.
...
At this point, you have successfully installed Composer on your Centos 7.
Dependencies for your project are listed within a composer.json file that is typically located in your project root. This file holds information about the required versions of packages for production and also development.
For more information, you can visit the Composer Documentation page.

Conclusion

At this point, you learn to install PHP Composer on Centos 7.
Hope you enjoy using it.
Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles

POPULAR TAGS

Most Popular