Free trial *Internet Service Required

How to configure PHP in Windows Azure Web Sites

This guide will show you how to configure the built-in PHP runtime in Windows Azure Web Sites, provide a custom PHP runtime, and enable extensions in Windows Azure Web Sites. To use Windows Azure Web Sites, sign up for the free trial. To get the most from this guide, you should first create a PHP site in Windows Azure Web Sites (see the PHP Developer Center Tutorials). For general information on configuring sites in Windows Azure Web Sites, see How to Configure Web Sites.

Table of Contents

What is Windows Azure Web Sites?

Windows Azure Web Sites allows you to build highly scalable web sites on Windows Azure. You can quickly and easily deploy sites to a highly scalable cloud environment that allows you to start small and scale as traffic grows. Windows Azure Web Sites uses the languages and open source apps of your choice and supports deployment with Git, FTP, and TFS. You can easily integrate other services like MySQL, SQL Database, Caching, CDN, and Storage.

How to: Change the built-in PHP configuration

By default, PHP 5.3 is installed and immediately available for use when you create a Windows Azure Web Site. The best way to see the available release revision, its default configuration, and the enabled extensions is to deploy a script that calls phpinfo().

PHP 5.4 is also available, but not enabled by default. To enable it, follow these steps:

  1. Browse to your web site's dashboard in the Windows Azure Portal, click on CONFIGURE.

    Configure tab on Web Sites dashboard

  2. Click PHP 5.4.

    Select PHP version

  3. Click SAVE at the bottom of the page.

    Save configuration settings

For either of the built-in PHP runtimes, you can change any of the configuration options that are not system-level-only directives by following the steps below. (For information about system-level-only directives, see List of php.ini directives.)

  1. Add a .user.ini file to your root directory.
  2. Add configuration settings to the .user.ini file using the same syntax you would use in a php.ini file. For example, if you wanted to turn the display_errors setting on and set upload_max_filesize setting to 10 MB, your .user.ini file would contain this text:

    ; Example Settings
    display_errors=On
    upload_max_filesize=10M
  3. Deploy your application.

  4. Restart your web site. (Restarting is necessary because the frequency with which PHP reads .user.ini files is governed by the user_ini.cache_ttl setting, which is a system level setting and is 300 seconds (5 minutes) by default. Restarting the site forces PHP to read the new settings in the .user.ini file.)

As an alternative to using a .user.ini file, you can use the ini_set() function in scripts to set configuration options that are not system-level directives.

How to: Enable extensions in the default PHP runtime

As noted in the previous section, the best way to see the default PHP version, its default configuration, and the enabled extensions is to deploy a script that calls phpinfo(). To enable additional extensions, follow the steps below.

  1. Add a bin directory to your root directoy.
  2. Put .dll extension files in the bin directory (for example, php_mongo.dll). Make sure that the extensions are compatible with default version of PHP (which is, as of this writing, PHP 5.3) and are VC9 and non-thread-safe (nts) compatible.
  3. Deploy your application.
  4. Navigate to your site’s dashboard in the Windows Azure Portal, and click on CONFIGURE.

    Configure tab on Web Sites dashboard

  5. In the app settings section, create a key PHP_EXTENSIONS and a value bin\your-ext-file. To enable multiple extensions, incude a comma-separated list of .dll files.

    Enable extension in app settings

  6. Click SAVE at the bottom of the page.

    Save configuration settings

How to: Use a custom PHP runtime

Instead of the default PHP runtime, Windows Azure Web Sites can use a PHP runtime that you provide to execute PHP scripts. The runtime that you provide can be configured by a php.ini file that you also provide. To use a custom PHP runtime in Windows Azure Web Sites, follow the steps below.

  1. Obtain a non-thread-safe, VC9 compatible version of PHP for Windows. Recent releases of PHP for Windows can be found here: http://windows.php.net/download/. Older releases can be found in the archive here: http://windows.php.net/downloads/releases/archives/.
  2. Modify the php.ini file for your runtime. Note that any configuration settings that are system-level-only directives will be ignored by Windows Azure Web Sites. (For information about system-level-only directives, see List of php.ini directives).
  3. Optionally, add extensions to your PHP runtime and enable them in the php.ini file.
  4. Add bin directory to your root directory, and put the directory that contains your PHP runtime in it (for example, bin\php).
  5. Deploy your application.
  6. Navigate to your site’s dashboard in the Windows Azure Portal, and click on CONFIGURE.

    Configure tab on Web Sites dashboard

  7. In the handler mappings section, add *.php to EXTENSION and add the path to the php-cgi.exe executable. If your put your PHP runtime in the bin directory in the root of you application, the path will be D:\home\site\wwwroot\bin\php\php-cgi.exe.

    Specify handler in hander mappings

  8. Click SAVE at the bottom of the page.

    Save configuration settings

Next steps

Now that you’ve learned how to configure PHP in Windows Azure Web Sites, follow the links below to learn how to do more.

Rss Newsletter