(Updated 7 Oct. 2011. Added Option 2.)
If you are someone who is experimenting with PHP on Azure (or even if you have some experience in this area), it is often helpful to have remote access to your running deployments. Remotely accessing deployments can be helpful in debugging problems that might otherwise be very difficult to figure out. In this article, I’ll show you how to configure, deploy, and remotely access a PHP application in Windows Azure.
I’ll assume that you have created a ready-to-deploy Azure/PHP application by following this tutorial: Build and Deploy a Windows Azure PHP Application. (i.e. I’ll assume you have run the scaffolder tool on the default scaffold, you have added your application files to the PhpOnAzure.Web directory, and that you’ve tested your application in the local development environment).
Note: Once you have a ready-to-deploy application, the instructions below apply (it doesn't necessarily have to be a PHP application).
1. Download the encutil.exe. You can download the encutil.exe tool here: http://wastarterkit4java.codeplex.com/releases/view/61026
2. Create a certificate (if you don’t already have one). You can use the encutil.exe to create a self-signed certificate (which is fine for basic testing situations), but using a trusted certificate issued by a certificate authority is the most secure way to go. The following command will create a self-signed certificate in the same directory that the encutil.exe tool is in (you may need to execute this from a command prompt with Administrator privileges):
You should see two files created: phptestcert.cer and phptestcert.pfx.
3. Get the certificate thumbprint. Execute the following command to get your certificate’s thumbprint:
This thumbprint (which you will add to your project’s ServiceConfiguration.cscfg file) must correspond to the certificate you upload to Windows Azure in order for your remote access configuration to be valid.
4. Add certificate thumbprint to ServiceConfiguration.cscfg file. To do this, open the ServiceConfiguration.cscfg file in your PhpOnAzure.Web directory and add the following element as a child of the <Role> element (adding your certificate thumbprint):
5. Encrypt your remote login password. The following command will encrypt the password you will use to remotely login to your Windows Azure instance:
Your encrypted login password will be written to a file (encryptedPwd.txt in the example above) in the same directory that encutil.exe is in.
6. Add remote settings to ServiceConfiguration.cscfg file. Add the elements below as children of the <ConfigurationSettings> element in your ServiceConfiguration.cscfg file. Note that you will need to add values for…
- AccountUserName (the user name you will use to login remotely)
- AccountEncryptedPassword (from the previous step)
- AccountExpirationDate (in the format shown)
7. Add <Import> elements to ServiceDefinition.csdef file. Add the following elements as children to the <Imports> element in your project’s ServiceDefinition.csdef file.
Your ServiceConfiguration.cscfg and ServiceDefinition.csdef files should now look similar to these:
You are now ready to deploy your application to Windows Azure. Follow the instructions in this tutorial to do so, Deploying your first PHP application to Windows Azure, but be sure to add your certificate when you create the deployment:
Browse to the .pfx file you created in step 2 and supply the password that you specified in that step:
When your deployment is in the Ready state, you can access your running Web role via Remote Desktop by selecting your role in the portal and clicking on Connect (at the top of the page):
Clicking on Connect will download an .rdp file which you can open directly (for immediate remote access) or save and use to gain remote access at any later time.
The Windows Azure SDK 1.5 contains tools for creating certificates that enable remote desktop connections. Here's how to use them:
1. Download the Windows Azure SDK 1.5: Download Windows Azure SDK 1.5.
2. Start the Windows Azure SDK Command Prompt with administrator priviliges and execute the following command to create a new certificate:
csencrypt New-PasswordEncryptionCertificate -FriendlyName phptestcert
This will create a certificate in your certificate store with the name phptestcert. See CSEncrypt Command-Line Tool for mor information. You will need to export this certificate. Directions for exporting a certificate can be found in the Creating a Certificate section of this post.
3. To get the thumbprint of the certificate, execute the following command:
This will list information (including the thumbprint) for all the certificates in your certificate store. Find the phptestcert and copy the thumbprint.
4. To encrypt your remote desktop password, execute the following command:
csencrypt encrypt-password -CopyToClipboard -Thumbprint "thumbprint for your certificate"
5. Modify your service configuration and service definition files as detailed in steps 4, 6, and 7 in Option 1 above.
Now you are ready to deploy...follow the instuctions in Option 1 above after step 7.
For more information about the tools available in the Windows Azure SDK 1.5, see the Windows Azure SDK Tools Reference.
That’s it! You now have full access to your running Web role. A couple of things to note:
- Your web root directory is E:\approot.
- As mentioned earlier, remote access to running web roles is primarily for debugging purposes. Any changes you make to a running instance will not be propagated to other instances should you spin more of them up.