PHP and Windows Azure Blob Storage
Do You Know About OneDrive, Dropbox, Google Drive, and Box?
If you search for those names on your favorite search engine, you’ll find that they can all be categorized as cloud-based storage services. You can use these services for free, while some also offer paid plans.
For application developers, an important question arises: what if developers want to create an application that allows users to upload content (images, text, videos, etc.), and that content is stored on one of these cloud services? The answer is—yes, it’s definitely possible!
In December 2010 (correct me if I'm wrong), Microsoft launched a cloud platform called Windows Azure. Azure provides several features, including Virtual Machines, Data Management, Business Analytics, Mobile Services, and many more. To answer the previous question, Microsoft offers a service called Azure Blob Storage, which can store up to 500TB of data (source). So, how can we utilize Azure Blob Storage in a web application we develop?
In this blog post, I will discuss how to configure PHP and Azure so that they can communicate with each other. I will divide the discussion into two parts: PHP and Azure Blob Storage.
PHP
I believe PHP is already familiar to most web developers since it is a widely used programming language. PHP is a server-side programming language commonly used in web application development. You can learn more about PHP at php.net.
Azure Blob Storage
Now, let’s move on to Azure Blob Storage. This is a cloud-based storage service provided by Windows Azure. As the name suggests, "Blob" stands for "Binary Large Object", which means it can store text files, media files (such as images and audio), and even application installers.
Currently, Azure Storage hosts trillions of objects and handles millions of requests per second. With Azure Blob Storage, you don’t have to worry about how much storage space you need to prepare on your own server. You can read more about Azure Storage here.
Below is a tutorial on how to use Azure Blob Storage with PHP.
Configuring Azure Blob Storage on Windows Azure
-
Log in to your Windows Azure account, then select Storage Items and click New.
-
Enter a storage name in the URL field so that your Azure Blob can be accessed through a URL in the following format:
Configuring PHP
-
Install the PEAR package manager by downloading the file from: PEAR.
-
Save the go-pear.phar file in the PHP root directory. Open Command Prompt and type: php go-pear.phar
-
Follow the instructions until you are prompted to update the php.ini file.
-
Ensure the process is completed successfully, then restart your PHP service.
-
You need to install HTTP_Request2-2.2.1 and Mail_Mime-1.8.9 on your PHP service, as Azure Blob Storage requires them to function properly. Wait until the installation is finished.
-
Download the required PHP libraries from: Azure SDK for PHP Samples. This repository also provides usage examples.
-
Open the storage folder in the root directory, then modify the BlockBlobExample.php or PageBlobExample.php file to match your Azure Blob Storage account configuration.
Source: http://azure.microsoft.com/en-us/documentation/articles/storage-php-how-to-use-blobs/