All Products
Document Center

Object Storage Service:Installation

Last Updated:Dec 13, 2023

If you want to manage Object Storage Service (OSS) buckets, upload and download objects, manage data, and perform image processing (IMG), install OSS SDK for PHP first. This topic describes how to install OSS SDK for PHP by using various methods. You can choose a suitable installation method based on your requirements.


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:

    • For more information about how to install PHP and the cURL extension in Windows, see Compile and use Alibaba Cloud OSS PHP SDK in Windows. If a message that indicates the specified module is unavailable appears, set extension_dir to C:/Windows/System32/ in the php.ini file.

    • 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

    • Run the php -v command to view the current PHP version.

    • Run the php -m command to check whether the cURL extension is installed.

Download OSS SDK for PHP

For more information, see API Documentation.


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:

              ├── src
              | └── 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.

    • 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. Decompress the package and import the autoload.php file contained in the decompressed root directory to the code.

      require_once '/path/to/oss-sdk/autoload.php';