16 C
Texas
angeloma
Senior Writer and partner

How to install PHP Composer on Ubuntu 20.04?

PHP is one of the most widely used programming languages on the web and this makes it possible to create tools that facilitate the development of quality applications. One of them is to install PHP Composer on Ubuntu 20.04 so that together with other tools you can start developing applications efficiently

What is Composer?

Composer is a tool for dependency management in PHP. So, it allows you to declare the libraries your project depends on and it will manage (install/update) them for you. This way we will not have to worry about installing those libraries.

To do this, Composer is strongly inspired by NPM and Ruby’s bundler. In other words, it is not a package manager like APT or Yum, because it does not install specific applications globally but only libraries.

On the same Composer website, we are given the following example to show the usefulness of the tool.

- Advertisement -

First, suppose:

  • You have a project that depends on a number of libraries.
  • Some of those libraries depend on other libraries.

Composer:

  • Enables you to declare the libraries you depend on.
  • Finds out which versions of which packages can and need to be installed, and installs them (meaning it downloads them into your project).

So, let us start to install Composer.

Install PHP Composer on Ubuntu 20.04

Composer has an executable for Ubuntu 20.04, so it’s best to take advantage of it and have the latest stable version available.

However, before starting you have to install some dependencies of Composer.

So, open a terminal and run the following command:

:~$ sudo apt update
:~$ sudo apt install php libapache2-mod-php php-mbstring php-xmlrpc php-soap php-gd php-xml php-cli php-zip

After the whole process is finished, check the version of PHP:

:~$ php -v
PHP 7.4.3 (cli) (built: Mar 26 2020 20:24:23) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies
with Zend OPcache v7.4.3, Copyright (c), by Zend Technologies

Composer requires PHP 5.4 but that’s not a problem because most Linux distributions already support version 7.0 or higher.

Then your system probably already has curl installed, but it’s always better to be sure, so proceed to run it:

:~$ sudo apt install curl

Curl is a program that serves to download files from the Internet using the terminal. Obviously it’s not limited to this, but let’s say that many people use it just for this.

How to use the Curl command?

Then download the installed Composer and run it with PHP. All this can be done from a single line.

:~$ curl -sS https://getcomposer.org/installer | php
1.- Install Composer on Ubuntu 20.04
1.- Install Composer on Ubuntu 20.04

To make Composer globally available, move it to the binary folder, change the permissions, and refresh the user’s bash profile.

:~$ sudo mv composer.phar /usr/local/bin/composer
:~$ sudo chmod +x /usr/local/bin/composer
:~$ source ~/.bashrc

Then, check that the command works correctly, you just have to use it and, for example, show the version of it.

:~$ composer -v
2.- Composer version
2.- Composer version

So, Composer is installed and running on Ubuntu 20.04

Conclusion

For web developers, it is important to have tools that help create applications. In this sense, Composer is presented to us as a vital dependency manager for our projects.

Finally, please share this post with your friends and join our Telegram Channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article