Skip to content

Commit b3a36d1

Browse files
AI Freshness Edit: Azure App Services
1 parent 61c48c9 commit b3a36d1

File tree

1 file changed

+39
-37
lines changed

1 file changed

+39
-37
lines changed

articles/app-service/configure-language-php.md

Lines changed: 39 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@ title: Configure a PHP App
33
description: Learn how to configure a PHP app in a prebuilt PHP container in Azure App Service. This article shows the most common configuration tasks.
44
ms.devlang: php
55
ms.topic: how-to
6-
ms.date: 08/31/2023
6+
ms.date: 04/01/2025
77
ms.custom: devx-track-azurecli, linux-related-content
88
zone_pivot_groups: app-service-platform-windows-linux
99
ms.author: msangapu
1010
author: msangapu-msft
11+
#customer intent: As an app developer who uses PHP, I want to understand how to configure my PHP web apps in Azure App Service.
1112
---
1213

1314
# Configure a PHP app for Azure App Service
@@ -18,7 +19,7 @@ author: msangapu-msft
1819

1920
This guide shows you how to configure your PHP web apps, mobile back ends, and API apps in Azure App Service.
2021

21-
This guide provides key concepts and instructions for PHP developers who deploy apps to App Service. If you've never used App Service, you should first follow the [Create a PHP web app in Azure App Service](quickstart-php.md) quickstart and the [Deploy a PHP, MySQL, and Redis app to Azure App Service](tutorial-php-mysql-app.md) tutorial.
22+
This guide provides key concepts and instructions for PHP developers who deploy apps to App Service. If you're new to App Service, you should first follow the [Create a PHP web app in Azure App Service](quickstart-php.md) quickstart and the [Deploy a PHP, MySQL, and Redis app to Azure App Service](tutorial-php-mysql-app.md) tutorial.
2223

2324
## Show the PHP version
2425

@@ -43,7 +44,7 @@ az webapp list-runtimes --os windows | grep PHP
4344

4445
This guide shows you how to configure your PHP web apps, mobile back ends, and API apps in Azure App Service.
4546

46-
This guide provides key concepts and instructions for PHP developers who deploy apps to App Service. If you've never used Azure App Service, you should first follow the [Create a PHP web app in Azure App Service](quickstart-php.md) quickstart and the [Deploy a PHP, MySQL, and Redis app to Azure App Service](tutorial-php-mysql-app.md) tutorial.
47+
This guide provides key concepts and instructions for PHP developers who deploy apps to App Service. If you're new to App Service, you should first follow the [Create a PHP web app in Azure App Service](quickstart-php.md) quickstart and the [Deploy a PHP, MySQL, and Redis app to Azure App Service](tutorial-php-mysql-app.md) tutorial.
4748

4849
## Show the PHP version
4950

@@ -68,7 +69,7 @@ az webapp list-runtimes --os linux | grep PHP
6869

6970
::: zone pivot="platform-windows"
7071

