How to Install and Use Composer on Ubuntu 16.04

Prerequisites

  1. You have an Alibaba Cloud Elastic Compute Service (ECS) instance. If you are a new user or new to ECS, you can get Free Credits in your Alibaba Cloud account. If you don’t know about how to setup your ECS instance, you can refer to this tutorial or check quick-start guide.
  2. You should setup your server’s hostname.
  3. You have access to the VNC console in your Alibaba Cloud or SSH client installed in your PC.

Procedure

Logging on to Your Console

  • An Alibaba Cloud ECS instance installed with Ubuntu version 16.04 with at least 2 GB of RAM, private networking enabled, and a non-root user. This can be set up by following the Initial ECS instance server set up with Ubuntu 16.04.

Installing the Dependencies

# sudo apt-get update# sudo apt-get upgrade
sudo apt-get install curl php-cli php-mbstring git unzip

Installing PHP

Installing Composer

cd ~curl –sS https://getcomposer.org/installer -o composer-setup.php
php -r "if (hash_file('SHA384', 'composer-setup.php') === '669656bab3166a7aff8a7506b8cb2d1c292f042046c5a994c43155c0be6190fa0355160742ab2e1c88d40d5be660b410') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('composer-setup.php'); } echo PHP_EOL;"
Output Installer verified
sudo php composer-setup.php --install-dir=/usr/local/bin --filename=composer
OutputAll settings correct for using ComposerDownloading 1.1.1...Composer successfully installed to: /usr/local/bin/composerUse it: php /usr/local/bin/composer
Output ______ / ____/___  ____ ___  ____  ____  ________  _____ / /  / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___// /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/ /_/Composer version 1.1.1 2016-05-17 12:25:44Usage: command [options] [arguments]Options: -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.. . .

Generating the Composer.json File

  • Find the library requirements of applications.
  • Find a matching open-source library on packagist.org, which is the official repository for Composer.
  • Select the package that you require.
  • Run the composer require the command to include the dependency in the composer.json file and then install the package.
cd ~ mkdir slugify cd slugify

Finding the Package from the Package List

Adding the Package

$ composer require cocur/slugify
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
$ ls -l
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

Updating the Project Dependencies

composer update vendor/package vendor2/package2

Summary

Original Source

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Alibaba Cloud

Alibaba Cloud

Follow me to keep abreast with the latest technology news, industry insights, and developer trends. Alibaba Cloud website:https://www.alibabacloud.com