May 13, 2011 1

PHP Application Logging On Azure

By admin in PHP Azure

In previous posts I’ve mentioned that once you get an app on Azure it’s often difficult to gain visibility on errors that occur on staging and production. The problem is compounded when (as in my Azure App) you have a number of remote workers processing tasks with little feedback on the results of each task.

To that end I’ve developed a little application to demonstrate using Azure’s blob storage to log events in your application to a blob you can retrieve and view.

The mini Zend Framework application consists of two parts: setting up an instance of Zend_Log and using it to log events and retrieving a list of the events and displaying them on screen.

The demo code is available here: https://github.com/benwaine/Application-Logging-On-Azure

Part One: Set Up

Blob storage is a means of writing files to a permanent cloud storage medium. The Azure cloud storage platform has an API. Using the API users can create containers and blobs. This of containers as folders and blobs of files. There are some differences, for example it’s not possible to nest containers. Although it is possible to using a naming convention to simulate a folder structure within a container.

Microsoft have supplied a comprehensive SDK for the Windows Azure Platform. This makes the task of interfacing with Blob storage a breeze.  The SDK is included in the source of the demo but you can download it and read about it on the projects site on codeplex.

The SDK provides a means of accessing blob storage using streams. Zend_Log supports a number of writing classes, one of which uses writes to streams. The of setting up Zend_Log and Zend_Log_Witter_Stream is accomplished in the applications Bootstrap class.

class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
 
    protected function _initAutoload()
    {
        Microsoft_AutoLoader::Register();
    }
 
    protected function _initBlob()
    {
        $this->getResource('autoload');
 
        $opts = $this->getOption('azure');
        $blob = $opts['blob'];
 
        $storageClient = new Microsoft_WindowsAzure_Storage_Blob(
                        $blob['host'], $blob['acname'], $blob['paccess']);
        $storageClient->registerStreamWrapper('blob');
 
        return $storageClient;
    }
 
    protected function _initLog()
    {
        $opts = $this->getOption('azure');
        $blob = $opts['blob'];
 
        $storageClient = $this->getResource('blob');
 
        if(!$storageClient->containerExists($blob['logs']['container']))
        {
            $storageClient->createContainer($blob['logs']['container']);
        }
 
        if(!$storageClient->blobExists($blob['logs']['container'], $blob['logs']['log']))
        {
            file_put_contents($blob['logs']['stream'], "\n");
        }
 
        $writer = new Zend_Log_Writer_Stream($blob['logs']['stream']);
        $log = new Zend_Log($writer);
 
        $log->info('Logging Initialized');
 
        return $log;
    }
 
}

1) Ensure Zend Framework and the Microsoft Azure SDK are on the include path. (Tip: Add both to the library/ directory in the root directory).

2) Rename the example configuration file in the application/configs directory to ‘application.ini’. Replace the dummy settings with the details of your Azure subscription.

2) In the Bootstrap class we can see that first we add the Microsfot SDK autoloader to the autoloader stack.

3) On line 10 in the _initBlob() method a new instance of the Azure Blog storage client is initialised. It is returned by the method and is stored in Zend_Application’s resource registry for use later.

4) The _initLog() method on line 24 grabs the blob resource from the previous step and uses it to check if both the container and blob specified in the application.ini file actually exist. Note we can see that if the blob isn’t present it must be initialised, otherwise a error is thrown.

5) The Zend log is created and returned. The log is now part of Zend_Application’s resource registry and can be accessed from any action controller or even injected into your domain models to provide richer logging.

Part Two – Retrieving Logs

Retrieving the logs from blob storage is a piece of cake. In this simple application I put all the code in a controller action. It simply opens the file using the storage client set up in the bootstrap process, explodes the string into an array and assigns this to the view.

class IndexController extends Zend_Controller_Action
{
 
    public function init()
    {
        /* Initialize action controller here */
    }
 
