All Products
Search
Document Center

Alibaba Cloud SDK:Install and use Composer

Last Updated:Jun 03, 2026

Composer is a PHP dependency manager that resolves packages via composer.json, autoloads classes, and runs custom scripts.

Prerequisites

  • PHP 5.6 or later is installed. If not, see Install PHP.

  • The openssl extension is enabled in your PHP installation.

    How to check if the openssl extension is enabled

    Run the following command. If the output includes openssl, the extension is enabled.

    • Windows

      php -m | find "openssl"
    • Linux

      php -m | grep openssl

    To enable the openssl extension:

    1. Locate php.ini in your PHP installation directory.

    2. Open the php.ini file and find the line that contains the openssl extension, such as extension=openssl, extension=php_openssl.dll, or extension=openssl.so.

    3. If the line starts with a semicolon (;), remove the semicolon to uncomment it.

    4. Save the file and verify the change.

Install Composer

Install Composer on your operating system.

Windows

  1. Download the Composer installer.

    Download Composer-Setup.exe from the Composer download page.

  2. Run the installer and follow the on-screen instructions.

  3. Verify the installation.

    Open a command prompt (Win+Rcmd) and run composer -V. Output similar to the following confirms success:

    Composer version 2.7.7 2024-06-10 22:11:12
    PHP version 7.4.33
    Run the "diagnose" command to get more detailed diagnostics output.

Linux

  1. Run one of the following commands to install Composer:

    • Alibaba Cloud Linux/CentOS

      sudo yum install -y composer
    • Ubuntu/Debian

      sudo apt install -y composer
  2. Run composer --version to verify. Output similar to the following confirms success:

    Composer version 1.10.27 2023-09-29 10:50:23

macOS

  1. Run the following commands to install Composer:

    curl -sS https://getcomposer.org/installer | php
    sudo mv composer.phar /usr/local/bin/composer
    chmod +x /usr/local/bin/composer
  2. Run composer --version to verify the installation.

Using Composer

Installing dependencies

  • The install command

    Create a composer.json file in your project root to define dependencies:

    {
        "require": {
            "alibabacloud/dysmsapi-20170525": "4.1.*"
        }
    }

    This requires version 4.1.x of alibabacloud/dysmsapi-20170525. Install it:

    composer install
  • The require command

    Alternatively, use require to install a dependency without editing composer.json manually:

    composer require alibabacloud/dysmsapi-20170525
    

    Composer resolves a compatible version, adds alibabacloud/dysmsapi-20170525 to composer.json, downloads the package, updates composer.lock, and regenerates autoload files.

Updating dependencies

The update command updates all or specific packages:

# Update all dependencies
composer update
# Update a specific package
composer update alibabacloud/dysmsapi-20170525
# Update multiple specific packages
composer update alibabacloud/dysmsapi-20170525 alibabacloud/credentials
# You can also use a wildcard to match packages
composer update alibabacloud/*
Note

Version constraints restrict package upgrades to a specified range.

Removing a dependency

The remove command removes a package and its unused dependencies:

composer remove monolog/monolog

Listing installed packages

composer show --installed

Version constraints

Exact version

Pin an exact version. For example, composer require alibabacloud/dysmsapi-20170525 4.1.2 installs version 4.1.2.

Range

Use comparison operators (>, >=, <, <=, !=) to define version ranges. A space or comma means AND; || means OR. AND has higher precedence.

  • composer require alibabacloud/dysmsapi-20170525 >=4.1 installs a version greater than or equal to 4.1.0.

  • composer require alibabacloud/dysmsapi-20170525 '>=4.1, <4.2' installs any 4.1.x version.

Wildcard (*)

The wildcard matches any minor or patch version within a major version. composer require alibabacloud/dysmsapi-20170525 4.1.* installs any 4.1.x version (equivalent to >=4.1.0 <4.2.0).

Tilde (~)

The tilde allows patch-level updates but locks the minor version. composer require alibabacloud/dysmsapi-20170525 ~4.1.3 installs a version in the range >=4.1.3 and <4.2.0.

Caret (^)

The caret allows minor and patch updates but prevents major version changes. composer require alibabacloud/dysmsapi-20170525 ^4.1 installs a version in the range >=4.1.0 and <5.0.0.