71-
Run the following command in [Cloud Shell](https://shell.azure.com) to set the PHP version to 8.1:
72+
To set the PHP version to 8.1, run the following command in [Cloud Shell](https://shell.azure.com):
7273

7374
```azurecli-interactive
7475
az webapp config set --resource-group <resource-group-name> --name <app-name> --php-version 8.1
@@ -78,7 +79,7 @@ az webapp config set --resource-group <resource-group-name> --name <app-name> --
7879

7980
::: zone pivot="platform-linux"
8081

81-
Run the following command in [Cloud Shell](https://shell.azure.com) to set the PHP version to 8.1:
82+
To set the PHP version to 8.1, run the following command in [Cloud Shell](https://shell.azure.com):
8283

8384
```azurecli-interactive
8485
az webapp config set --resource-group <resource-group-name> --name <app-name> --linux-fx-version "PHP|8.1"
@@ -101,7 +102,7 @@ npm install kuduscript -g
101102
kuduscript --node --scriptType bash --suppressPrompt
102103
```
103104

104-
Your repository root now has two additional files: `.deployment` and `deploy.sh`.
105+
Your repository root now has two new files: `.deployment` and `deploy.sh`.
105106

106107
Open `deploy.sh` and find the `Deployment` section, which looks like this example:
107108

@@ -129,7 +130,7 @@ Commit all your changes and deploy your code by using Git or by using ZIP deploy
129130

130131
## Run Bower, Gulp, or Grunt
131132

132-
If you want App Service to run popular automation tools at deployment time (such as Bower, Gulp, or Grunt), you need to supply a [custom deployment script](https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script). App Service runs this script when you deploy by using Git or by using ZIP deploy with [build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy).
133+
If you want App Service to run popular automation tools at deployment time, such as Bower, Gulp, or Grunt, you need to supply a [custom deployment script](https://github.com/projectkudu/kudu/wiki/Custom-Deployment-Script). App Service runs this script when you deploy by using Git or by using ZIP deploy with [build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy).
133134

134135
To enable your repository to run these tools, you need to add them to the dependencies in `package.json`. For example:
135136

@@ -149,7 +150,7 @@ npm install kuduscript -g
149150
kuduscript --node --scriptType bash --suppressPrompt
150151
```
151152

152-
Your repository root now has two additional files: `.deployment` and `deploy.sh`.
153+
Your repository root now has two new files: `.deployment` and `deploy.sh`.
153154

154155
Open `deploy.sh` and find the `Deployment` section, which looks like this example:
155156

@@ -212,13 +213,13 @@ fi
212213

213214
## Customize build automation
214215

215-
If you deploy your app by using Git or by using ZIP packages [with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy), the App Service build automation steps through the following sequence:
216+
If you deploy your app by using Git or by using ZIP packages [with build automation enabled](deploy-zip.md#enable-build-automation-for-zip-deploy), the build automation in App Service steps through the following sequence:
216217

217218
1. Run a custom script if `PRE_BUILD_SCRIPT_PATH` specifies it.
218219
1. Run `php composer.phar install`.
219220
1. Run a custom script if `POST_BUILD_SCRIPT_PATH` specifies it.
220221

221-
`PRE_BUILD_COMMAND` and `POST_BUILD_COMMAND` are environment variables that are empty by default. To run pre-build commands, define `PRE_BUILD_COMMAND`. To run post-build commands, define `POST_BUILD_COMMAND`.
222+
`PRE_BUILD_COMMAND` and `POST_BUILD_COMMAND` are environment variables that are empty by default. To run prebuild commands, define `PRE_BUILD_COMMAND`. To run post-build commands, define `POST_BUILD_COMMAND`.
222223

223224
The following example specifies the two variables to a series of commands, separated by commas:
224225

@@ -227,13 +228,13 @@ az webapp config appsettings set --name <app-name> --resource-group <resource-gr
227228
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings POST_BUILD_COMMAND="echo foo, scripts/postbuild.sh"
228229
```
229230

230-
For additional environment variables to customize build automation, see [Oryx configuration](https://github.com/microsoft/Oryx/blob/master/doc/configuration.md).
231+
For other environment variables to customize build automation, see [Oryx configuration](https://github.com/microsoft/Oryx/blob/master/doc/configuration.md).
231232

232233
For more information on how App Service runs and builds PHP apps in Linux, see the [Oryx documentation on how PHP apps are detected and built](https://github.com/microsoft/Oryx/blob/master/doc/runtimes/php.md).
233234

234235
## Customize startup
235236

236-
If you want, you can run a custom command at the container startup time. Run the following command in [Cloud Shell](https://shell.azure.com):
237+
You can run a custom command at the container startup time. Run the following command in [Cloud Shell](https://shell.azure.com):
237238

238239
```azurecli-interactive
239240
az webapp config set --resource-group <resource-group-name> --name <app-name> --startup-file "<custom-command>"
@@ -271,7 +272,7 @@ The web framework of your choice might use a subdirectory as the site root. For
271272

272273
The default PHP image for App Service uses NGINX, and you change the site root by [configuring the NGINX server with the `root` directive](https://docs.nginx.com/nginx/admin-guide/web-server/serving-static-content/). [This example configuration file](https://github.com/Azure-Samples/laravel-tasks/blob/main/default) contains the following snippet that changes the `root` directive:
273274

274-
```
275+
```output
275276
server {
276277
#proxy_cache cache;
277278
#proxy_cache_valid 200 1s;
@@ -286,9 +287,9 @@ server {
286287
...
287288
```
288289

289-
The default container uses the configuration file at `/etc/nginx/sites-available/default`. Keep in mind that any edit you make to this file is erased when the app restarts. To make a change that's effective across app restarts, [add a custom startup command](#customize-startup) like this example:
290+
The default container uses the configuration file at `/etc/nginx/sites-available/default`. Any edit you make to this file is erased when the app restarts. To make a change that's effective across app restarts, [add a custom startup command](#customize-startup) like this example:
290291

291-
```
292+
```output
292293
cp /home/site/wwwroot/default /etc/nginx/sites-available/default && service nginx reload
293294
```
294295

@@ -323,7 +324,7 @@ To customize `PHP_INI_USER`, `PHP_INI_PERDIR`, and `PHP_INI_ALL` directives, add
323324

324325
Add configuration settings to the `.user.ini` file by using the same syntax that you would use in a `php.ini` file. For example, if you wanted to turn on the `display_errors` setting and set the `upload_max_filesize` setting to `10M`, your `.user.ini` file would contain this text:
325326

326-
```
327+
```ini
327328
; Example Settings
328329
display_errors=On
329330
upload_max_filesize=10M
@@ -342,15 +343,15 @@ As an alternative to using a `.user.ini` file, you can use [`ini_set()`](https:/
342343

343344
To customize `PHP_INI_USER`, `PHP_INI_PERDIR`, and `PHP_INI_ALL` directives for Linux web apps, such as `upload_max_filesize` and `expose_php`, use a custom .ini file. You can create it in an [SSH session](configure-linux-open-ssh-session.md). First, set up the directory:
344345

345-
1. Go to your Kudu site: `https://<sitename>.scm.azurewebsites.net`.
346-
2. On the top menu, select **Bash** or **SSH**.
347-
3. In Bash or SSH, go to your `/home/site/wwwroot` directory.
348-
4. Create a directory called `ini` (for example, `mkdir ini`).
349-
5. Change the current working directory to the `ini` folder that you just created.
346+
1. Go to your Kudu site, by default: `https://<app-name>-<random-hash>.scm.<region>.azurewebsites.net/`. To get the random hash and region values, in your app **Overview**, copy **Default domain**.
347+
1. On the top menu, select **Debug console**, then **Bash** or **SSH**.
348+
1. In Bash or SSH, go to your `/home/site/wwwroot` directory.
349+
1. Create a directory called `ini` (for example, `mkdir ini`).
350+
1. Change the current working directory to the `ini` folder that you created.
350351

351-
Now, create an .ini file where you'll add your settings. This example uses `extensions.ini`. There are no file editors such as Vi, Vim, or Nano, so use Echo to add the settings to the file. Change the `upload_max_filesize` value from `2M` to `50M`. Use the following command to add the setting and create an `extensions.ini` file if one doesn't already exist:
352+
Next, create an .ini file where you add your settings. This example uses `extensions.ini`. There are no file editors such as Vi, Vim, or Nano, so use Echo to add the settings to the file. Change the `upload_max_filesize` value from `2M` to `50M`. Use the following command to add the setting and create an `extensions.ini` file if one doesn't already exist:
352353

353-
```
354+
```bash
354355
/home/site/wwwroot/ini>echo "upload_max_filesize=50M" >> extensions.ini
355356
/home/site/wwwroot/ini>cat extensions.ini
356357

@@ -362,9 +363,10 @@ upload_max_filesize=50M
362363
In the Azure portal, add an application setting to scan the `ini` directory that you just created to apply the change for `upload_max_filesize`:
363364

364365
1. Go to the [Azure portal](https://portal.azure.com) and select your App Service Linux PHP application.
365-
2. Under **Application settings**, select **+ Add new setting**.
366-
3. For the app setting name, enter `PHP_INI_SCAN_DIR`. For the value, enter `:/home/site/wwwroot/ini`.
367-
4. Select **Save**.
366+
1. Go to **Settings** > **Environment variables**.
367+
1. Select **Add**.
368+
1. For **Name** enter *PHP_INI_SCAN_DIR* and for **Value**, enter `:/home/site/wwwroot/ini`.
369+
1. Select **Apply**, then **Apply** again. Confirm your changes.
368370

369371
> [!NOTE]
370372
> If you recompiled a PHP extension, such as GD, follow the steps at [Recompiling PHP extensions](/archive/blogs/azureossds/azure-app-service-linux-adding-php-extensions#recompiling-php-extensions--).
@@ -383,9 +385,9 @@ First, run the following command in [Cloud Shell](https://shell.azure.com) to ad
383385
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PHP_INI_SCAN_DIR="d:\home\site\ini"
384386
```
385387

386-
Go to the Kudu console (`https://<app-name>.scm.azurewebsites.net/DebugConsole`), and then go to `d:\home\site`.
388+
Go to the Kudu console (`https://<app-name>-<random-hash>.scm.<region>.azurewebsites.net/DebugConsole`), and then go to `d:\home\site`.
387389

388-
Create a directory in `d:\home\site` called `ini`. Then, create an .ini file in the `d:\home\site\ini` directory (for example, `settings.ini`) with the directives that you want to customize. Use the same syntax that you would use in a `php.ini` file.
390+
Create a directory in `d:\home\site` called `ini`. Then, create an .ini file in the `d:\home\site\ini` directory, for example, `settings.ini`, with the directives that you want to customize. Use the same syntax that you would use in a `php.ini` file.
389391

390392
For example, to change the value of [`expose_php`](https://php.net/manual/ini.core.php#ini.expose-php), run the following commands:
391393

@@ -409,11 +411,11 @@ First, run the following command in [Cloud Shell](https://shell.azure.com) to ad
409411
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PHP_INI_SCAN_DIR="/usr/local/etc/php/conf.d:/home/site/ini"
410412
```
411413

412-
The value `/usr/local/etc/php/conf.d` is the default directory where `php.ini` exists. The value `/home/site/ini` is the custom directory in which you'll add a custom .ini file. You separate the values with a colon (`:`).
414+
The value `/usr/local/etc/php/conf.d` is the default directory where `php.ini` exists. The value `/home/site/ini` is the custom directory in which you add a custom .ini file. You separate the values with a colon (`:`).
413415

414-
Go to the web SSH session with your Linux container (`https://<app-name>.scm.azurewebsites.net/webssh/host`).
416+
Go to the web SSH session with your Linux container (`https://<app-name>-<random-hash>.scm.<region>.azurewebsites.net/webssh/host`).
415417

416-
Create a directory in `/home/site` called `ini`. Then, create an .ini file in the `/home/site/ini` directory (for example, `settings.ini`) with the directives that you want to customize. Use the same syntax that you would use in a `php.ini` file.
418+
Create a directory in `/home/site` called `ini`. Then, create an .ini file in the `/home/site/ini` directory, for example, `settings.ini`, with the directives that you want to customize. Use the same syntax that you would use in a `php.ini` file.
417419

418420
> [!TIP]
419421
> The built-in Linux containers in App Service use `/home` as persisted shared storage.
@@ -434,20 +436,20 @@ For the changes to take effect, restart the app.
434436

435437
::: zone pivot="platform-windows"
436438

437-
The built-in PHP installations contain the most commonly used extensions. You can enable additional extensions in the same way that you [customize php.ini directives](#customize-php_ini_system-directives).
439+
The built-in PHP installations contain the most commonly used extensions. You can enable more extensions in the same way that you [customize php.ini directives](#customize-php_ini_system-directives).
438440

439441
> [!NOTE]
440442
> The best way to see the PHP version and the current `php.ini` configuration is to call [`phpinfo()`](https://php.net/manual/function.phpinfo.php) in your app.
441443
442-
To enable additional extensions, use the following steps:
444+
To enable other extensions, use the following steps:
443445

444-
1. Add a `bin` directory to the root directory of your app, and put the `.dll` extension files in it (for example, `mongodb.dll`). Make sure that the extensions are compatible with the PHP version in Azure, and that they're VC9 and non-thread-safe (NTS) compatible.
446+
1. Add a `bin` directory to the root directory of your app, and put the `.dll` extension files in it, for example, `mongodb.dll`. Make sure that the extensions are compatible with the PHP version in Azure, and that they're VC9 and non-thread-safe (NTS) compatible.
445447

446448
1. Deploy your changes.
447449

448450
1. Follow the steps in [Customize PHP_INI_SYSTEM directives](#customize-php_ini_system-directives), and add the extensions into the custom .ini file with the [extension](https://www.php.net/manual/ini.core.php#ini.extension) or [zend_extension](https://www.php.net/manual/ini.core.php#ini.zend-extension) directive:
449451

450-
```
452+
```ini
451453
extension=d:\home\site\wwwroot\bin\mongodb.dll
452454
zend_extension=d:\home\site\wwwroot\bin\xdebug.dll
453455
```
@@ -458,12 +460,12 @@ For the changes to take effect, restart the app.
458460

459461
::: zone pivot="platform-linux"
460462

461-
The built-in PHP installations contain the most commonly used extensions. You can enable additional extensions in the same way that you [customize php.ini directives](#customize-php_ini_system-directives).
463+
The built-in PHP installations contain the most commonly used extensions. You can enable more extensions in the same way that you [customize php.ini directives](#customize-php_ini_system-directives).
462464

463465
> [!NOTE]
464466
> The best way to see the PHP version and the current `php.ini` configuration is to call [`phpinfo()`](https://php.net/manual/function.phpinfo.php) in your app.
465467
466-
To enable additional extensions, use the following steps:
468+
To enable other extensions, use the following steps:
467469

468470
1. Add a `bin` directory to the root directory of your app, and put the `.so` extension files in it (for example, `mongodb.so`). Make sure that the extensions are compatible with the PHP version in Azure, and that they're VC9 and non-thread-safe (NTS) compatible.
469471

0 commit comments

Comments
 (0)