Web Sites Series: Create PHP and MySQL sites with Windows Azure Web Sites and WebMatrix

The newly introduced Windows Azure Web Sites and latest release of Microsoft WebMatrix provide a great way to create and host PHP + MySQL sites. You can write your own or get started with one of the popular open source applications that run in Windows Azure, such as Drupal, Joomla! or WordPress.

This post covers how to create a site in Windows Azure, download and customize it, then deploy back to Windows Azure Web Sites. We will be using WebMatrix, a free, lightweight web development tool. We’ll look at some of the new capabilities in WebMatrix that make writing sites easier and new features in the Windows Azure portal.

Create a new Web Site

With the release of Windows Azure Web Sites, you can create a new website in the portal in minutes. After signing up for a free trial, you have the option of creating an empty site without a database, with a database or install an open source application automatically.

While you can create an empty site with a database and then publish a site to it, we’re going to start by using the gallery.

For those of you familiar with the Web Platform Installer, you will recognize some of the same popular applications, specifically ones that have been tested on Windows Azure.

I want to build a content management based site; I will use Acquia Drupal as an example. When you choose an application, enter a site name and choose the database.

You can customize the database name and choose the region. Be sure to choose the same region as the site for best performance. You will have to configure a username and password for MySQL if you haven’t already.

 

Progress is displayed in the command bar area at the bottom of the portal. When site creation and installation of the app is complete, the notification may include a link to finish configuration. Click Setup to finish Acquia Drupal’s installation in the browser.

In the browser, most of the fields have been pre-filled in. Just type your MySQL password and continue.

After you have completed Acquia Drupal’s browser install, you can now login and customize your site!

Download and customize a Web Site in WebMatrix

When you’re ready to start making changes, you can download the site to your computer to edit offline. Downloading is useful if you don’t want to break your site running in production, or you want a rich editing experience with PHP code completion, colorization and other editing features.

We’ll start by navigating to the site in the portal and clicking the WebMatrix button in the command bar.

If WebMatrix is not already installed, you will be prompted to install WebPI and WebMatrix, along with any pre-requisites that are needed on your machine. Once it completes, WebMatrix will launch and automatically begin downloading your site.

Since you are running an application from the Web Application Gallery, WebMatrix will automatically install dependencies and make any changes needed so that the application runs locally.

Enter the database administrator password when prompted. Any required dependencies, such as MySQL or PHP, will be listed.

The final steps of the wizard will download the database and make any configuration changes needed for the site to run locally.

After the wizard completes, you will see the Site dashboard with helpful getting started links provided by Acquia Drupal. WebMatrix is split into four workspaces, Site, Files, Database and Reports.

Since we’re customizing the site, let’s go to the Files workspace. We’ll start by adding a custom module, learning from a Drupal tutorial. Notice the Drupal specific code completion that appears, allowing us to learn about and quickly use Drupal functions.

You can change the theme, install new modules and more using the Acquia Drupal control panel in the browser by clicking Run in the ribbon.

 

Deploy the Web Site

Once you’ve customized the local version, you can publish it back to your live site. Simply click the Publish button in the ribbon.

You’ll be able to preview the files. Check the database in order to publish changes.

Note: Publishing the database will replace your remote database with the local one. If you have data in the remote database that you don’t want to overwrite, you should skip publishing the database.

Once publishing completes, you can browse to your remote site.

If you need to quickly make a change to the remote site, such as changing a configuration setting that is only applicable on the remote server, this is easy to do – select the Remote tab and then Open Remote View in the ribbon.

Create a Custom Web Site

If you prefer to create your own sites from scratch, you can use the built-in templates. Follow the steps in this article on the Windows Azure development center.

Summary

This post covered how Windows Azure Web Sites and WebMatrix make it easier to get started with open source web applications, or create your own custom site.

Please share your feedback on the post, the features discussed or new topics you’d like to see us cover.

– by Faith Allington, Sr. Program Manager, Windows Azure