Introduction
This article explains how to install Composer.
Installation of Composer
Composer is a dependency manager for PHP that allows you to define third-party code packages used by a project, which can then be easily installed and updated.
It is important to distinguish between a global Composer installation and a local one. Installing Composer globally allows you to use the dependency management tool from any folder on your system, whereas a local installation (within your project) restricts its use and the downloaded packages to the specific folder of the current project. For N0C, it is a local installation.
Connect in SSH on your N0C account
First of all, you need to connect to the N0C account via SSH (How to Create an SSH Key and Connect to an Account Remotely). Then, you can proceed with the installation.
Make Sure PHP is Well Installed
Before running the Composer installation, carry out a quick check to ensure that PHP is correctly installed and working properly.
For instance, php -v.
Download Composer
Start by entering the following command:
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"Add hash Verification (Optional)
Add hash verification, as explained at https://getcomposer.org/download/.
For example:
php -r "if (hash_file('sha384', 'composer-setup.php') === 'c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47') { echo 'Installer verified'.PHP_EOL; } else { echo 'Installer corrupt'.PHP_EOL; unlink('composer-setup.php'); exit(1); }"Install/Configure Composer
Enter this command:
php composer-setup.phpYou can install a specific version of Composer using the –version= option. In this case, enter the following command instead (example with version 2.2.18):
php composer-setup.php --version=2.2.18Move to the Proper File
Add this to your code:
mkdir -p ~/.local/bin
mv composer.phar ~/.local/bin/composerDelete the Configuration File
Enter this command:
php -r "unlink('composer-setup.php');"Add Composer to PATH
Add this to your code:
echo 'export PATH="$PATH:$HOME/.local/bin"' >> ~/.bash_profile
source ~/.bash_profileMake a Verification
To check this, type the following:
composer --versionThe following message will appear:
All settings correct for using Composer
Downloading…
Composer (version 2.3.4) successfully installed to: /home/zjpqumjq/composer.phar
Use it: php composer.phar