All Products
Search
Document Center

Object Storage Service:Installation

Last Updated:Feb 27, 2025

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.

Preparations

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.

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:

              .
              ├── 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 must add the following dependency to app.php:

      require_once __DIR__ . '/../vendor/autoload.php';
                                  
    Note
    • 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 http://packagist.phpcomposer.com 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';

FAQ

What do I do if the "Your configuration does not allow connection" error message is returned?

Complete 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

Problem description

When you use Composer to install OSS SDK for PHP, a connection problem occurs and the required dependencies cannot be downloaded by using Composer.

Causes

By default, Composer is configured to deny connections over HTTP. To ensure data security, all connections must use HTTPS. This improves data transmission security and prevents sensitive data from being leaked or tampered with.

Solutions

If you need to download dependencies over HTTP in specific internal network environments, you can change the configurations of Composer to allow HTTP connections.

Run the following command in the root directory of the project to configure Composer to allow HTTP connections:

composer config secure-http false.

Take note that data security is compromised if you disable HTTPS. We recommend that you use HTTPS for secure connections.