I started my first web hosting with Xoom in 90s and then Geocities. They are both free hosting services. Thanks to hosting company like Lunarpages and Exabytes, I able to afford my own cpanel hosting at reasonable fee as low as RM300 annually. I even subscribed for a reseller plan so I can host multiples sites under one WHM. Now, I am more keen to use cloud services such as Heroku, AWS, Azure and Google Hosting. My recent favorite cloud provider is Digital Ocean. I had tried both Heroku and AWS and they are all charge like utilities bill base on usage, which can be very expensive for my free project. Digital Ocean offered fixed price and somehow I feel the vm are more stable than AWS Ec2 although Amazon S3 are still my all time favorite when come to storing static files. With emerging trend like dns cloudflare, baas parse.com, smtp mandrill… it seems that all infrastructure can be provided as service base (IaaS) and programmer can more focus on coding than setting up server.
After finished the online training on EC2, S3, RDS which I already familiar with, I finally received the remaining USD75 credit thru email from amazon. Many thanks! Sum up with the USD25 free credit that obtain by attending AWSome Day KL in cyberjaya, I accumulated a total of USD100 credit. Well, my monthly expenses on AWS is certainly more than this amount but I appreciate this marketing approach. Thanks again to Amazon and I do hope your pricing can keep reducing from time to time as your scale of economy increase.
Amazon S3 is a reliable and affordable cloud storage. When you host a file up there, it is automatically scale-able. Not to confuse with your traditional hosting ftp diskspace, s3 is meant to store static files like images, html, js, css and etc; but not dynamically executed server side code like PHP. In this tutorial, I will teach you how to create a web enabled s3 bucket and how to use PHP code to upload your content onto it. An S3 bucket is a grouping or set of discrete storage container where you can define specific rules and condition. For example, you can create a bucketA which is private while another bucketB which is publicly accessible from the web. You can also create another bucketC which only serve to log access data generated from the bucketB. Be notice that each bucket name have to be globally unique and follow the naming convention here. Your bucket name will also be part of your url if you choose to open the bucket to public. You can have unlimited folders and files inside a bucket. Create a web access bucket Login to your AWS web console, goto S3 section. Click “Create Bucket” button found on the top right of page. On the right is your bucket properties. We will need to make changes to Permissions and Static Web Hosting section. For static web hosting section, note down your end point url. Then click the Enable Website hosting radio button. Do not forget to insert your index document name too. In this case, i just use index.htm. If this file is missing, it will show a 404 File not found HTTP error page. Unlike a convention HTTP server, it wont display a list of other files found in this directory. For Permission section, Click on the Edit Bucket Policy button. Then, insert the code as shown. Remember to change your resource name to match your bucket name. This move is to give right to the public to have read access on your bucket and every files/folders in it. Ok, now you have successfully created your bucket and may test it with the endpoint url. Download Amazon SDK for PHP Next, we will download Amazon SDK for PHP. As amazon update their SDK frequently, the following information might be out-dated. However, the concept would still be the same. Visit http://aws.amazon.com/sdkforphp/ for the download file link. Click ‘AWS SDK for PHP‘. Notice the file downloaded is aws.phar. PHAR is a very nice feature from PHP 5.2 and newer for easy distribution and installation. Writing PHP code to upload file to s3
// replace the $CONFIG['amazonKey'] and $CONFIG['amazonSecret'] to your own
$client = S3Client::factory(array(
'key' => $CONFIG['amazonKey'],
'secret' => $CONFIG['amazonSecret'],
$bucketName = 'yeesiang-test';
$keyName = "hello.txt";
$fileContent = "Hello World"
$result = $client->putObject(array
'Bucket' => $bucketName,
'Key' => $keyName,
'Body' => $fileContent
$uploadSuccess = $client->waitUntilObjectExists(array
'Bucket' => $bucketName,
'Key' => $keyName
echo "upload success!";
echo "upload failed!";
I have been using AWS for years, mainly on EC2 and S3. I am so glad when first heard that AWS is coming to KL Malaysia for the very first time. They also picked a great vanue, Cyberjaya, which is where my office located. So, back to the uni time huhh… I was expecting some onspot lab hands on but it’s more like a general introduction. The lab part will be done online later at my own comfort. Got some sticker as door gift: I will share more about the online lab when I got my login info.