This blog entry is about running PHP in the cloud. Why would you want to run PHP in the cloud?
We will work with our Azure data storage constructs (Blogs, Queues, Tables).
The setup to do all this is very easy. Just follow the steps in this blog and you will get PHP up and running very easily. IIS is one of the first things we’ll configure. IIS is the web server.
When Visual Studio is used to create a PHP project, there will be a couple of configuration options we'll need to set. In order to run PHP in the cloud, we'll need to deploy the PHP runtime up into the cloud. Luckily, that is automatic and is part of the whole configuration process.
The good news is that we can run our project locally before uploading it into the cloud. This is an important feature because you always want to debug your application locally on your computer before uploading it up to the cloud.
PHP can run locally in the Azure development fabric, which acts as an abstraction layer to simulate how your application will ultimately run in the cloud.
FastCGI provides a high-performance alternative to the Common Gateway Interface (CGI), a standard way of interfacing external applications with Web servers that has been supported as part of the IIS feature-set since the very first release.
FastCGI comes into play every time the web server receives a request and will generate a response back to the client browser.
CGI is a protocol for interfacing external applications to web servers. CGI applications run in a separate process, which is created at the start of each request and torn down at the end. This "one new process per request" model makes CGI programs very simple to implement, but limits efficiency and scalability. The operating system process creation and destruction overhead becomes significant and limits scalability.
FastCGI's main aim is to reduce the overhead associated with interfacing the web server and CGI programs, allowing a server to handle more web page requests at once.
IIS (the Apache substitute) is able to overcome the multithreading challenges be re-using CGI processes to service subsequent requests.
In order to run PHP on your local computer, you will need to install FastCGI.
FastCGI runs applications in processes isolated from the core Web server, which provides greater security than APIs, thereby minimizing or eliminating a crashed web server.
By far the easiest way is using the web platform installer. I am running Windows 7 with IIS 7.
Navigate to the web platform installer:
http://www.microsoft.com/web/downloads/platform.aspx
Install PHP as seen below.
It will take only a few minutes.
You can even see that PHP was installed in the “C:\program files” folder. An important file here is the configuration file, php.ini.
This file controls many aspects of PHP's behavior. In order for PHP to read it, it must be named 'php.ini'. PHP looks for it in the current working .
There are some key settings that get setup automatically. You do not need to change them.
Figure: PHP.ini file contents
All these settings have been automatically added, even to “applicationHost.config.”
Also add the PHP_FCGI_MAX_REQUESTS environment variable and set its value to 10000, which is equal to instanceMaxRequests set in the above command.
Since I’m an evangelist and since this may provide some value, I will briefly talk about using Expression Web to create and maintain web sites.
Microsoft Expression Web will be used to test our PHP abilities. You can test your PHP configuration in other ways as well.
From Expression Web, select “New Site"
You will need to configure Expression Web so that it can render your php code.
If the Web Platform Installer succeeded, then you will be able to enter the path below.
Right mouse click to rename.
The dialog box below is Expression Web being really nice, offering to fix all the references to your newly renamed files.
Start by opening “default.php.”
We will change “Heading 2” to “<?php print “php on windows is easy!”; ?>
We are ready to run after making the change below.
Run “default.php” in the browser to work
The final outcome is php running under Windows with little or no fuss.
[more to come…]