How to Install PHP Composer on Ubuntu 20.04

 

 

 

In simple terms, it is a PHP application-level package manager you can use to declare the libraries your project depends on and it manage them. The development of the system was led by Nils Adermann and Jordi Boggiano. Composers are PHP tools for managing dependencies. Composers use Packagist.org as their main bundle providers. These files are accessed from repositories submitted by users. Among other features, Packagist.org provides version control or integration with GitHub or Bitbucket.

 

 

 

 

Throughout this tutorial, we’ll walk you through the steps to install PHP Composer on Ubuntu 20.04

 

 

 

 

 

Step 1: Configure VPSie cloud server

 

 

 

  1. Sign in to your system or register a newly created one by logging in to your VPSie account
  2. Connect by SSH using the credentials we emailed you.
  3. Once you have logged into your Ubuntu instance, run these commands to update your system.
# apt-get update && apt-get upgrade -y

 

 

 

 

 

Step 2: Installing PHP

 

 

 

 

In order to use composer, your system must have PHP installed. Follow these steps to install PHP.

 

 

 

# sudo apt update

# sudo apt install php php-gd php-xml php-cli php-zip

 

 

Additional packages need to be installed on your system as well. Run the following commands on shell.

 

 

# sudo apt install unzip curl 

 

 

 

By executing the following commands you can determine the current PHP version,

 

 

# php -v

 

 

 

 

Step 3: Install PHP Composer

 

 

 

 

Please use the following command to download and install the composer executable file.

 

 

 

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

 

 

By using the following commands, composer will be made available globally to all users on your network,

 

 

 

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

# chmod +x /usr/local/bin/composer 

 

 

After installation of the composer on your system. Execute composer from the command line. It provides details about the composer version as well as options available through the composer command.

 

 

 

# composer -v 

 

 

 

 

 

Step 4: Using the Composer

 

 

 

 

 

 

By following the same instructions as for installation, you can download the latest version of the composer. Composers can also update themselves. You can do this with the following command.

 

 

 

 

 

In the case of an existing project:

 

 

Run the below command in the application root directory. Composer.json will be read and dependencies will be installed.

 

 

 

# composer install 

 

 

 

 

Starting a New Project:

 

 

 

 

Install the required modules in the project directory as shown below.

 

# mkdir myapp && cd myapp 

# composer require psr/log

 

 

 


 

 

Thanks for reading, that’s all for now! I hope it was informative. 


 

 

 

 

Try VPSie for free today!