    public function indexAction()
    {
        $bootstrap = $this->getInvokeArg('bootstrap');
        $storageClient = $bootstrap->getResource('blob'); /** @var $storageClient Microsoft_WindowsAzure_Storage_Blob **/
 
        $config = $bootstrap->getOption('azure');
        $project = $bootstrap->getOption('project');
        $fileStr =  file_get_contents($config['blob']['logs']['stream']);
        $logAr = explode("\n", $fileStr);
 
        $this->view->projectName = $project['name'];
        $this->view->logs = $logAr;
 
}

1) Options and resources are retrieved from the bootstrap.

2) file_get_contents is used to retrieve the content of the blob.

3) The string from the blob is exploded into an array.

4) Project name and log array are both assigned to the view.

5) In the view script the log array is iterated over and each line of output is echoed.

The result is a page full of log information.

Tips

Azure blob storage is accessed via a RESTful web service. While this is a great tool getting some visibility on what’s happening in your application while it’s on staging there is definitely a performance hit incured by the latency of talking to a remote service.

Even initialising the log incurs a performance penalty as the you can see that a check for both the container and the blob is made in the bootstrap. I recommend using this technique on staging and disabling it when in production.

In the future I’m going to add some ajax support so that the log refreshes in real time, similar to the way in which linux developers  offten use the tail -f command to watch logs during development.

Feel free to use the code and if you have an suggestions please comment.

Tags: , ,

April 2, 2011 0

Launching My PHP Application on Azure: Take Two (Success!)

By admin in PHP Azure

Today I successfully launched v1 of my application on Azure. Yesterday i was feeling quite disheartened and was faced with a difficult problem to solve in order to get my application running in the cloud. Luckily PHP on Windows veteran Juozas Kaziukėnas was around to lend me hand. As he never sleeps we were able to get an answer to my problem at around 3am. Thanks Joe!

The issue: The PHP configuration on on my local development environment included the sqlsrv driver. When using the Windows Azure Command Line Tools to package my application I used the –phpRuntime switch to specify a version of PHP to be shipped to the cloud to run my application on. Unfortunately when tuning the application on Azure Doctrine2 reported the sqlsrv driver missing.

The solution: It turns out the the php.ini Azure was using to run my application on azure contained absolute paths to the extension directory. Joe recommended changing the path to a relative one. I made the following changes to php.ini in both the local version of PHP used by IIS to run my site and also in the php.ini file located in the windows command line tool directory (in my case: “C:\Program Files\WindowsAzureCmdLineTools4PHP\res\php\runtime”). The version in the tools directory should be updated when specifying the –phpRuntime switch when packaging but I wanted to be sure.

extension_dir="c:\Program Files (x86)\PHP\v5.3\ext"

to:

extension_dir="./ext"

A further issue I mentioned yesterday was my inability to adjust the size of the VM used by Azure to host my application. I found the answer to this indirectly on Ben Lobaugh’s blog. In a recent post about customising the ‘ServiceDefinition.csdef’ file used by the command line tools to create an Azure package. In the post he demonstrates how to insert your own values and have them used by the tool to produce the service definition included in the package and used by Azure.

In short you need to edit the ‘ServiceDefinition.csdef’ located in the res directory of the command line tools (in my case: “C:\Program Files\WindowsAzureCmdLineTools4PHP\res\tool”).

The line:

<WebRole name="WebRole">

Changes to:

<WebRole name="WebRole" vmsize="ExtraSmall">

And the VM size is set to ExtraSmall when the package is uploaded to Azure (currently the only size you can run continuously under the free tier).

These two issues where the last ‘blockers’ preventing me from running my application on Azure. In the coming week I need to look into some optimizations:

1) Moving the application library folder onto blob storage

2) Using WinCache with Doctrine to ensure maximum performance

3) Setting up SSL and a domain name for the Azure instance.

I’ll be making it available for public view when i have cleared up the last few bugs surrounding security and API limits.

Tags: , ,

April 2, 2011 1

Launching My PHP Application On Azure: Take One

By admin in PHP Azure

