All Products
Search
Document Center

Object Storage Service:Installation (PHP SDK V1)

Last Updated:Nov 29, 2025

Install the OSS PHP SDK to manage OSS buckets, upload and download files, manage data, or perform image processing. This topic describes multiple ways to install the OSS PHP SDK. You can choose the method that best fits your scenario.

Prerequisites

The OSS PHP SDK requires PHP 5.3 or later. This topic uses PHP 5.6.22 as an example.

  • Installation environment

    Install PHP and the cURL extension:

    • On Windows, see Compile and use Alibaba Cloud OSS PHP SDK on Windows to install PHP and the cURL extension. If a "module not found" error occurs, set `extension_dir` to C:/Windows/System32/ in the php.ini file.

    • On Ubuntu, you can use the apt-get package manager to install the cURL extension for PHP: sudo apt-get install php-curl.

    • On CentOS, you can use the yum package manager to install the cURL extension for PHP: sudo yum install php-curl.

  • Check versions

    • Run the php -v command to check the PHP version.

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

Download the SDK

For more information, see the OSS API documentation.

Note

We recommend that you use the latest version of the SDK. You can download the documentation for OSS PHP SDK versions earlier than 2.0.0 from here.

Install the SDK

You can install the SDK using one of the following methods:

  • Using Composer

    1. Run the composer require aliyuncs/oss-sdk-php command in the root directory of your project, or add the following dependency to your composer.json file.

      
      "require": {
          "aliyuncs/oss-sdk-php": "~2.4"
      }
                                  
    2. Run the composer install command to install the dependencies. After the installation is complete, the directory structure is as follows:

              .
              ├── src
              |   └──app.php
              ├── composer.json
              ├── composer.lock
              └── vendor
                                  

      In this structure, app.php is your application file and the vendor/ folder contains the dependencies. Add the following line to your app.php file:

      require_once __DIR__ . '/../vendor/autoload.php';
                                  
    Note
    • If your project already includes a reference to autoload.php, you do not need to add it again.

    • If a network error occurs when you use Composer, you can use a Composer mirror for the China region. To do this, run the following command on the command line: composer config -g repositories.packagist composer http://packagist.phpcomposer.com.

  • Using a PHAR file

    1. From GitHub, select the required version and download the packaged PHAR file.

    2. Include a reference to the PHAR file in your code:

      require_once '/path/to/oss-sdk-php.phar';
                                  
  • Using the source code

    1. From GitHub, select the required version and download the source code package (ZIP file).

    2. The root directory of the unzipped package contains an autoload.php file. Include a reference to this file in your code:

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

FAQ

Error: Your configuration does not allow connection

Full error message

Your configuration does not allow connection to http://packagist.phpcomposer.com/packages.json. See https://getcomposer.org/doc/06-config.md#secure-http for details

Symptoms

When you use Composer to install the SDK, a connection error occurs, and you cannot download the required dependencies.

Cause

By default, the Composer configuration prohibits connections over HTTP. For security reasons, all connections must use HTTPS. This practice ensures data transmission security and prevents sensitive information from being leaked or tampered with.

Solution

To download dependencies over HTTP, such as in certain internal network environments, you can adjust the Composer configuration to allow HTTP connections.

In the root directory of your project, run the following command to configure Composer to allow HTTP connections:

composer config secure-http false.

Note that disabling HTTPS reduces security. Prioritize secure connections in environments where HTTPS is available.