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.
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:. ├── src | └── 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';
NoteIf
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
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.
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';