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
# Tutorial: Build a Tomcat web app with Azure App Service on Linux and MySQL
14
14
15
-
This tutorial shows how to build, configure, and deploy a secure Tomcat application in Azure App Service that's connected to a MySQL database (using [Azure Database for MySQL](../mysql/index.yml)). Azure App Service is a highly scalable, self-patching, web-hosting service that can easily deploy apps on Windows or Linux. When you're finished, you'll have a Tomcat app running on [Azure App Service on Linux](overview.md).
15
+
This tutorial shows how to build, configure, and deploy a secure Tomcat application in Azure App Service that connects to a MySQL database (using [Azure Database for MySQL](../mysql/index.yml)). Azure App Service is a highly scalable, self-patching, web-hosting service that can easily deploy apps on Windows or Linux. When you're finished, you'll have a Tomcat app running on [Azure App Service on Linux](overview.md).
16
16
17
17
:::image type="content" source="./media/tutorial-java-tomcat-mysql-app/azure-portal-browse-app-2.png" alt-text="Screenshot of Tomcat application storing data in MySQL.":::
18
18
@@ -163,7 +163,7 @@ App settings are one way to keep connection secrets out of your code repository.
163
163
:::column span="2":::
164
164
**Step 2:**
165
165
1. In the **Application settings** tab of the **Configuration** page, find the app setting `AZURE_MYSQL_CONNECTIONSTRING`. The creation wizard created it for you.
166
-
1. If you want, you can select the **Edit** button to the right of each setting and see or copy its value, or select Add to add a variable to inject into your Tomcat container. If you add an app setting that contains a valid Oracle, SQL Server, PostgreSQL, or MySQL connection string, App Service adds it as a JNDI data source in the Tomcat server's *context.xml* file.
166
+
1. If you want, you can select the **Edit** button to the right of each setting and see or copy its value, or select Add to add a variable to inject into your Tomcat container. If you add an app setting that contains a valid Oracle, SQL Server, PostgreSQL, or MySQL connection string, App Service adds it as a Java Naming and Directory Interface (JNDI) data source in the Tomcat server's *context.xml* file.
167
167
:::column-end:::
168
168
:::column:::
169
169
:::image type="content" source="./media/tutorial-java-tomcat-mysql-app/azure-portal-get-connection-string-2.png" alt-text="A screenshot showing how to see the autogenerated connection string." lightbox="./media/tutorial-java-tomcat-mysql-app/azure-portal-get-connection-string-2.png":::
@@ -189,7 +189,7 @@ In this step, you use the SSH connection to the app container to verify the JNDI
189
189
:::row:::
190
190
:::column span="2":::
191
191
**Step 2:** In the SSH terminal:
192
-
1. Run `cat /usr/local/tomcat/conf/context.xml`. You should see that a JNDI resource called `jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS` was added. You will use this data source later.
192
+
1. Run `cat /usr/local/tomcat/conf/context.xml`. You should see that a JNDI resource called `jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS` was added. You'll use this data source later.
193
193
:::column-end:::
194
194
:::column:::
195
195
:::image type="content" source="./media/tutorial-java-tomcat-mysql-app/azure-portal-check-config-in-ssh-2.png" alt-text="A screenshot showing the commands to run in the SSH shell and their output." lightbox="./media/tutorial-java-tomcat-mysql-app/azure-portal-check-config-in-ssh-2.png":::
@@ -307,7 +307,7 @@ Having issues? Check the [Troubleshooting section](#troubleshooting).
307
307
308
308
## 7. Stream diagnostic logs
309
309
310
-
Azure App Service captures all messages output to the console to help you diagnose issues with your application. The sample application includes standard Log4j logging statements to demonstrate this capability as shown below.
310
+
Azure App Service captures all messages output to the console to help you diagnose issues with your application. The sample application includes standard Log4j logging statements to demonstrate this capability, as shown in the following snippet:
@@ -375,7 +375,7 @@ When you're finished, you can delete all of the resources from your Azure subscr
375
375
376
376
In this step, you create the Azure resources and deploy a sample app to App Service on Linux. The steps used in this tutorial create a set of secure-by-default resources that include App Service and Azure Database for MySQL.
377
377
378
-
The dev container already has the [Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd).
378
+
The dev container already has the [Azure Developer CLI](/azure/developer/azure-developer-cli/install-azd) (AZD).
379
379
380
380
1. From the repository root, run `azd init`.
381
381
@@ -389,23 +389,23 @@ The dev container already has the [Azure Developer CLI](/azure/developer/azure-d
389
389
|---------|---------|
390
390
|The current directory is not empty. Would you like to initialize a project here in'\<your-directory>'?|**Y**|
391
391
|What would you like to do with these files?|**Keep my existing files unchanged**|
392
-
|Enter a new environment name | Type a unique name. The azd template uses this name as part of the DNS name of your web app in Azure (`<app-name>.azurewebsites.net`). Alphanumeric characters and hyphens are allowed. |
392
+
|Enter a new environment name | Type a unique name. The AZD template uses this name as part of the DNS name of your web app in Azure (`<app-name>.azurewebsites.net`). Alphanumeric characters and hyphens are allowed. |
393
393
394
-
1. Run the `azd auth login`command and follow the prompt to sign into Azure.
394
+
1. Sign into Azure by running the `azd auth login`command and following the prompt:
395
395
396
396
```bash
397
397
azd auth login
398
398
```
399
399
400
-
1. Run the `azd up`command to create the necessary Azure resources and deploy the app code. Follow the prompt to selectthe desired subscription and location for the Azure resources.
400
+
1. Create the necessary Azure resources and deploy the app code with the `azd up` command. Follow the prompt to selectthe desired subscription and location for the Azure resources.
401
401
402
402
```bash
403
403
azd up
404
404
```
405
405
406
406
The `azd up`command takes about 15 minutes to complete (the Redis cache take the most time). It also compiles and deploys your application code, but you'll modify your code later to work with App Service. While it's running, the command provides messages about the provisioning and deployment process, including a link to the deployment in Azure. When it finishes, the command also displays a link to the deploy application.
407
407
408
-
This azd template contains files (*azure.yaml* and the *infra* directory) that generate a secure-by-default architecture with the following Azure resources:
408
+
This AZD template contains files (*azure.yaml* and the *infra* directory) that generate a secure-by-default architecture with the following Azure resources:
409
409
410
410
- **Resource group**: The container for all the created resources.
411
411
- **App Service plan**: Defines the compute resources forApp Service. A Linux planin the *B1* tier is created.
@@ -415,13 +415,13 @@ The dev container already has the [Azure Developer CLI](/azure/developer/azure-d
415
415
- **Azure Cache for Redis**: Accessible only from within the virtual network.
416
416
- **Private DNS zones**: Enable DNS resolution of the database server and the Redis cache in the virtual network.
417
417
- **Log Analytics workspace**: Acts as the target container for your app to ship its logs, where you can also query the logs.
418
-
- **Key vault**: Used to keep your database password the same when you redeploy with azd.
418
+
- **Key vault**: Used to keep your database password the same when you redeploy with AZD.
419
419
420
420
## 3. Verify connection strings
421
421
422
-
The azd template you use generated the connectivity variables for you already as [app settings](configure-common.md#configure-app-settings) and outputs the them to the terminal for your convenience. App settings are one way to keep connection secrets out of your code repository.
422
+
The AZD template you use generated the connectivity variables for you already as [app settings](configure-common.md#configure-app-settings) and outputs the them to the terminal for your convenience. App settings are one way to keep connection secrets out of your code repository.
423
423
424
-
1. In the azd output, find the app setting `AZURE_MYSQL_CONNECTIONSTRING`. To keep secrets safe, only the setting names are displayed. They look like this in the azd output:
424
+
1. In the AZD output, find the app setting `AZURE_MYSQL_CONNECTIONSTRING`. To keep secrets safe, only the setting names are displayed. They look like this in the AZD output:
425
425
426
426
<pre>
427
427
App Service app has the following connection strings:
@@ -432,21 +432,21 @@ The azd template you use generated the connectivity variables for you already as
432
432
433
433
`AZURE_MYSQL_CONNECTIONSTRING` contains the connection string to the MySQL database in Azure. You need to use it in your code later.
434
434
435
-
1. For your convenience, the azd template shows you the direct link to the app's app settings page. Find the link and open it in a new browser tab.
435
+
1. For your convenience, the AZD template shows you the direct link to the app's app settings page. Find the link and open it in a new browser tab.
436
436
437
-
If you add an app setting that contains a valid Oracle, SQL Server, PostgreSQL, or MySQL connection string, App Service adds it as a JNDI data source in the Tomcat server's *context.xml* file.
437
+
If you add an app setting that contains a valid Oracle, SQL Server, PostgreSQL, or MySQL connection string, App Service adds it as a Java Naming and Directory Interface (JNDI) data source in the Tomcat server's *context.xml* file.
438
438
439
439
## 4. Confirm JNDI data source
440
440
441
441
In this step, you use the SSH connection to the app container to verify the JNDI data sourcein the Tomcat server. In the process, you learn how to access the SSH shell for the Tomcat container.
442
442
443
-
1. In the azd output, find the URL forthe SSH session and navigate to itin the browser. It looks like this in the output:
443
+
1. In the AZD output, find the URL forthe SSH session and navigate to itin the browser. It looks like this in the output:
444
444
445
445
<pre>
446
446
Open SSH session to App Service container at: https://<app-name>.scm.azurewebsites.net/webssh/host
447
447
</pre>
448
448
449
-
1. In the SSH terminal, run `cat /usr/local/tomcat/conf/context.xml`. You should see that a JNDI resource called `jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS` was added. You will use this data source later.
449
+
1. In the SSH terminal, run `cat /usr/local/tomcat/conf/context.xml`. You should see that a JNDI resource called `jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS` was added. You'll use this data source later.
450
450
451
451
:::image type="content" source="./media/tutorial-java-tomcat-mysql-app/azure-portal-check-config-in-ssh-2.png" alt-text="A screenshot showing the commands to run in the SSH shell and their output.":::
452
452
@@ -481,7 +481,7 @@ In this step, you use the SSH connection to the app container to verify the JNDI
481
481
482
482
## 6. Browse to the app
483
483
484
-
1. In the azd output, find the URL of your app and navigate to it in the browser. The URL looks like this in the AZD output:
484
+
1. In the AZD output, find the URL of your app and navigate to it in the browser. The URL looks like this in the AZD output:
485
485
486
486
<pre>
487
487
Deploying services (azd deploy)
@@ -498,13 +498,13 @@ In this step, you use the SSH connection to the app container to verify the JNDI
498
498
499
499
## 7. Stream diagnostic logs
500
500
501
-
Azure App Service can capture console logs to help you diagnose issues with your application. For convenience, the azd template already [enabled logging to the local file system](troubleshoot-diagnostic-logs.md#enable-application-logging-linuxcontainer) and is [shipping the logs to a Log Analytics workspace](troubleshoot-diagnostic-logs.md#send-logs-to-azure-monitor).
501
+
Azure App Service can capture console logs to help you diagnose issues with your application. For convenience, the AZD template already [enabled logging to the local file system](troubleshoot-diagnostic-logs.md#enable-application-logging-linuxcontainer) and is [shipping the logs to a Log Analytics workspace](troubleshoot-diagnostic-logs.md#send-logs-to-azure-monitor).
502
502
503
-
The sample application includes standard Log4j logging statements to demonstrate this capability as shown below.
503
+
The sample application includes standard Log4j logging statements to demonstrate this capability, as shown in the following snippet:
In the azd output, find the link to stream App Service logs and navigate to it in the browser. The link looks like this in the azd output:
507
+
In the AZD output, find the link to stream App Service logs and navigate to it in the browser. The link looks like this in the AZD output:
508
508
509
509
<pre>
510
510
Stream App Service logs at: https://portal.azure.com/#@/resource/subscriptions/<subscription-guid>/resourceGroups/<group-name>/providers/Microsoft.Web/sites/<app-name>/logStream
@@ -535,19 +535,19 @@ You can ignore the warnings. The Maven Jetty plugin shows the warnings because t
535
535
536
536
#### The portal deployment view for Azure Database for MySQL Flexible Server shows a Conflict status
537
537
538
-
Depending on your subscription and the region you select, you may see the deployment status forAzure Database for MySQL Flexible Server to be `Conflict`, with the following messagein Operation details:
538
+
Depending on your subscription and the region you select, you might see the deployment status for Azure Database for MySQL Flexible Server to be `Conflict`, with the following message in Operation details:
539
539
540
540
`InternalServerError: An unexpected error occured while processing the request.`
541
541
542
-
This is most likely because there's a limit on your subscription for the region you select. Try choosing a different region for your deployment.
542
+
This error is most likely caused by a limit on your subscription for the region you select. Try choosing a different region for your deployment.
543
543
544
544
#### The deployed sample app doesn't show the tasks list app
545
545
546
546
If you see a `Hey, Java developers!` page instead of the tasks list app, App Service is most likely still loading the updated container from your most recent code deployment. Wait a few minutes and refresh the page.
547
547
548
548
#### I see a 404 Page Not Found error in the deployed sample app
549
549
550
-
Make sure that you made the code changes to use the `java:comp/env/jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS` data source. If you have made the changes and have redeployed your code, App Service is most likely still loading the updated container. Wait a few minutes and refresh the page.
550
+
Make sure that you made the code changes to use the `java:comp/env/jdbc/AZURE_MYSQL_CONNECTIONSTRING_DS` data source. If you made the changes and redeployed your code, App Service is most likely still loading the updated container. Wait a few minutes and refresh the page.
551
551
552
552
## Frequently asked questions
553
553
@@ -567,8 +567,8 @@ Pricing for the created resources is as follows:
567
567
568
568
#### How do I connect to the MySQL server behind the virtual network with other tools?
569
569
570
-
- The Tomcat container currently doesn't have the `mysql-client` terminal too. If you want, you must manually install it. Note that anything you install won't persist across app restart.
571
-
- To connect from a desktop tool like MySQL Workbench, your machine must be within the virtual network. For example, it could be an Azure VM that's connected to one of the subnets, or a machine in an on-premises network that has a [site-to-site VPN](../vpn-gateway/vpn-gateway-about-vpngateways.md) connection with the Azure virtual network.
570
+
- The Tomcat container currently doesn't have the `mysql-client` terminal too. If you want, you must manually install it. Note that anything you install doesn't persist across app restarts.
571
+
- To connect from a desktop tool like MySQL Workbench, your machine must be within the virtual network. For example, it could be an Azure VM in one of the subnets, or a machine in an on-premises network that has a [site-to-site VPN](../vpn-gateway/vpn-gateway-about-vpngateways.md) connection with the Azure virtual network.
572
572
- You can also [integrate Azure Cloud Shell](../cloud-shell/private-vnet.md) with the virtual network.
573
573
574
574
#### How does local app development work with GitHub Actions?
0 commit comments