Over the past two weeks I’ve been frantically developing Twitter Sentiment Engine, my entry for the PHP Azure Contest and my university final project. With the functionality for v1.0 nearly complete I thought that it would be a good idea to get the application on Azure. I could then diagnose any platform specific bugs that may occur and have a demo version of the project for others to critique.

That was the plan today at 8am when I started trying to deploy the application. Over the course of the day I hit a number of snags and still haven’t been able to get my application ‘in the cloud’.

My first attempt utilized the steps I outlined in my previous post on how to deploy a Zend Framework application on Azure. Also I previously set up an SQL Azure instance, described here, to use as data storage for the application.

To summarise, I fired up the Azure CL Tool, pointed it at my application and waited while the tool packaged my application ready for uploading to azure. I also selected the option to run the application on the Dev Fabric so I could test the app before uploading it. The tool built the App and it ran fine on DevFabric. I expected in a few minuets time to have a fully functional application on Azure staging however I encountered my first issue shortly after uploading the package using the Azure management portal.

After the package uploaded and the web role was started successfully I went to the index page of my application. The holding page I had created displayed correctly. However on trying to access any of the api URLS a generic IIS7 500 custom error page was displayed. These pages are deliberately vague and offer no information as to what the error condition is. Great for production, terrible for me right now!

On a traditional development I would log into the box serving the application and review the error logs however I could not find a mechanism for doing this in the context of Azure. Instead I decided to view errors on screen, this would mean having to remove the custom error page and get at the underlying PHP error.

Removing Custom Error Pages On Azure Using web.config

1) Open your web.config file (usually located in projects source directory or the route of the site.

2) Add the line <httpErrors errorMode=”Detailed” /> within the <system.webServer> tags

3) Re-upload your project to Azure

After applying the changes above and re uploading the application to Azure I was able to see the real cause of the problem. Doctrine2 was unable to locate the sqlsrv driver for php. In order to verify that the driver wasn’t loaded I appended a phpinfo() call to the error page Zend Framework serves in the event of an application error. Unfortunately this involved another packaging and re-uploading of the whole application (including libraries). A process which I clock at between 30 – 40 min including packaging and uploading.

The phpinfo confirmed that the module was not loaded (no pdo modules were). This suprised me as it was my understanding that when you ran the packaging tool and specified the location of your PHP run time it to was uploaded to Azure also. I also checked the php.ini file in the Web_Role folder generated by the packaging tools. At the bottom of file listed with all the other extensions was ‘extension=php_pdo_sqlsrv_53_nts_vc9.dll’.

At present this is the bug that is holding me back from launch. Up to know the Microsoft team have been really supportive. I hope they can help again as I’d really like to get application in the cloud asap! If any one has ideas or thinks they could help please comment.

Platform Evaluation

My first experience in actually launching a full application on Azure hasn’t been very successful. I have some critique and questions:

1) Packaging and uploading my application takes roughly 30-40 min. In this debugging stage this puts an unacceptable amount of time between the opportunities to try fixes to the problems I’m encountering. I’ve been told it’s possible to move libraries to blob storage but haven’t yet been able to fond a good tutorial illustrating this.

2) I cant find a good tutorial outlining how to set up access to the PHP error log.

3) A related issue: I’m trying to launch my application on a Extra-Small compute instance. Ive followed the instructions here and altered the service definition file in the source directory of my project. When uploading this to Azure though I notice the instance is still given as ’small’. I’d like to utilize the 750 hours of ExtraSmall compute on offer.

Tags: ,

April 1, 2011 0

Creating And Using An SQL Azure Database

By admin in PHP Azure

In preparation for the launch of my project on the Azure platform I created a new Azure Database Server Instance and a database to host the data for my application. The whole process went smoothly and within 5 minutes I had a functioning database with test data. Hats off to Microsoft for this, SQLAzure is really slick.

The process is pretty simple, I’ve putlined the steps below:

Creating A Database Server Instance on Azure

1) Log into the Windows Azure Managment Portal

2) Click the ‘Database’ icon (bottom of the left hand panel)

4) Select your Azure subscription from the drop down and click OK.

