Configure PHP in Azure App Service Web Apps
Introduction
This guide will show you how to configure the built-in PHP runtime for Web Apps in Azure App Service, provide a custom PHP runtime, and enable extensions. To use App Service, sign up for the free trial. To get the most from this guide, you should first create a PHP web app in App Service.
How to: Change the built-in PHP version
By default, PHP 5.4 is installed and immediately available for use when you create an App Service web app. The best way to see the available release revision, its default configuration, and the enabled extensions is to deploy a script that calls the phpinfo() function.
PHP 5.5 and PHP 5.6 versions are also available, but not enabled by default. To update the PHP version, follow one of these methods:
Azure Portal
Browse to your web app in the Azure Portal and click on the Settings button.
From the Settings blade select Application Settings and choose the new PHP version.
Click the Save button at the top of the Web app settings blade.
Azure PowerShell (Windows)
Open Azure PowerShell, and login to your account:
PS C:\> Login-AzureRmAccount
Set the PHP version for the web app.
PS C:\> Set-AzureWebsite -PhpVersion [5.4 | 5.5 | 5.6] -Name {site-name}The PHP version is now set. You can confirm these settings:
PS C:\> Get-AzureWebsite -Name {site-name} | findstr PhpVersion
Azure Command-Line Interface (Linux, Mac, Windows)
To use the Azure Command-Line Interface, you must have Node.js installed on your computer.
Open Terminal, and login to your account.
azure login
Set the PHP version for the web app.
azure site set --php-version [5.4 | 5.5] {site-name}The PHP version is now set. You can confirm these settings:
azure site show {site-name}
How to: Change the built-in PHP configurations
For any built-in PHP runtime, you can change any of the configuration options by following the steps below. (For information about php.ini directives, see List of php.ini directives.)
Changing PHP_INI_USER, PHP_INI_PERDIR, PHP_INI_ALL configuration settings
- Add a .user.ini file to your root directory.
Add configuration settings to the
.user.inifile using the same syntax you would use in aphp.inifile. For example, if you wanted to turn thedisplay_errorssetting on and setupload_max_filesizesetting to 10M, your.user.inifile would contain this text:; Example Settings display_errors=On upload_max_filesize=10M
Deploy your web app.
Restart the web app. (Restarting is necessary because the frequency with which PHP reads
.user.inifiles is governed by theuser_ini.cache_ttlsetting, which is a system level setting and is 300 seconds (5 minutes) by default. Restarting the web app forces PHP to read the new settings in the.user.inifile.)
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.
Changing PHP_INI_SYSTEM configuration settings
- Add an App Setting to your Web App with the key
PHP_INI_SCAN_DIRand valued:\home\site\ini - Create an
settings.inifile using Kudu Console (http://<site-name>.scm.azurewebsite.net) in thed:\home\site\inidirectory. Add configuration settings to the
settings.inifile using the same syntax you would use in a php.ini file. For example, if you wanted to point thecurl.cainfosetting to a*.crtfile and set 'wincache.maxfilesize' setting to 512K, yoursettings.inifile would contain this text:; Example Settings curl.cainfo="%ProgramFiles(x86)%\Git\bin\curl-ca-bundle.crt" wincache.maxfilesize=512
Restart your Web App to load the changes.
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:
Configure via ini settings
- Add a
extdirectory to thed:\home\sitedirectory. - Put
.dllextension files in theextdirectory (for example,php_mongo.dllandphp_xdebug.dll). Make sure that the extensions are compatible with default version of PHP (which is, as of this writing, PHP 5.4) and are VC9 and non-thread-safe (nts) compatible. - Add an App Setting to your Web App with the key
PHP_INI_SCAN_DIRand valued:\home\site\ini - Create an
inifile ind:\home\site\inicalledextensions.ini. Add configuration settings to the
extensions.inifile using the same syntax you would use in a php.ini file. For example, if you wanted to enable the MongoDB and XDebug extensions, yourextensions.inifile would contain this text:; Enable Extensions extension=d:\home\site\ext\php_mongo.dll zend_extension=d:\home\site\ext\php_xdebug.dll
Restart your Web App to load the changes.
Configure via App Setting
- Add a
bindirectory to the root directory. - Put
.dllextension files in thebindirectory (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.4) and are VC9 and non-thread-safe (nts) compatible. - Deploy your web app.
Browse to your web app in the Azure Portal and click on the Settings button.
From the Settings blade select Application Settings and scroll to the App settings section.
In the App settings section, create a PHP_EXTENSIONS key. The value for this key would be a path relative to website root: bin\your-ext-file.
Click the Save button at the top of the Web app settings blade.
Zend extensions are also supported by using a PHP_ZENDEXTENSIONS key. To enable multiple extensions, include a comma-separated list of .dll files for the app setting value.
How to: Use a custom PHP runtime
Instead of the default PHP runtime, App Service Web Apps 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 with Web Apps, follow the steps below.
- Obtain a non-thread-safe, VC9 or VC11 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/.
- Modify the
php.inifile for your runtime. Note that any configuration settings that are system-level-only directives will be ignored by Web Apps. (For information about system-level-only directives, see List of php.ini directives). - Optionally, add extensions to your PHP runtime and enable them in the
php.inifile. - Add a
bindirectory to your root directory, and put the directory that contains your PHP runtime in it (for example,bin\php). - Deploy your web app.
Browse to your web app in the Azure Portal and click on the Settings button.
From the Settings blade select Application Settings and scroll to the Handler mappings section. Add
*.phpto the Extension field and add the path to thephp-cgi.exeexecutable. If you put your PHP runtime in thebindirectory in the root of you application, the path will beD:\home\site\wwwroot\bin\php\php-cgi.exe.
Click the Save button at the top of the Web app settings blade.
How to: Enable Composer automation in Azure
By default, App Service doesn't do anything with composer.json, if you have one in your PHP project. If you use Git deployment, you can enable composer.json processing during git push by enabling the Composer extension.
Note:
You can vote for first-class Composer support in App Service here!
In your PHP web app's blade in the Azure portal, click Tools > Extensions.
Click Add, then click Composer.
Click OK to accept legal terms. Click OK again to add the extension.
The Installed extensions blade will now show the Composer extension.
Now, perform
git add,git commit, andgit pushlike in the previous section. You'll now see that Composer is installing dependencies defined in composer.json.
Next steps
For more information, see the PHP Developer Center.
Note:
If you want to get started with Azure App Service before signing up for an Azure account, go to Try App Service, where you can immediately create a short-lived starter web app in App Service. No credit cards required; no commitments.

