How to install and use Composer on an ECS instance on Ubuntu 16.04

This tutorial will show you how to install and use ** Composer ** on a ** Alibaba Cloud ECS ** instance installed on Ubuntu 16.04.

By Ghulam Qadir, author of Alibaba Cloud Community Blog.

Composer depends on the package of PHP The relationship management tool can be used by you and other developers alike to manage PHP-based projects and applications.

You've seen many PHP applications asking you if you have Composer installed on your system in order to install and run the package. That's how important and popular Composer is now.

This means that composer is often used to make it easier to install and update PHP applications. The Composer Dependency Tool makes it easy to install and manage packages. Composer is a list of required packages in a JSON file called composer.json Helps you manage.

Composer is compatible with Alibaba Cloud Elastic Compute Service (ECS) instances and works well. As a developer, I prefer to use Composer on Alibaba Cloud ECS instances with Ubuntu 16.04 installed. Alibaba Elastic Compute (ECS) is flexible and allows you to upgrade your hardware resources whenever traffic increases.


  1. I have an instance of Alibaba Cloud Elastic Compute Service (ECS). If you are new to ECS or new to ECS, use your Alibaba Cloud account for Free Credit .0.4b9d58c9AtZlfU & biz_params =% 7B% 22intl% 22% 3A% 22% 7B% 5C% 22referralCode% 5C% 22% 3A% 5C% 22ffxt3q% 5C% 22% 7D% 22% 7D) can be obtained. If you don't know how to set up an ECS instance, this Tutorial ( = a2c65.11461447.0.0.4b9d58c9AtZlfU) or check the Quick Start Guide (
  2. You need to set the host name of the server.
  3. Access Alibaba Cloud's VNC console or use the SSH client installed on your PC.


Follow the steps in the next section to learn how to install and use Composer on your Alibaba Cloud ECS instance installed with Ubuntu version 16.04.

Log on to the console

Enter your root username and password from the SSH client (Putty) or the VNC console available on the Alibaba Cloud account dashboard. Log on as the root user.

Before we start this tutorial, again, we need the following:

-The Alibaba Cloud ECS instance is installed with Ubuntu version 16.04, has at least 2GB of RAM, has private networks enabled, and is not the root user. This can be set by following the initial ECS instance server configured in Ubuntu 16.04.

Dependency installation

Before you download and install Composer, you need to make sure that all the dependencies are installed on your server.

First, run the following two commands to update the package manager cache.

# sudo apt-get update

# sudo apt-get upgrade

Next, you have to install the dependencies (curl, php-cli, php-mbstring, git, unzip). You can install everything with the following command.

sudo apt-get install curl php-cli php-mbstring git unzip

PHP installation

Composer requires PHP version 5.3.0 or later. To install PHP on Ubuntu, run the sudo apt-get install php command. Alternatively, you can use the following command to install a specific version of PHP: sudo apt-get install php7.2. If you are installing another version, such as 7.1 or 7.3, the numeric value. You can also change.

Install Composer

Composer provides an installer written in PHP. Since PHP is installed, execute the following command to install composer.

cd ~

curl -sS -o composer-setup.php

