Articles

How to Install PHP Composer on CentOS 8

A 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.

Install and use PHP composer on centOS 8; Through this tutorial, we will learn how to install and use PHP composer on CentOS 8.

How to Install PHP Composer on CentOS 8

Just follow the following steps to install PHP composer on centOS 8:

  • Step 1 – Install the PHP CLI
  • Step 2 – Download Composer with curl
  • Step 3 – Move Composer file
  • Step 4 – Getting Started with Composer

Step 1 – Install the PHP CLI

First of all, open the command line or terminal and execute the following command into it to install PHP CLI on centOS 8:

sudo dnf install php-cli php-json php-zip curl unzip

Step 2 – Download Composer with curl

Once the PHP CLI installation is completed, then execute the following command on the command line or terminal to download composer with curl:

curl -sS https://getcomposer.org/installer |php

Step 3 – Move Composer file

Then move the composer file using the following command on centOS 8:

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

Step 4 – Getting Started with Composer

At this point, WE have successfully installed Composer on CentOS system. And now, we will learn how to use Composer in a PHP project.

Now, execute the following command on the command line or terminal to create PHP project using the composer command:

mkdir ~/my-first-composer-project
cd ~/my-first-composer-project

Once the PHP project creation is done, then execute the following command to initialize a new Composer project and install the carbon package:

composer require nesbot/carbon

Then create a file named testing.php and add the following code:

Finally, execute the following command n command line or terminal to test above created PHP project with the help of PHP composer:

php testing.php

The output should look something like this:

Now: 2022-08-10 22:12:26

Conclusion

Through this tutorial, we have learned how to install and use Composer on CentOS 8 machine. And also how to use Composer to create a basic PHP project.

Images mentioned above related to CentOS,Composer,PHP are either copyright property of respective image owners.

Rabins Sharma Lamichhane

Rabins Sharma Lamichhane is the owner of RabinsXP who is constantly working for increasing the Internet of Things (IoT) in Nepal. He also builds android apps and crafts beautiful websites. He is also working with various social services. The main aim of Lamichhane is to digitally empower the citizens of Nepal and make the world spiritually sound better both in terms of technology and personal development. Rabins is also the first initiator of Digital Nepal.

Related Articles

Leave a Reply

Your email address will not be published.

Back to top button