Install the OSS PHP SDK to manage OSS buckets, upload and download files, manage data, or perform image processing. This topic describes multiple ways to install the OSS PHP SDK. You can choose the method that best fits your scenario.
Prerequisites
The OSS PHP SDK requires PHP 5.3 or later. This topic uses PHP 5.6.22 as an example.
Installation environment
Install PHP and the cURL extension:
On Windows, see Compile and use Alibaba Cloud OSS PHP SDK on Windows to install PHP and the cURL extension. If a "module not found" error occurs, set `extension_dir` to
C:/Windows/System32/in the php.ini file.On Ubuntu, you can use the apt-get package manager to install the cURL extension for PHP:
sudo apt-get install php-curl.On CentOS, you can use the yum package manager to install the cURL extension for PHP:
sudo yum install php-curl.
Check versions
Run the
php -vcommand to check the PHP version.Run the
php -mcommand to check whether the cURL extension is installed.
Download the SDK
For more information, see the OSS API documentation.
We recommend that you use the latest version of the SDK. You can download the documentation for OSS PHP SDK versions earlier than 2.0.0 from here.
Install the SDK
You can install the SDK using one of the following methods:
Using Composer
Run the
composer require aliyuncs/oss-sdk-phpcommand in the root directory of your project, or add the following dependency to yourcomposer.jsonfile."require": { "aliyuncs/oss-sdk-php": "~2.4" }Run the
composer installcommand to install the dependencies. After the installation is complete, the directory structure is as follows:. ├── src | └──app.php ├── composer.json ├── composer.lock └── vendorIn this structure,
app.phpis your application file and thevendor/folder contains the dependencies. Add the following line to yourapp.phpfile:require_once __DIR__ . '/../vendor/autoload.php';
NoteIf your project already includes a reference to
autoload.php, you do not need to add it again.If a network error occurs when you use Composer, you can use a Composer mirror for the China region. To do this, run the following command on the command line:
composer config -g repositories.packagist composer http://packagist.phpcomposer.com.
Using a PHAR file
From GitHub, select the required version and download the packaged PHAR file.
Include a reference to the PHAR file in your code:
require_once '/path/to/oss-sdk-php.phar';
Using the source code
From GitHub, select the required version and download the source code package (ZIP file).
The root directory of the unzipped package contains an
autoload.phpfile. Include a reference to this file in your code:require_once '/path/to/oss-sdk/autoload.php';