All Products
Search
Document Center

Object Storage Service:Installation (PHP SDK V1)

Last Updated:Mar 20, 2026

Install the OSS SDK for PHP to manage buckets and objects in Object Storage Service (OSS). Three installation methods are available: Composer, PHAR file, and source code.

Prerequisites

Before you begin, ensure that you have:

  • PHP 5.3 or later (this document uses PHP 5.6.22 as an example)

  • The cURL extension for PHP

Install the cURL extension

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 your php.ini file.

Ubuntu

sudo apt-get install php-curl

CentOS

sudo yum install php-curl

Verify prerequisites

Run the following commands to confirm that PHP and cURL are installed:

# Check PHP version
php -v

# List loaded extensions
php -m

The output of php -v displays the PHP version. The output of php -m should include curl.

Choose an installation method

MethodBest for
Composer (recommended)Projects that use a dependency manager
PHAR fileProjects without Composer
Source codeCustom builds or legacy systems

Method 1: Composer (recommended)

Composer is the standard PHP dependency manager. Use this method for most projects.

Step 1: Install Composer

If Composer is not already installed:

Step 2: Add the SDK dependency

In the root directory of your project, run:

composer require aliyuncs/oss-sdk-php

Alternatively, add the dependency to your composer.json file and run composer install:

"require": {
    "aliyuncs/oss-sdk-php": "~2.4"
}

Step 3: Add the autoloader

After installation, your project structure looks like this:

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

Add the Composer autoloader to your application file (for example, app.php):

<?php
require_once __DIR__ . '/../vendor/autoload.php';
?>

If your project already references autoload.php, skip this step.

If a network error occurs, use the Composer mirror for the China region by running: composer config -g repositories.packagist composer http://packagist.phpcomposer.com

Method 2: PHAR file

  1. Go to GitHub Releases and download the PHAR file for your target version.

  2. Include the PHAR file in your code:

       <?php
       require_once '/path/to/oss-sdk-php.phar';
       ?>

Method 3: Source code

  1. Go to GitHub Releases and download the ZIP file for your target version.

  2. Extract the archive. The root directory contains an autoload.php file. Include it in your code:

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

Verify the SDK installation

Create a test script to confirm the SDK is installed correctly:

<?php
require_once __DIR__ . '/vendor/autoload.php';

use OSS\OssClient;

echo "OSS SDK loaded successfully.\n";
?>

Run the script:

php test.php

If the SDK is installed correctly, the script runs without errors.

Troubleshooting

"Your configuration does not allow connection" error

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

Cause

Composer blocks HTTP connections by default and requires HTTPS for all package downloads.

Solution

If HTTPS is unavailable in your network environment, allow HTTP connections by running the following command in your project root:

composer config secure-http false
Warning

Disabling HTTPS reduces security. Use secure connections whenever possible.

cURL extension not loaded

Symptom

Call to undefined function curl_init()

Cause

The cURL extension is not installed or not enabled.

Solution

  1. Install the cURL extension for your operating system (see Prerequisites).

  2. Verify the extension is loaded:

       php -m | grep curl
  3. If cURL is installed but not listed, uncomment the following line in php.ini:

       extension=curl
  4. Restart your web server or PHP-FPM service.

SDK resources

ResourceLink
Source codeGitHub
Releases and changelogGitHub Releases
API referenceOSS PHP SDK API documentation
Use the latest version of the SDK. For versions earlier than 2.0.0, see OSS PHP SDK legacy documentation.

What's next