5) Select a Region for your database server to reside in. Click OK.

6) Create a Username and password for your database server.

7) You need to specify firewall rules in this step. I opted to let other Azure Services have access and also the IP of my own internet connection. Click Finish.

8) You should now have a database server listed under the subscription you selected in step 4.

When expanding the newly created server instance you’ll notice that a database has already been created for you called ‘master’. This is a database used by the sytem for its own administrative processes. It is NOT billable and casual users should probably leave it alone. In order to use the newly created server instance you need to create a new database.

Creating A New Database On A Server Instance

1) Select the blue ‘Create’ icon from the task bar at the top of the screen

2) Enter a name for your database.

3) Databases come in a range of sizes. The Azure free tier currently allows you to have 1 free web edition 1GB database free for three months. I selected these options and clicked OK.

Links

SQL Azure Home Page

Tags: , ,

March 19, 2011 0

Utilizing all HTTP Verbs on IIS7 with PHP

By admin in PHP Azure

When building the API for Twitter Sentiment Engine it quickly became obvious that out the box IIS7 only accepts requests for certain HTTP Verbs (GET / POST). When using the REST Client to PUT on a resource i got the message ‘405 METHOD NOT IMPLEMENTED’. After googling round I found you need to some settings on PHP’s handler in the IIS Manager Screen.

1) Open IIS Manager.
2) Select the site you with to edit.
3) Click ‘Handler Mappings’
4) Right Click the mappig for PHP (mine is called PHP53_via_FastCGI), choose edit.
5) Click ‘Request Restrictions’
6) Select the ‘Verbs’ tab.
7) Select ‘All Verbs’ option. Click OK until you are back to IIS Manager.

Requests using the PUT and DELETE verbs should hit your PHP scripts.

Tags: ,

March 15, 2011 4

Twitter Sentiment Engine: A Proper Introduction

By admin in PHP Azure

Over the course of the past few weeks I have been so tied up in the working on a  new technology stack that I haven’t formely introduced my PHPAzureContest (and university disertation project) ‘Twitter Sentiment Engine.’

Today I took an hour or two  to catch up on some of the written side of this project and put togethert an introduction, rational, requirments and draft functional spec. I say ‘draft’ as at the moment the specification is more than a little vauge.  In the next week (when I drag myself away from Azure) I’m going to fill this out more.

Twitter Sentiment Introduction And Rational

Twitter Sentiment Engine (TSE) is a tool for analysing the way people feel towards an event, brand or product on the social network Twitter. Twitter is one of the fastest growing social networks around the world. Users make status updates (tweets) about a variety of subjects. There is a clear commercial rationale for this product for companies who wish to answer the question “How are we perceived right now?” Answering this question would help companies quickly respond to emerging trends on this fast paced and influential social network.

The aim of this project is to deliver a working prototype of TSE. It should accept a keyword or keywords, gather a sample of positive and negative tweets about the keyword and use this sample to produce a filter that can monitor sentiment on an on going basis. The tool may initially consist of a reporting website but a key objective is that is should expose an API that lets developers access the product and integrate it with their own social media monitoring solutions. A secondary objective of this project is that TSE should be a highly scalable solution. It should be able to expand it’s processing power and throughput by adding more hardware to the solution.

Twitter Sentiment Engine Requirements Document

The product will be capable of inferring sentiment (positive or negative) on a Tweet.

The product will be capable of tracking keywords or terms on Twitter.

Tracked terms should have regular sentiment statistics available for them (ie, What do people feel about this tracked term now).

Sentiment history should be available for tracked terms.

The product should be capable of serving numerous endpoints / end applications.

The product should provide a means of authentication for the end points.

Tracking and the NLP processing should occur ‘off request’ / asynchronously.

Twitter Sentiment Engine Functional Specification (draft)

Section One: Sentiment Detection / Natural Language Processing

The product will make use of the naïve Bayes filtering technique to infer sentiment on tweets.

