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
+39-37Lines changed: 39 additions & 37 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,11 +3,12 @@ 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.
#customer intent: As an app developer who uses PHP, I want to understand how to configure my PHP web apps in Azure App Service.
11
12
---
12
13
13
14
# Configure a PHP app for Azure App Service
@@ -18,7 +19,7 @@ author: msangapu-msft
18
19
19
20
This guide shows you how to configure your PHP web apps, mobile back ends, and API apps in Azure App Service.
20
21
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.
22
23
23
24
## Show the PHP version
24
25
@@ -43,7 +44,7 @@ az webapp list-runtimes --os windows | grep PHP
43
44
44
45
This guide shows you how to configure your PHP web apps, mobile back ends, and API apps in Azure App Service.
45
46
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.
47
48
48
49
## Show the PHP version
49
50
@@ -68,7 +69,7 @@ az webapp list-runtimes --os linux | grep PHP
68
69
69
70
::: zone pivot="platform-windows"
70
71
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):
72
73
73
74
```azurecli-interactive
74
75
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> --
78
79
79
80
::: zone pivot="platform-linux"
80
81
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):
82
83
83
84
```azurecli-interactive
84
85
az webapp config set --resource-group <resource-group-name> --name <app-name> --linux-fx-version "PHP|8.1"
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`.
105
106
106
107
Open `deploy.sh` and find the `Deployment` section, which looks like this example:
107
108
@@ -129,7 +130,7 @@ Commit all your changes and deploy your code by using Git or by using ZIP deploy
129
130
130
131
## Run Bower, Gulp, or Grunt
131
132
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).
133
134
134
135
To enable your repository to run these tools, you need to add them to the dependencies in `package.json`. For example:
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`.
153
154
154
155
Open `deploy.sh` and find the `Deployment` section, which looks like this example:
155
156
@@ -212,13 +213,13 @@ fi
212
213
213
214
## Customize build automation
214
215
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:
216
217
217
218
1. Run a custom script if `PRE_BUILD_SCRIPT_PATH` specifies it.
218
219
1. Run `php composer.phar install`.
219
220
1. Run a custom script if `POST_BUILD_SCRIPT_PATH` specifies it.
220
221
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`.
222
223
223
224
The following example specifies the two variables to a series of commands, separated by commas:
224
225
@@ -227,13 +228,13 @@ az webapp config appsettings set --name <app-name> --resource-group <resource-gr
227
228
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings POST_BUILD_COMMAND="echo foo, scripts/postbuild.sh"
228
229
```
229
230
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).
231
232
232
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).
233
234
234
235
## Customize startup
235
236
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):
237
238
238
239
```azurecli-interactive
239
240
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
271
272
272
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:
273
274
274
-
```
275
+
```output
275
276
server {
276
277
#proxy_cache cache;
277
278
#proxy_cache_valid 200 1s;
@@ -286,9 +287,9 @@ server {
286
287
...
287
288
```
288
289
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:
290
291
291
-
```
292
+
```output
292
293
cp /home/site/wwwroot/default /etc/nginx/sites-available/default && service nginx reload
293
294
```
294
295
@@ -323,7 +324,7 @@ To customize `PHP_INI_USER`, `PHP_INI_PERDIR`, and `PHP_INI_ALL` directives, add
323
324
324
325
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:
325
326
326
-
```
327
+
```ini
327
328
; Example Settings
328
329
display_errors=On
329
330
upload_max_filesize=10M
@@ -342,15 +343,15 @@ As an alternative to using a `.user.ini` file, you can use [`ini_set()`](https:/
342
343
343
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:
344
345
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.
350
351
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:
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`:
363
364
364
365
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.
368
370
369
371
> [!NOTE]
370
372
> 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
383
385
az webapp config appsettings set --name <app-name> --resource-group <resource-group-name> --settings PHP_INI_SCAN_DIR="d:\home\site\ini"
384
386
```
385
387
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`.
387
389
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.
389
391
390
392
For example, to change the value of [`expose_php`](https://php.net/manual/ini.core.php#ini.expose-php), run the following commands:
391
393
@@ -409,11 +411,11 @@ First, run the following command in [Cloud Shell](https://shell.azure.com) to ad
409
411
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"
410
412
```
411
413
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 (`:`).
413
415
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`).
415
417
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.
417
419
418
420
> [!TIP]
419
421
> 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.
434
436
435
437
::: zone pivot="platform-windows"
436
438
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).
438
440
439
441
> [!NOTE]
440
442
> 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.
441
443
442
-
To enable additional extensions, use the following steps:
444
+
To enable other extensions, use the following steps:
443
445
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.
445
447
446
448
1. Deploy your changes.
447
449
448
450
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:
@@ -458,12 +460,12 @@ For the changes to take effect, restart the app.
458
460
459
461
::: zone pivot="platform-linux"
460
462
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).
462
464
463
465
> [!NOTE]
464
466
> 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.
465
467
466
-
To enable additional extensions, use the following steps:
468
+
To enable other extensions, use the following steps:
467
469
468
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.
0 commit comments