This topic describes how to install and update the upgraded server operation SDK for
PHP.
Overview
Alibaba Cloud SDK for PHP is a development kit that enables quick access to Alibaba
Cloud services. The
Alibaba Cloud Client for PHP provides underlying support. We recommend that you install the SDK by using Composer.
If you cannot use Composer, you can install the SDK by using a ZIP package.
Note Alibaba Cloud SDK for PHP of the latest version is different from that of the earlier
version in terms of installation and usage. Read the following sections to learn more
about the installation and the usage. For more information, see
Alibaba Cloud SDK for PHP.
Environment requirements
- Requirements
- PHP 5.5.0 or later is installed.
Note
- You can run the
php -v
command to view the current PHP version. If you need to install PHP, visit the PHP official website.
- The PHP version used to install the SDK by using Composer must be equal to or lower
than the actual version of PHP used to run the SDK. For example, if you use PHP 7.2
to install the SDK and generate the vendor directory, you must use the SDK in PHP
7.2 or later. If you use the SDK in PHP 5.6, a compatibility issue occurs.
- Composer is used and the
composer dump-autoload --optimize
command is run.
- If you use a RsaKeyPair client that is supported only on the Alibaba Cloud Japan site,
OpenSSL PHP is enabled.
- Suggestions
- cURL 7.16.2 or later is used.
- OPcache is used.
- Do not use Xdebug in the production environment.
Install the SDK by using Composer (Recommended)
Composer is a dependency manager for PHP. For more information about how to install
Composer, configure autoloading, and follow other best practices for defining dependencies,
visit the Composer page.
- Install dependencies.
- If Composer is installed on your system, run the following command in your project
folder to install Alibaba Cloud SDK for PHP as a dependency: The following sample
code provides an example:
composer require alibabacloud/sdk
After you run the code, a folder named
vendor is generated in the project folder. The following figure shows an example.

If Composer is not installed,
globally install Composer. For Windows users, download and run
Composer-Setup.exe. The following code provides an example:
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
Note If HTTPS is not supported, run the
curl http://getcomposer.org/installer | php
command. For more information, see
Composer Download.
- Run a Composer command to install Alibaba Cloud SDK for PHP of the latest version
as a dependency. The following code provides an example:
composer require alibabacloud/sdk
Note If the installation fails due to network issues, change the address of the Composer
image.
- Add the autoloader to the PHP script. The following sample code provides an example:
<?php
require __DIR__ . '/vendor/autoload.php';
Note To use Alibaba Cloud SDK for PHP in a script, include an autoloader in the script.
Install the SDK by using a ZIP package
If Composer is unavailable, you can download a ZIP package that contains all classes
and dependencies. For more information about how to download the ZIP package, see
the "Server operation SDKs" section of the SDK download topic.
Download the ZIP package, decompress it in the specified folder of the project, and
then include the autoloader in your script. The following sample code provides an
example:
<?php
require __DIR__ . '/vendor/autoload.php';
Update the SDK
If new operations or new features of existing operations are unavailable in the current
SDK version, update the SDK to the latest version. The following sample code provides
an example:
php -d memory_limit=-1 composer.phar require alibabacloud/sdk