This topic describes how to install Object Storage Service (OSS) SDK for PHP.
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:
- In Windows, you can go to Compile and use Alibaba Cloud OSS PHP SDK in Windows to install PHP and the cURL extension. If a message that indicates the specified
module is unavailable appears, set extension_dir to
C:/Windows/System32/
. - 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.
- In Windows, you can go to Compile and use Alibaba Cloud OSS PHP SDK in Windows to install PHP and the cURL extension. If a message that indicates the specified
module is unavailable appears, set extension_dir to
- PHP version and cURL extension checks
- You can run the
php -v
command to view the current PHP version. - You can run the
php -m
command to check whether the cURL extension is installed.
- You can run the
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
- Go to the root directory of your project and run the
composer require aliyuncs/oss-sdk-php
command or add the following dependency to thecomposer.json
file:"require": { "aliyuncs/oss-sdk-php": "~2.4" }
- Run the
composer install
command to install the dependency. After the dependency is installed, check whether your directory structure complies with the following structure:. ├── app.php ├── composer.json ├── composer.lock └── vendor
In the preceding directory structure,
app.php
indicates your application, and thevendor/
directory contains the dependent library. You need to add the following dependency toapp.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 of OSS SDK for PHP. - 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.
- Go to the root directory of your project and run the
- PHAR
- Select the corresponding version and download the packaged PHAR file from GitHub.
- Import the PHAR file to your code:
require_once '/path/to/oss-sdk-php.phar';
- Source code
- Select the required version and download the ZIP package from GitHub.
- The decompressed root directory contains the
autoload.php
file. Import the file to the code:require_once '/path/to/oss-sdk/autoload.php';