Vishal
Posted on November 15th
How to install composer on Fedora, Debian, and CentOS
"How to install composer on Fedora, Debian, and CentOS"
Composer Introduction
Composer is a package manager that is used for PHP language, which is a popular programming language, largely used in development of web applications. Launched at http://google.com/2012 by Nils Adermann and Jordi Boggiano, Composer is a tool that has improved the way PHP developers include libraries and packages in their projects.
Key Features
As has already been mentioned, the basic usage of Composer is to manage dependencies in PHP applications. This means it enables a developer to declare the libraries on which the project depends and then handles the process of getting (installing), upgrading, or even uninstalling those libraries. Specifically, the participant referred to a file called composer as the type of file a composer creates. json to define the dependencies and versions that are needed for the particular project. Whenever a developer types the composer install or composer update command, the composer reads it, fetches the packages indicated in the file from the package central repository, and deploys them in the project.
How It Works
Composer acts at the project level and not at the global level so that each project can have its structure of dependencies and versions without interference. This can be particularly helpful provided that there are variations in the numerous extents projects that call for different libraries. In realizing the vendor's directory within the project, Composer locks out the dependencies, thus dealing with the issue of version conflicts and streamlining of the management of dependencies.
Benefits
Another appealing factor that the users of Composer can benefit from is that it is quite efficient in handling intricate dependency relationships. It can fix and install libraries and their dependent ones with no intervention from the developers itself, bringing a lot of convenience to the developers. Moreover, Composer can provide autoload support that considers classes that are in the included libraries, which makes the development easier.
Impact on PHP Development
Nowadays, Composer has become one of the basic PHP tools since its appearance. It has become a standard way for PHP developers to handle the project dependencies, to easily include third-party libraries, and to share code. Due to this, there are fewer monolithic PHP apps and more maintainable ones because many packages can be acquired easily from Packagist without the tension of dependency solving.
Install on Fedora
About Fedora
Fedora is relatively new Linux distribution that was established by the Fedora project, which is sponsored by Red Hat. Often hailed for quicker adoption of new open source technologies, it is highly reliable and secure as well. The Fedora’s standard version is Fedora Workstation, which employs the GNOME shell to provide users with enhanced graphical environment. Of these, its modularity with different versions of software installed simultaneously, and its six-month release schedule are features that developers and technophile users love.
Fedora enchances security through SELinux (Security-Enhanced Linux) and the distribution is developed through community contribution to ensure it continues to be a free distribution. In addition to the Workstation flavor, Fedora has other specialized releases such as Fedora Server, Fedora IoT and Fedora Silverblue. In conclusion, if one is looking for a secure Linux environment, that will always have the latest updates and suite a wide range of applications, then Fedora is the right option.
Step 1. Install composer
Open your terminal and run this commnad to download composer
curl -sS https://getcomposer.org/installer | php
Step 2. Make Composer available globally
Run this commands to make your composer globally, so every user use ot
sudo mv composer.phar /usr/local/bin/composer
sudo chmod +x /usr/local/bin/composer
After this your Your composer will be installed successfully but we need to verify to make sure it is installed successfully or not
Step 3. Verify Installation
To verify instaliing successfull or not run this command
composer -v
Output
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ / __ `__ / __ / __ / ___/ _ / ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
____/____/_/ /_/ /_/ .___/____/____/___/_/
/_/
Composer version 2.7.1 2024-02-09 15:26:28
...
Install on Debian
About Debian
Debian is a very mature, general-purpose Linux distribution with a very strong package management system and an enormous software collection. Promoted by Debian Project, this is acknowledged to be as one of the oldest and most well-regarded distributions within the Linux realm. Debian is, therefore, optimized for stability, and most people use it for servers, workstations, and embedded systems.
The distribution entails a testing process that ensures that a software is both credible and free from security flaws. Debian utilizes the APT software, which helps in the installation, management as well as updating of the packages as a system can require. It runs on multiple architectures and has multiple options for the desktop environments such as GNOME, KDE, and XFCE.
Debian has been developed in cooperation with a community and it follows Debian Social Contract and Debian Free Software Guidelines and it also respects the principles of free and open source software. For users who want stable and well-documented Linux distributions where major updates occur in long intervals Debian can be recommended.
Step 1. Install Dependencies
Before Installing Dependencies, update your package list to latest version with this command:
sudo apt update
Install This all dependencies with this command:
sudo apt install curl php-cli php-mbstring git unzip
Curl: We need curl to Download Composer
php-cli: php-cli for installing and running composer
php-mbstring: php-mbstring provides functions for libarary
git: git for downloading project dependencies
unzip: unzip for extracting zipped package
Step 2. Download and setup Composer
Go home directory
Make sure you are in home directory:
cd ~
Install Composer
Install composer using curl:
curl -sS https://getcomposer.org/installer -o composer-setup.php
Verify installation
Verify your installation with this command:
HASH=`curl -sS https://composer.github.io/installer.sig`
run this to print your output:
echo $HASH
Output
dac665fdc30fdd8ec78b38b4800061b4150413gf2e3b6f88543c636k7cd84f6db7577d43a81e5503cda447da73c7e5b6
Your output value might be different
Verify installation seafty
Run this command ,to verify that the installation script is safe to run::
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Output:
Installer verified
Step 3. Set as globally
After installation and checking every security we need to make our composer for global usages:
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
output:
All settings correct for using Composer
Downloading...
Composer (version 2.7.1) successfully installed to: /usr/local/bin/composer
Use it: php /usr/local/bin/composer
Step 4. Verify Composer Installation
Your installation must be complete if you are following this tutorial correctly
So, run this command to checking installation:
composer
Output
______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ / __ `__ / __ / __ / ___/ _ / ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
____/____/_/ /_/ /_/ .___/____/____/___/_/
/_/
Composer version 2.7.1 2024-02-09 15:26:28
...
If you are getting output like this it means you are successfully installed Composer on your system
Install on CentOS
About CentOS
CentOS – A free, enterprise-class, community-supported Linux distribution that exists as a derived work from the source code of Red Hat Enterprise Linux (RHEL). Observable for its stability and steadiness CentOS is extensively used in business environments for servers and significant applications. It therefore provides Red Hat Enterprise Linux compatible environment but does not cost money, making it suitable for businesses and developers.
CentOS Stream, announced as rolling-release version, is designed as the preview of the next RHEL update. CentOS is perfect for anyone who requires a strong, long-term, community-supported distro made more so for enterprise uses.
Step 1. Update your repository
Before doing any thing make sure your local repositories is up-to-dated
If not run this command
sudo yum -y update
Step 2. Install software Dependencies
Install all dependencies which we need to install Composer
yum install php-cli php-zip wget unzip
php-cli: php-cli provides the command-line interface for PHP.
php-zip: using php-zip for handeling zip file.
wget: wget help us to download any file from internet.
unzip: using unzip to extract zip file
Step 3. Install Composer Installer
we need to download composer installer
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
Step 4. Verify download
After downloading verify your download and for this run this command
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
php -r "if (hash_file('SHA384', 'composer-setup.php') === '$HASH') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;
Step 5. Install composer
To install composer run this command
php composer-setup.php --install-dir=/usr/local/bin --filename=composer
After running this command your installation will be completed
Step 6. Verify Installation
Run this command to verify installation
composer
Output
**______
/ ____/___ ____ ___ ____ ____ ________ _____
/ / / __ / __ `__ / __ / __ / ___/ _ / ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__ ) __/ /
____/____/_/ /_/ /_/ .___/____/____/___/_/
/_/
Composer version 2.7.1 ...**
And You're done.