Process Outline:

  1. A training corpus is created. The corpus consists of an equal sample of positive and negative Tweets.
    1. Every Tweet in the corpus is ‘normalised’. Punctuation is removed, letters are lower cased.
    2. Each tweet is split into its component words.
    3. For each sample class (+tive / -tive) the instances of words are counted and recorded.
  2. Tweets are gathered from the Twitter API and classified.
    1. Every tweet undergoes the same normalisation process as in the training corpus.
    2. Tweets are split into the component words. Bayes formula is used to determine the probability that a word is either positive or negative.
    3. Providing that the probability for either +tive / -tive exceeds a given certainty threshold the tweet is classified by the greater possibility +tive / -tive.

Training Corpus:

Reid(2005) describes the process of using a ‘noisy indicator’ to broadly cast a sample into one of a number of possible classes. He used the example of the presence of a smiley face glyph in small text samples to broadly infer the authors sentiment / feelings. This processes will be used in TSE to gather sample data from the twitter api.

  1. The Twitter search API will be used to gather tweets with the tracked term and a smiley face glyph.
  2. Positive Glyphs are: :-) :)
  3. Negative Glyphs are: :-( :-(
  4. Tweets with more that one glyph are discarded (as this may symbolise conflicting sentiment or irony).
  5. The sample should be as large as possible. Twitter currently supports a sample of 1500 tweets per search term. Two search terms are used totalling a sample size of 3000 tweets.
  6. The training corpus will be persisted using a database.
  7. A term may have more than one training corpus associated with it (in the case of a retraining).

Ongoing Classification:

  1. The Twitter API will be used to query for Tweets with the search term used to in the training corpus on a regular basis.
  2. The persisted training corpus will be used to calculate the sentiment of tweets as described above.

Section Two: API & Infrastructure

The product will have an internal and external API. The external API will deal with tracking requests, sentiment statistics data requests. The internal API will expose an event based queuing system used by worker nodes to process the sample gathering and sentiment processing jobs.

Webservice Diagram

Public REST API

The public REST API accepts tracking requests from authorized web clients. It also provides statistics on tracked terms. The public API utilises the AtomPub protocol for publishing data about the tracked terms. The service is hypermedia driven:

  1. A single AtomPub workspace exists containing the category ‘tracking’.
  2. An AtomPub feed provides hyper media links to entries which represent tracked terms.
  3. Tracked term entries contain links to a paginated resource representing the historical data help on that entity.
  4. The API will provide a search resource to obtain specific tracked item entries.
  5. Authentication is achieved using AuthBasic over SSL utilising API keys.

Internal REST API

  1. The internal API exposes a single workspace containing the category ‘tracking’.
  2. An AtomPub feed provides hypermedia links to <app> draft entities representing unfulfilled tracking requests. Workers monitor the feed and fulfil the jobs represented by each entry. Concurrency is managed using HTTP cache control headers and etags which are checked before a resource is PUT back to the service on job fulfilment.
  3. A similar feed is exposed to marshal the Sentiment statistics gathering jobs.
  4. Authentication is achieved using Auth Basic over SSL using API keys. IP based blocking should also be in place.

Tags: , , ,

March 9, 2011 2

Deploying A Zend Framework Application To App Fabric

By admin in PHP Azure

In my previous post I mentioned I’d completed a few of the Windows Azure: Getting Started tutorials. The tutorials are ok as far as they go (displaying a single page) but when I tried launching my ZendFramework application to Azure I encountered a few issues.

1) Creating web.config

2) Getting URL Re-Writing to work

This post describes the process I went through to get my Basic application in the cloud. I am assuming some familiartiy with the tools which can be gained by completing “Deploy Your First Application With Windows Azure CLI Tools for PHP ” and “Deploying Your First PHP Application To Windows Azure“.

Application Structure

My application structre follows the standard structure created by Zend_Tool shown bellow.

SentimentEngine
-application
--models
--controllers
--views
-modules
--api
---controllers
---models
---views
-library
-public
--img
--css
--js

Considerations

