This topic describes how to install Object Storage Service (OSS) SDK for PHP.


OSS SDK for PHP is applicable to PHP 5.3 and later. This topic uses PHP 5.6.22 in the example.

  • Environment requirements

    You must install PHP and the cURL extension:

    • In Windows, you can go to Compile and use Alibaba Cloud OSS PHP SDK in Windows to install PHP and the cURL extension. If a message that indicates the specified module is unavailable appears, set extension_dir to C:/Windows/System32/.
    • In Ubuntu, run the sudo apt-get install php-curl command to install the cURL extension of PHP by using apt-get.
    • In CentOS, run the sudo yum install php-curl command to install the cURL extension of PHP by using YUM.
  • PHP version and cURL extension checks
    • You can run the php -v command to view the current PHP version.
    • You can run the php -m command to check whether the cURL extension is installed.

Download OSS SDK for PHP

For more information, see API Documentation.

Note We recommend that you use the SDK of the latest version. To download OSS SDK for PHP versions earlier than 2.0.0, click Download.

Install OSS SDK for PHP

You can use one of the following methods to install OSS SDK for PHP:

  • Composer
    1. Go to the root directory of your project and run the composer require aliyuncs/oss-sdk-php command or add the following dependency to the composer.json file:
      "require": {
          "aliyuncs/oss-sdk-php": "~2.4"
    2. Run the composer install command to install the dependency. After the dependency is installed, check whether your directory structure complies with the following structure:
              ├── app.php
              ├── composer.json
              ├── composer.lock
              └── vendor

      In the preceding directory structure, app.php indicates your application, and the vendor/ directory contains the dependent library. You need to add the following dependency to app.php:

      require_once __DIR__ . '/vendor/autoload.php';
    • If autoload.php is imported to your project, you do not need to import it again after you add the dependency of OSS SDK for PHP.
    • If a network error occurs when you use Composer, you can use the image source of Composer China by running the composer config -g repositories.packagist composer command.
  • PHAR
    1. Select the corresponding version and download the packaged PHAR file from GitHub.
    2. Import the PHAR file to your code:
      require_once '/path/to/oss-sdk-php.phar';
  • Source code
    1. Select the required version and download the ZIP package from GitHub.
    2. The decompressed root directory contains the autoload.php file. Import the file to the code:
      require_once '/path/to/oss-sdk/autoload.php';