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:
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).
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.