You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/app-service/configure-language-php.md
+34-30Lines changed: 34 additions & 30 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,36 +3,38 @@ title: Configure a PHP App
3
3
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.
This guide shows you how to configure your PHP web apps, mobile back ends, and API apps in Azure App Service.
20
+
This guide shows you how to configure your PHP web apps, mobile back ends, and API apps in Azure App Service. The most common configuration tasks are covered.
21
21
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.
22
+
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.
23
23
24
24
## Show the PHP version
25
25
26
-
To show the current PHP version, run the following command in[Azure Cloud Shell](https://shell.azure.com):
26
+
To show the current PHP version, run the following command. You can use the[Azure Cloud Shell](https://shell.azure.com):
27
27
28
28
```azurecli-interactive
29
29
az webapp config show --resource-group <resource-group-name> --name <app-name> --query phpVersion
30
30
```
31
31
32
+
Replace `<resource-group-name>` and `<app-name>` with names that are appropriate for your web app.
33
+
32
34
> [!NOTE]
33
35
> To address a development slot, include the parameter `--slot` followed by the name of the slot.
34
36
35
-
To show all supported PHP versions, run the following command in Cloud Shell:
37
+
To show all supported PHP versions, run the following command:
36
38
37
39
```azurecli-interactive
38
40
az webapp list-runtimes --os windows | grep PHP
@@ -42,22 +44,24 @@ az webapp list-runtimes --os windows | grep PHP
42
44
43
45
::: zone pivot="platform-linux"
44
46
45
-
This guide shows you how to configure your PHP web apps, mobile back ends, and API apps in Azure App Service.
47
+
This guide shows you how to configure your PHP web apps, mobile back ends, and API apps in Azure App Service. The most common configuration tasks are covered.
46
48
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.
49
+
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.
48
50
49
51
## Show the PHP version
50
52
51
-
To show the current PHP version, run the following command in [Azure Cloud Shell](https://shell.azure.com):
53
+
To show the current PHP version, run the following command. You can use the [Azure Cloud Shell](https://shell.azure.com).
52
54
53
55
```azurecli-interactive
54
56
az webapp config show --resource-group <resource-group-name> --name <app-name> --query linuxFxVersion
55
57
```
56
58
59
+
Replace `<resource-group-name>` and `<app-name>` with names that are appropriate for your web app.
60
+
57
61
> [!NOTE]
58
62
> To address a development slot, include the parameter `--slot` followed by the name of the slot.
59
63
60
-
To show all supported PHP versions, run the following command in Cloud Shell:
64
+
To show all supported PHP versions, run the following command:
61
65
62
66
```azurecli-interactive
63
67
az webapp list-runtimes --os linux | grep PHP
@@ -69,7 +73,7 @@ az webapp list-runtimes --os linux | grep PHP
69
73
70
74
::: zone pivot="platform-windows"
71
75
72
-
To set the PHP version to 8.1, run the following command in [Cloud Shell](https://shell.azure.com):
76
+
To set the PHP version to 8.1, run the following command:
73
77
74
78
```azurecli-interactive
75
79
az webapp config set --resource-group <resource-group-name> --name <app-name> --php-version 8.1
@@ -79,7 +83,7 @@ az webapp config set --resource-group <resource-group-name> --name <app-name> --
79
83
80
84
::: zone pivot="platform-linux"
81
85
82
-
To set the PHP version to 8.1, run the following command in [Cloud Shell](https://shell.azure.com):
86
+
To set the PHP version to 8.1, run the following command:
83
87
84
88
```azurecli-interactive
85
89
az webapp config set --resource-group <resource-group-name> --name <app-name> --linux-fx-version "PHP|8.1"
@@ -230,11 +234,11 @@ az webapp config appsettings set --name <app-name> --resource-group <resource-gr
230
234
231
235
For other environment variables to customize build automation, see [Oryx configuration](https://github.com/microsoft/Oryx/blob/master/doc/configuration.md).
232
236
233
-
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).
237
+
To learn 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).
234
238
235
239
## Customize startup
236
240
237
-
You can run a custom command at the container startup time. Run the following command in [Cloud Shell](https://shell.azure.com):
241
+
You can run a custom command at the container startup time. Run the following command:
238
242
239
243
```azurecli-interactive
240
244
az webapp config set --resource-group <resource-group-name> --name <app-name> --startup-file "<custom-command>"
@@ -270,7 +274,7 @@ By default, Azure App Service points the root virtual application path (`/`) to
270
274
271
275
The web framework of your choice might use a subdirectory as the site root. For example, [Laravel](https://laravel.com/) uses the `public/` subdirectory as the site root.
272
276
273
-
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:
277
+
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:
274
278
275
279
```output
276
280
server {
@@ -341,15 +345,15 @@ As an alternative to using a `.user.ini` file, you can use [`ini_set()`](https:/
341
345
342
346
::: zone pivot="platform-linux"
343
347
344
-
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:
348
+
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:
345
349
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**.
350
+
1. Go to your Kudu site. To get the random hash and region values, in your app **Overview**, copy **Default domain**.
347
351
1. On the top menu, select **Debug console**, then **Bash** or **SSH**.
348
352
1. In Bash or SSH, go to your `/home/site/wwwroot` directory.
349
353
1. Create a directory called `ini` (for example, `mkdir ini`).
350
354
1. Change the current working directory to the `ini` folder that you created.
351
355
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:
356
+
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:
@@ -364,7 +368,7 @@ In the Azure portal, add an application setting to scan the `ini` directory that
364
368
365
369
1. Go to the [Azure portal](https://portal.azure.com) and select your App Service Linux PHP application.
366
370
1. Go to **Settings** > **Environment variables**.
367
-
1. Select **Add**.
371
+
1. Select **+ Add**.
368
372
1. For **Name** enter *PHP_INI_SCAN_DIR* and for **Value**, enter `:/home/site/wwwroot/ini`.
369
373
1. Select **Apply**, then **Apply** again. Confirm your changes.
370
374
@@ -379,15 +383,15 @@ In the Azure portal, add an application setting to scan the `ini` directory that
379
383
380
384
To customize `PHP_INI_SYSTEM` directives, use the `PHP_INI_SCAN_DIR` app setting.
381
385
382
-
First, run the following command in [Cloud Shell](https://shell.azure.com)to add an app setting called `PHP_INI_SCAN_DIR`:
386
+
First, run the following command to add an app setting called `PHP_INI_SCAN_DIR`:
383
387
384
388
```azurecli-interactive
385
389
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PHP_INI_SCAN_DIR="d:\home\site\ini"
386
390
```
387
391
388
-
Go to the Kudu console (`https://<app-name>-<random-hash>.scm.<region>.azurewebsites.net/DebugConsole`), and then go to `d:\home\site`.
392
+
Go to the Kudu console, and then go to `d:\home\site`.
389
393
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.
394
+
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.
391
395
392
396
For example, to change the value of [`expose_php`](https://php.net/manual/ini.core.php#ini.expose-php), run the following commands:
393
397
@@ -403,19 +407,19 @@ For the changes to take effect, restart the app.
403
407
404
408
::: zone pivot="platform-linux"
405
409
406
-
To customize `PHP_INI_SYSTEM` directives, you can't use the `.htaccess` approach. App Service provides a separate mechanism that uses the `PHP_INI_SCAN_DIR` app setting.
410
+
To customize `PHP_INI_SYSTEM` directives, you can't use the *.htaccess* approach. App Service provides a separate mechanism that uses the `PHP_INI_SCAN_DIR` app setting.
407
411
408
-
First, run the following command in [Cloud Shell](https://shell.azure.com)to add an app setting called `PHP_INI_SCAN_DIR`:
412
+
First, run the following command to add an app setting called `PHP_INI_SCAN_DIR`:
409
413
410
414
```azurecli-interactive
411
415
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"
412
416
```
413
417
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 (`:`).
418
+
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 (`:`).
415
419
416
-
Go to the web SSH session with your Linux container (`https://<app-name>-<random-hash>.scm.<region>.azurewebsites.net/webssh/host`).
420
+
Go to the web SSH session with your Linux container.
417
421
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.
422
+
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.
419
423
420
424
> [!TIP]
421
425
> The built-in Linux containers in App Service use `/home` as persisted shared storage.
@@ -443,7 +447,7 @@ The built-in PHP installations contain the most commonly used extensions. You ca
443
447
444
448
To enable other extensions, use the following steps:
445
449
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.
450
+
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.
447
451
448
452
1. Deploy your changes.
449
453
@@ -467,7 +471,7 @@ The built-in PHP installations contain the most commonly used extensions. You ca
467
471
468
472
To enable other extensions, use the following steps:
469
473
470
-
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.
474
+
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.
471
475
472
476
1. Deploy your changes.
473
477
@@ -502,7 +506,7 @@ Use the standard [`error_log()`](https://php.net/manual/function.error-log.php)
502
506
503
507
When a working PHP app behaves differently in App Service or has errors, try the following solutions:
504
508
505
-
-[Access the log stream](#access-diagnostic-logs).
- Test the app locally in production mode. App Service runs your app in production mode, so you need to make sure that your project works as expected in production mode locally. For example:
507
511
- Depending on your `composer.json` file, different packages might be installed for production mode (`require` versus `require-dev`).
508
512
- Certain web frameworks might deploy static files differently in production mode.
0 commit comments