Then run a short PHP script to run the latest installer SHA on the Composer Public Keys / Signatures ( page. -384 Make sure it matches the hash. You need to assign the latest hash to the highlighted value below.

 php -r "if (hash_file('SHA384', 'composer-setup. php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL; “

Should be the output.


 Installer verified

To install composer globally:

sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer

This will download and install Composer as a system-wide command named composer under / usr / local / bin. The output looks like this:


All settings correct for using Composer

Downloading 1.1.1...

Composer successfully installed to: /usr/local/bin/composer

Use it: php /usr/local/bin/composer

To test the installation, run the composer command and you should get output like this:



 / ____/___  ____ ___  ____  ____  ________  _____

 / /  / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/

/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /

\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/


Composer version 1.1.1 2016-05-17 12:25:44


 command [options] [arguments]


 -h, --help  Display this help message

 -q, --quiet  Do not output any message

 -V, --version  Display this application version

 --ansi  Force ANSI output

 --no-ansi  Disable ANSI output

 -n, --no-interaction  Do not ask any interactive question

 --profile  Display timing and memory usage information

 --no-plugins  Whether to disable plugins.

. . .

Composer is now installed on your system.

Now, if you want to install a PHP-based application that requires Composer, just refer to this page to learn how to install Composer. Then continue to get the PHP application on Ubuntu.

You can also upgrade Composer by running the sudo composer self-update command. This will upgrade all composer related packages. You can also install it by downloading and verifying the installation script as above, and then doing the following: php composer-setup.php. It will generate a composer.phar file in your current directory and you can run it with the ./composer.phar command.

Generate Composer.json file

You need the composer.json file to use composer in your project. The composer.json file is a file that tells composer to download the dependencies needed for your project.

Also specify the version to install in the project. This avoids backwards compatibility issues while running the project due to unstable package versions.

You don't have to create this project manually. Also, if you actually create it, you may get a syntax error. composer automatically creates the composer.json file while you install the project dependencies using the require command.

You can use this command to add dependencies without having to edit the file. This section describes the process of adding a package as a dependency to your project.

--Find the library requirements for your application. --Search for application library requirements. Search the official Composer repository,, for a matching open source library. --Select the required package. --Run the composer require command to include the dependencies in the composer.json file and install the package.

Let's see how it works in real time using the demo application.

Here we need to give a sentence and convert it to a slug (that is, a URL-friendly string). This technique is used to convert page titles to URLs. First, change to your home directory.

First, let's create a directory for the project. I'll call it slugify here.

 cd ~

 mkdir slugify

 cd slugify

Find a package from the package list

Go to Packagist and search for packages that will help you generate slugs. Search for "slug" in the search bar. All related packages are listed here. Numbers are displayed in each description after the name.

The down arrow indicates the number of downloads, and the star indicates how many times the package was featured in the composer. Select the package that you download most often. Packages that are downloaded by many people will be stable. You also have to find a package that matches your expectations.

Here, slugify matches our requirements. You can see what a package looks like by reading the package description. The packages are listed by package name and vendor name. The package name is also listed.

Here we use cocur / slugify.

Add package

To add a package, use the composer require command. Then generate a composer.json file.

 $ composer require cocur/slugify

You will get the following output.


 Using version ^2.1 for cocur/slugify

 ./composer.json has been created

 Loading composer repositories with package information

 Updating dependencies (including require-dev)

 - Installing cocur/slugify (v2.1.1)

 Downloading: 100% 

 Writing lock file

 Generating autoload files

You can see that the composer automatically selects the version of the package to add to the output. There are also two files, composer.json and composer.lock.

You can also check the vendor directory.

$ ls -l

You will get the following output.


 total 12

 -rw-rw-r-- 1 gqadir gqadir  59 Jan 17 10:24 composer.json

 -rw-rw-r-- 1 gqadir gqadir 2894 Jan 17 10:24 composer.lock

 drwxrwxr-x 4 gqadir gqadir 4096 Jan 17 10:24 vendor

We've already seen how to use the composer.json file. However, this time I will show you how to use the composer.lock file. This file contains version information for each package.

If you copied the project, this file will help you install the correct version of Composer. The vendor directory has dependencies for all projects.

Do not commit vendor folders to version control. Just include the composer.json and composer.lock files in your vendor folder.

If you tend to install the project and it contains the composer.json file, you must use the composer installation to download the project dependencies.

Project dependency updates

Updating project dependencies is very easy. To update the dependencies, just use the composer update command. What this command does is look for the latest version of the dependency.

In other words, if you have the latest version available and it is compatible with the composer.json file, the old dependencies will be replaced with the new ones. The composer.lock file is also updated to take advantage of the changes.

Next is the command to update a specific dependency.

 composer update vendor/package vendor2/package2


This tutorial has shown you what you need to get started with Composer on an ECS instance installed with Ubuntu 16.04. Composer is a must-have tool for PHP developers.

Not only does it provide an easy and reliable way to manage project dependencies, but it also establishes a new standard for sharing and discovering PHP packages created by the community.

Recommended Posts

How to install and use Composer on an ECS instance on Ubuntu 16.04
How to install Ruby on an EC2 instance on AWS
How to use Bio-Formats on Ubuntu 20.04
How to install WildFly on Ubuntu 18.04
Install SonarQube on ECS instance on Ubuntu 16.04
How to Install Elixir and Phoenix Framework on Ubuntu 20.04 LTS
How to install production Metabase on Ubuntu
How to install and configure the monitoring tool "Graphite" on Ubuntu
How to install network drivers on standalone Ubuntu
How to install NVIDIA driver on Ubuntu 18.04 (Note)
How to install multiple JDKs on Ubuntu 18.04 LTS
How to install NVIDIA driver on Ubuntu ssh destination
How to use RealSense with ubuntu 20.04 and ROS Noetic
How to handle an instance
How to use OpenCV 4 on Android and view camera live view
How to create an application server on an EC2 instance on AWS
How to install java9 on elementaryOS Freya or Ubuntu 14.04 LTS
How to use StringBurrer and Arrays.toString.
How to use EventBus3 and ThreadMode
Install JDK and JRE on Ubuntu 16.10
How to install ImageMagick on Windows 10
How to use Ruby on Rails
How to use equality and equality (how to use equals)
How to install MariaDB 10.4 on CentOS 8
Preparing to use electron-react-boilerplate on Ubuntu 20.4
How to build vim on Ubuntu 20.04
How to develop an app with Jersey Java RESTful API on Alibaba Cloud ECS instance
How to install the language used in Ubuntu and how to build the environment
How to install Adopt OpenJDK on Debian, Ubuntu with apt (-get)
Install Ubuntu20.04 on RaspberryPi 4 and build Kubernetes to run the container
How to create a web server on an EC2 instance on AWS
Steps to install Maven on Mac and use it in Eclipse
A memorandum on how to use Eclipse
How to use Apache Derby on Eclipse
How to use OrientJS and OrientDB together
[Ruby on Rails] How to use CarrierWave
How to install Eclipse (Photon) on Mac
How to publish an application on Heroku
[Easy-to-understand explanation! ] How to use Java instance
I want to install PHP 7.2 on Ubuntu 20.04.
How to install beta php8.0 on CentOS8
How to set up and use kapt
How to change the timezone on Ubuntu
[Ruby on Rails] How to use redirect_to
[Ruby on Rails] How to use kaminari
How to use substring and substr methods
How to install kafkacat on Amazon Linux2
How to use @Builder and @NoArgsConstructor together
How to install c2ffi on Ubuntu, which automatically parses C header files
What to do and how to install when an error occurs in DXRuby 1.4.7
(For beginners) [Rails] Time saving tech! How to install and use slim
[Java] How to use FileReader class and BufferedReader class
Build and install Wireshark Development Release (3.3.1) on Ubuntu
How to configure ubuntu to be used on GCP
[Ruby] How to use gsub method and sub method
How to use an array for HashMap keys
Notes on how to use each JUnit Rule
How to use Segmented Control and points to note
How to use scope and pass processing (Jakarta)
Install and switch between multiple Javas on Ubuntu
How to use nfs protocol version 2 with ubuntu 18.04