- PHP 5.3+ (Run the
php -vcommand to view the current PHP version)
- cURL extension (Run the
php -mcommand to check whether cURL extension has been installed).
- 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.
You can install the SDK with three methods:
- Source code
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
You can also declare the dependency on Alibaba Cloud OSS SDK for PHP in
Install the dependency through
composer install. After the dependency is installed, check whether your directory structure complies with the following structure:
The app.php is a user application. The vendor/ directory contains the dependent library. You need to introduce the dependency in app.php:
require_once __DIR__ . '/vendor/autoload.php';
- If your project references
autoload.php, you do not need to introduce
autoload.phpagain 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
To use the Phar single-file method, you need to select the desired version on the Release Page and download the Phar package.
Introduce the file in your code:
To use the SDK source code method, you need to select the desired version on the Release Page and download the Zip package.
Find the autoload.php file in the root directory of the unzipped package, and introduce the file in your code:
Run the sample project by following the steps below:
Decompress the downloaded SDK package.
Modify the Config.php file in the samples directory.
OSS_ACCESS_ID, which is the AccessKeyID that you obtain from OSS.
OSS_ACCESS_KEY, which is the AccessKeySecret that you obtain from OSS.
OSS_ENDPOINT, which is the access domain name (such as
http://oss-cn-hangzhou.aliyuncs.com) of the OSS data center you have selected.
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.
php RunAll.phpin 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.|
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.