Installation

Last Updated: Aug 11, 2017

Download SDK

Prepare the environment

  • PHP 5.3+ (Run the php -v command to view the current PHP version)
  • cURL extension (Run the php -m command to check whether cURL extension has been installed).

Note:

  • In Ubuntu, you can use the apt-get package manager to install the PHP cURL extension sudo apt-get install php-curl.
  • In CentOS, you can use the yum package manager to install the PHP cURL extension sudo yum install php-curl.

Installation

You can install the SDK with three methods:

  • composer
  • pha
  • Source code

composer

  1. You can install your project dependencies through Composer. To do this, run the following in your project root directory:

    composer require aliyuncs/oss-sdk-php

  2. You can also declare the dependency on Alibaba Cloud OSS SDK for PHP in composer.json:

    1. "require": {
    2. "aliyuncs/oss-sdk-php": "~2.0"
    3. }
  3. Install the dependency through composer install. After the dependency is installed, check whether your directory structure complies with the following structure:

    1. .
    2. ├── app.php
    3. ├── composer.json
    4. ├── composer.lock
    5. └── vendor

    The app.php is a user application. The vendor/ directory contains the dependent library. You need to introduce the dependency in app.php:

    1. require_once __DIR__ . '/vendor/autoload.php';

Notice:

  • If your project references autoload.php, you do not need to introduce autoload.php again after adding the SDK dependency.
  • If a network error occurs when you use the Composer Dependency Manager, you can use the Composer China region Image Source by executing the following in the command line: composer config -g repositories.packagist composer http://packagist.phpcomposer.com

phar

  1. To use the Phar single-file method, you need to select the desired version on the Release Page and download the Phar package.

  2. Introduce the file in your code:

    1. require_once '/path/to/oss-sdk-php.phar';

Source code

  1. To use the SDK source code method, you need to select the desired version on the Release Page and download the Zip package.

  2. Find the autoload.php file in the root directory of the unzipped package, and introduce the file in your code:

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

Sample project

Run the sample project by following the steps below:

  1. Decompress the downloaded SDK package.

  2. Modify the Config.php file in the samples directory.

    1. Modify OSS_ACCESS_ID, which is the AccessKeyID that you obtain from OSS.
    2. Modify OSS_ACCESS_KEY, which is the AccessKeySecret that you obtain from OSS.
    3. Modify OSS_ENDPOINT, which is the access domain name (such as http://oss-cn-hangzhou.aliyuncs.com) of the OSS data center you have selected.
    4. Modify OSS_TEST_BUCKET, which is the bucket to be used for running the sample project. The sample project will create a few objects in this bucket.

      Notice: Do not use a bucket in a production environment to avoid contaminating user data.

  3. Run php RunAll.php in the samples directory. You can also run a single sample file.

The sample project includes the following content:

Sample files Sample content
Object.php Demonstrate Object operations, including Upload, Download, Copy, Delete, List, and Metadata.
MultipartUpload.php Demonstrate the usage of Large File Upload and Multipart Upload.
Signature.php Demonstrate the Access Authorization by URL Signature usage.
Callback.php Demonstrate Upload Callback usage.
Image.php Demonstrate Image Processing usage.
LiveChannel.php Demonstrate LiveChannel usage.
Bucket.php Demonstrate Bucket management operations, including Create, Delete, List, and ACL.
BucketLifecycle.php Demonstrate how to set/read/clear bucket Lifecycle.
BucketLogging.php Demonstrate how to set/read/clear bucket Log.
BucketReferer.php Demonstrate how to set/read/clear bucket Anti-leech.
BucketWebsite.php Demonstrate how to set/read/clear bucket Static Website.
BucketCors.php Demonstrate how to set/read/clear bucket Cross-original Resource Sharing.

Old version

This version serves as a major version upgrade from 1.*.* versions. Their interfaces are not compatible. We recommend that you use the latest SDK versions. If you still use SDK of Version 2.0.0 or below, download related documentation.

Thank you! We've received your feedback.