This topic describes how to install STS SDK for PHP and provides an example about how to use STS SDK for PHP.

Background information

  • Alibaba Cloud provides OpenAPI Explorer to simplify API usage. You can use OpenAPI Explorer to debug API operations and dynamically generate SDK sample code.
  • For information about STS API operations, see What is STS?
  • For information about endpoints to access STS, see Endpoints.

Install the SDK for PHP

For information about how to install the SDK for PHP, see Quick start.

You can download the installation packages of the SDK for PHP from the following links:


The following sample code shows how to call the AssumeRole API operation by using the SDK for PHP. You can use OpenAPI Explorer to debug other API operations and obtain sample code.

use AlibabaCloud\Client\AlibabaCloud;
use AlibabaCloud\Client\Exception\ClientException;
use AlibabaCloud\Client\Exception\ServerException;

// Construct an Alibaba Cloud client to initiate requests.
// When you construct the client, specify your AccessKey ID and AccessKey secret.
AlibabaCloud::accessKeyClient('<accessKeyId>', '<accessSecret>')
// Specify request parameters and initiate a request.
try {
    $result = AlibabaCloud::rpc()
                          // ->scheme('https') // https | http
                                        'query' => [
                                          'RegionId' => "cn-hangzhou",
                                          'RoleArn' => "<RoleArn>",
                                          'RoleSessionName' => "<RoleSessionName>",
} catch (ClientException $e) {
    echo $e->getErrorMessage() . PHP_EOL;
} catch (ServerException $e) {
    echo $e->getErrorMessage() . PHP_EOL;