Zend Framework requires all requests (apart from requests on files eg, img, js,css) to be routed through index.php in the public folder. The application is then bootstrapped and the response served by the aplication.

The Zend Framework library needs to be included.

Before following the steps bellow the project did not have a web.config or webrole.config, these are files used by Azure to deploy your application. The steps bellow will ensure you have the required files before deploying.

Using The Windows Azure Command Line Tool For PHP

The CLI Tools allow you to launch your project on Dev Fabric (a local staging version of App Fabric). I found the documentation of the tool to be a little light on the options and combinations of options required to launch a more complex application. So I’ll walk through the process step by step:

1) Open the SDK CLI as administrator (START > All Programms > Windows Azure SDK v1.3> Windows Azure  SDK Command Prompt)

2) Navigate to C:\Program Files\WindowsAzureCmdLineTools4PHP (or wherever you installed to tool to).

3) Ensure the package.php script is working. Execute php package.php –help. If it is not go back to the tutorials above and trouble shoot.

4) I used the following command to deploy my application (lines added for clarity):

>> C:\Program Files\WindowsAzureCmdLineTools4PHP>php package.php
–project=”TSE”
–source=”c:\Users\Ben\Documents\NetbeansProjects\SentimentEngine\Sentiment-Engine” –defaultDoc=”public/index.php”
–phpRuntime=”c:\PHP\v5.3″
–cleanRebuild
–runDevFabric

Project: Name of project. At first I encountered an error when using the name “TwitterSentimentEngine”. I tracked this down to be the size of the file names and paths generated by the tool where to long. I suggest using an abbrieviation like TSE to keep filenames nice and short.

Source: This should contain the entire application. “SentimentEngine” in the folder layout above.

DefaultDoc: It is important to specify this when deploying an application with a more complex structure (in this case a public directory with application and library folder above the web root). The path is relative to the source directory specified above.

PHPRuntime: This is the directory where php.exe is located on your system.

CleanRebuild: Wipes previous versions of your app off the system while building the project.

RunDevFabric: Runs the application on the dev fabric after a sucessfull build.

At this point your application’s front page should appear in the browser however you’ll notice when you try and navigate away from the front page you will get a 404. This is becuase URL Re-Writing has not been configured.

Configure URL Re-Write

The URL Re-Write module is made available by default the Azure SDK ver 1.3 and above. However in order to make it work a customised web.config is required. At this point you won’t have a web.config in your projects source code, however one was generated by the build process when you built the application.

1) Navigate to C:\Users\<USERNAME>\AppData\Local\Temp\WACmdLineTools\<PROJECT_NAME>_Build\<PROJECT_NAME>_WebRole

2) Copy web.config and web.roleconfig and paste them into the project folder (in the case the folder “SentimentEngine” above).

3) The next step is to add a Re-Write rule to the web.config file. Juozas was nice enough to provide me with the required rule. It should be inserted into the web.config like so. Do note delete any other content from this file.

web.config

Note To Self: Get a code formatting and display plugin!!

The URL attribute of the <action> tag should match the defaultDocument used in the command to build you application on the CLI.

4) Repeat the build process outlined above. The tool will now use the web.config we just created. When the Dev Fabric is launched the application should redirect to the index page correctly, you should be able to navigate through all it’s pages.

5) Finally launch the application to the Application Fabric using the Windows Azure Development Portal as described in the second tutorial above.

Evaluation Of The Platform

Pros

  • The Azure CLI Tool worked well. On most occasions it outputted high quality error messages (that gave me the information I needed to solve the issues).  Although there were a few exceptions for example when the xml in the web.config was malformed.
  • The Devfabric is like a personal cloud. I haven’t yet taped all its potential but being able to test an entire infrastructure on a developers machine is an excellent idea.

Cons

  • The documentation for the tool accurelty describes how to get a really simple cloud application up and running. I wasn’t able to find documentation covering more complex app structures.
  • As someone who deploys on apache and is used to editing .htaccess files the URL Re-Write module and the web.config approach is an entirley new product to me. Including specific examples on how to get this product up and running with the PHP CLI tools would really benefit me and other users getting their framework apps on Azure.

