Tutorial - Using the Windows Azure SDK for PHP
Join the DZone community and get the full member experience.
Join For FreeThis tutorial focuses on obtaining the Windows Azure SDK and a Windows Azure storage account. In all tutorials, the Windows Azure development storage will be used for working with Windows Azure storage services. Development storage is a simulation environment that runs on your local computer and can be used for development purposes. However, it is also possible to work through the tutorials using a production Windows Azure storage account. Both alternatives are described in the next two topics.
Installing Windows Azure development storage
The Windows Azure SDK provides the Windows Azure development storage and additional features which make it easier to build & test applications. The SDK requires a version of Windows 7, Windows Vista Service Pack 1 or greater, or Windows Server 2008 with a version of SQL Server Express or SQL Server installed.
The download for the Windows Azure SDK can be found at http://msdn.microsoft.com/en-us/windowsazure/cc974146.aspx.
After installation, the development storage service can be started through the Start button, All programs, Windows Azure SDK, Development Storage.
Figure 1: Development Storage
The storage service endpoints are listed in the development storage UI:
Access to the storage endpoints is granted based on an account key that you choose and a generated account key. For the development storage environment, the following account is the default one:
Account name: devstoreaccount1
Account key:
Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==
Creating a production Windows Azure storage account
If you choose not to work with development storage, or want to deploy your application to the Windows Azure production environment, the following steps need to be taken:
1. You need a Windows Live ID
2. You need a Windows Azure subscription. The Introductory Special offers plenty of free storage for development purposes.
3. After activating your subscription, navigate to the Windows Azure Developer Portal, click on your Project Name, then on New Service and select Storage Account:
Figure 2: Creating a storage account
4. Provide a Service Label and Description for your storage account and click Next.
Figure 3: Storage account service label
5. After this, a globally unique name for your storage account has to be decided. Also, a Region for your storage service has to be decided: in which datacenter should all data be stored? After specifying the DNS name and Region, click Create.
Figure 4: Specifying DNS name and region
6. The storage account will be created and added to your Windows Azure subscription. All details such as storage endpoints, account name and account key are listed on the details page.
Figure 5: Storage account details
A Windows Azure storage account is structured as follows: every account includes blob storage, table storage and the queue service with specific HTTP(S) endpoints that are listed on the storage account details page:
- http://<account>.blob.core.windows.net
- http:// <account>.table.core.windows.net
- http:// <account>.queue.core.windows.net
The account details for the current storage account are the following:
Account name: mystorageplayground
Account key:
Kd9goKFw/QtP0AFIxxUQ08q9ntgTA5TcUcw5cgE3eOUOBDhBIiE991Q4AK/5PmQiWlYzAlWRf1uqVUnq7/FD4Q==
Obtaining & installing the Windows Azure SDK for PHP
The Windows Azure SDK for PHP focuses on providing a means of interacting with the storage and diagnostic components of Windows Azure by providing an abstraction of the REST operations that are exposed by Windows Azure storage in the form of an easy-to-use PHP class library.
Manual installation
The Windows Azure SDK for PHP can be downloaded from http://phpazure.codeplex.com:
1. Navigate to http://phpazure.codeplex.com and click the Downloads tab.
2. Under Recommended Download, download the file that is listed.
3. Extract the downloaded archive to your hard disk. The unzipped folder structure looks like the following:
Figure 6: Folder structure of extracted Windows Azure SDK for PHP
You may now use the Windows Azure SDK for PHP in your applications.
Installation via PEAR
If you are used to working with PEAR (PHP Extension and Application Repository, more information via http://pear.php.net), you can also install the Windows Azure SDK for PHP through a PEAR channel. The following steps can be taken to discover the Windows Azure for PHP PEAR channel and install the latest Windows Azure SDK for PHP package:
1. Open a PHP console and ensure that PEAR is installed.
2. Register the Windows Azure SDK for PHP PEAR channel by issuing the command pear channel-discover pear.pearplex.net
Figure 7: Registering the Windows Azure for SDK PEAR channel
3. After successful channel registration, install the Windows Azure SDK for PHP by issuing the command pear install pearplex/PHPAzure
Figure 8: Installing the WIndows Azure SDK for PHP PEAR package
4. The Windows Azure SDK for PHP is now installed at <path to PHP>/PEAR/PHPAzure
Additional Resources
Opinions expressed by DZone contributors are their own.
Comments