Summary

Although it took me a while to get my simple app on to Azure I’m now convinced that I’ll be able to deploy to the platform consitently in the future. In the coming weeks as the application matures I’ll need to add support for SQL Azure and also move the Zend Framework Library over to blob storage to reduce the build time of the aplication.

Tags: , ,

March 2, 2011 1

Setting Up A Local Microsoft Development Environment

By admin in PHP Azure

Over the past two weeks I’ve been busy creating the bare bones of my disertation project. This included creating a process to query the Twitter Streaming API, a process to create sample from the results and building a Bayes Classifier. Early on in the project I made the descision to launch the platform using Azure. Azure provides a local staging area called ‘The Development Fabric’ to test your application. Building to the Dev Fabric can take anything between 30 seconds to 1 min and is a little too slow when a project is in it’s infancy and requires constant adjustment. It seems logical then to install  a similar technology stack to carry out local development.

Enter PHP on IIS with MSSQL Server. Thats a bit of a mouthfull and as the PHP comunity (and everyone else in tech) loves achronims I’ll here on refer to it as PIMS.

Setting the stack up was a largley painless process aided by the Web Platform Installer but I did have some difficulty in making MSSQL Server accessable to my PHP application.

Setting Up PHP on IIS

Install the following products using the webplatform installer:

IIS 7

PHP Manager For IIS 7

PHP 5.3.5 (If you previously installed PHP Azure CLI Tools this has been installed as a dependancy).

IIS runs PHP as a FastCGI process – if installed using the WebPI this process is set up to fire when PHP files are run on IIS. If you need to set up the process manually This Video is a really great help and guides you through the steps required.

Setting Up A Site On IIS

IIS is capable of serving multiple sites off one server instance. I set up a site for my project using the following steps:

1) Open up IIS Manager.

2) Click on the Sites (left hand column)

3) Click Add Web Site (right hand column)

4) On the following screen give your site a name and enter the physical path to it (eg: c:\users\ben.waine\sites\project\public).

5) Enter the sites URL (remembering to add the URL of your choice to your hosts file)

6) Click OK.

7) Go to the parent folder of your project. (eg: c:\users\ben.waine\sites\project – one level up from the web root).

8) Right click the folder, select properties and move to the Security tab.

9) Under the Group or Usernames section click Edit.

10) Click ADD

11) Enter IIS_IUSRS and click the Check Names button the click OK.

12) Add the permisions: Read | Write | Read & Execute. Click OK unil there are no windows left.

13) Add a test page or phpinfo to the physical path you specfied in step 4.

14) Open your browser and navigate to the URL you specified in step 5.

15) You should see your test page.

Setting UP MSSQL Including Remote Access

Install the following packages using WebPI:

SQL Server 2008 Express

SQL Server Managment Studio Express

After the the installation is complete check and see if SQL Server is running. You can do this by right clicking on the computer icon in the start menu and selecting manage. Then click ‘Services and Applications’ followed by ‘Services’. Look down the list for SQL SERVER (SQL EXPRESS). It’s state should be ‘Started’ if not, hit ‘More Actions’ > ‘Start’ on the right hand side of the screen.

You should now be able to log into SQL Server via the SQLSRV Managment Studio. The default authentication type is ‘Windows Authentication’. Use this and press ‘Connect’.

Create a database for your project. Expand the ‘localhost\sqlexpress’ icon and then the ‘Database’ icon.  Right click and select ‘Add New Database….’.

In order to make the database accessable to a PHP application you need to do two things:

Create a new database login

Within ‘localhost\sqlexpress’  tab expand the ‘Security’ tab and then the ‘Logins’ tab. Right click the ‘Logins’ tab  and select ‘New Login..’. Add a login name and select the SQL server authentication option. Add and confirm a password and select a password policy. Ensure the default database matches the one you previously set up.

Add The Login to Your Database

Expand the tab of the database previously selected. Expand the security tab. Right click on Users and ‘Add new User..’. Enter a name and search for the login you previously created. Give the user the role ‘db_owner’, this should provide sufficient privilages for development use.

Disconnect from the server (left hand menu – icon with the red cross in it).

Reconnect with the user you created to ensure it works.

Remote connections to the database from PHP using PDOSQLSRV should now be possible.

Your PIMS stack should now be complete! Enjoy working on the Microsoft stack.

Tags: , , ,

February 12, 2011 2

First Steps with PHP on Windows Azure

By admin in PHP Azure

Today I put some time aside to work through the various tutorials recommended by the PHP on Azure contest team.

The tutorials I used:

Getting the PHP Windows Azure Prerequisites

Deploying Your First PHP Application with the Windows Azure Command Line Tools for PHP

Deploying Your First PHP Application to Windows Azure

Cover the following steps:

1) Sign up for a Windows Azure Free account. http://tinyurl.com/freeazureaccount

2) Install the Azure PHP SDK using the web platform installer.

3) Install the Azure PHP command line tools from codeplex.

4) Deploy a test page to the local development cloud.

5) Deploy the test page to Windows Azure.

I worked through the tutorials with relative ease and managed to produce the following screen shot at the end:

Image of my first encounter with Windows Azure

A summary of the Good and bad points:

Good

The Web platform installer is made of awesome. It is like a visual version of aptitude for the windows platform. It manages all the dependencies required to install a set of tools.  When I needed to install the Windows Azure PHP tools it also took care of all the IIS configuration, downloading and installing PHP and installing SQL server. It did this quickly and flawlessly.

The Windows Azure command line tools for PHP are also very good. Packaging an existing application or a new application is achieved with a few lines on the command line.

The Bad

The free Windows Azure package comes with a tiny 25 hours of run time (per month) before you start paying for the service. When you compare this to Amazons Free Tier which comes with enough hours to  run an instance  continuously for a month you are left feeling short changed. I think Microsoft need to expand their free usage to this level before developers will consider testing PHP on Azure over other Linux based cloud providers.

Some screens on the Azure control panel where quite suseptable to time outs.

Deploying a one page application did take some time (roughly 15 min of various ‘loading’ screens).

Things I Need To Research

The deployment process packages up all the files needed to run your application into a deployment. The deployment is then uploaded to Azure and you can install it on staging then move it into production. This is all very well when creating a test application with one page. However my real application will utilize Zend Framework and Doctrine. I don’t want to upload these to Azure every time I deploy. There must be some way to set up the libraries on Azure so I can just upload application files.

My application will likely utilise tools like memchache and PHPeanstalk. I need to investigate support for these tools on Azure. In the instance that they aren’t supported (particularly likely in the case of memcache) I need to look at integrating an Azure instance with some linux ones.

Tags: , ,

February 10, 2011 1

PHP Azure Contest

By admin in PHP Azure

I’m pleased to announce I have just signed up to Microsoft’s PHP Azure contest. I’m currently writing a PHP application as part of my university final project. The project was announced at PHPBNL11 with the slogan ‘Your application in the cloud and your ass in Vegas!’ The Microsoft key note illustrated some of the benefits of the Azure platform and how easy it is to deploy PHP applications on it.

The application itself is a sentiment analysis and reporting tool based around Twitter. The tool will perform sentiment analysis on tweets about brands, products and events.  The project is built on Zend Framework and Doctrine and will implement sentiment analysis algorithms like Nieve Bayes, SVM and discriminant algorithms to classify tweets into positive and negative categories. I’d like to create some cool visualizes to display this data on the front end.

I’m looking forward to implementing PHP on Windows. I’ll be blogging about my experiences along the way and open sourcing some of the text classification code as I write it. Possibly one of the most interesting elements of this project will be trying out the new Doctrine2 support for SQL Azure.

The next step is to sign up for all the relevant tools and try and push some test code up to Azure!

You can get started with Azure by going to http://www.microsoft.com/windowsazure/offers/ and with the competition at http://www.phpazurecontest.com/

Tags: , ,