t1agob / Drupal-7.1-with-PHP-7-as-an-Azure-App-Service

Running Drupal 7.1 with PHP 7 as an Azure App Service

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

image

Running a Custom Docker Container in an Azure App Service

This tutorial deploys Drupal 7.61 with PHP 7. However, the steps and principals can be applied to other customer containers too.

Prerequisites (required)

  1. Install the Azure CLI on your local machine.
  2. Install Docker CE on your local machine.
  3. Create a Docker Hub account or an [Azure Container Registry] (ACR).(https://docs.microsoft.com/en-us/azure/container-registry/container-registry-get-started-portal).
  4. Note your username and password for ACR or for Docker Hub. You'll need the credentials to push your Docker image to the repository. The ACR credentials are not the same as the credentials you use to log into the Azure portal.

Prerequisites (optional)

  1. If you are new to Docker, read the overview.
  2. Install Visual Studio Code (VS Code).
  3. Install the VS Code Azure Account Extension .
  4. Install the VS Code Docker Extension.

Instructions

How to Build the Base Docker Image

WHY? The base image takes several minutes to create. Waiting several minutes everytime you deploy your web site gets tedious. Instead I like to create a base image, and then I build my main image everytime I deploy. Because the main image is based on the base image, the main image is created in less than 30 seconds.

  1. Run docker build --rm -f "Dockerfile.BASE" -t t1agobacr.azurecr.io/drupal7:PHP7-base . (NOTE: include the period. If you are using Docker Hub and not ACR, remove t1agobacr.azurecr.io/)

t1agobacr.azurecr.io is the name of my Docker repository. Replace it with your repository name.

Visual Studio Code - Build (click here)

myimage

How to Build the Main Docker Image

  1. Edit line 1 of Dockerfile.MAIN. The FROM command should reference the base image name For example: FROM t1agobacr.azurecr.io/drupal7:PHP7-base
  2. Run docker build --rm -f "Dockerfile.MAIN" -t t1agobacr.azurecr.io/drupal7:PHP7-latest .
Visual Studio Code - Run (click here)

myimage

How to Run your Site Locally

  1. Run docker run --rm -it -p 2222:2222 -p 80:80 drupal7:PHP7-latest
  2. Open a web browser and navigate to http://localhost. You should see the Drual logo and the title "Select an installation profile"
  3. To get to the bash prompt inside of your now running container, in another terminal window, run: docker exec -it vigilant_elion /bin/sh

Replace vigilant_elion with the name of your running container. To see what containers are running and their names, run docker ps -a

If you successfully got to the webpage showing the Drupal logo, you can move to the next steps. Otherwise, it's time to troubleshoot.

  1. You'll now push (upload) both the base image and the main images to a container registery so that others, including Azure, can use it: Run docker push t1agobacr.azurecr.io/drupal7:PHP7-base . Again replace t1agobacr.azurecr.io with the name of your Docker repository.
  2. Now push the main image. Run docker push t1agobacr.azurecr.io/drupal7:PHP7-latest
Visual Studio Code - Push (click here)

myimage

How to Create Your Website In Azure

Prerequisite: complete the steps in the section above: How to Build the Base Image

  1. Open a command prompt to use the Azure CLI. First, login. For help, see here.

    az login

  2. Edit the following parameters and then copy/paste into the Azure CLI. Remove the $ in from each parameter if you are in bash. Keep the dollar signs if you are in PowerShell.

$SUBSCRIPTION="Your Subscription Name"
$RESOURCEGROUP="rg-smg-euwe"
$LOCATION="westeurope"
$PLANNAME="myappserviceplan"
$PLANSKU="B1"
$SITENAME="myappservice829601"
$RUNTIME="DOCKER|mycontainerregistryname.azurecr.io/drupal7_for_docker:base"
$IMAGENAME="mycontainerregistryname.azurecr.io/drupal7_for_docker:base"
$SERVERURL="https://mycontainerregistryname.azurecr.io"
$SERVERUSER="MyContainerRegistryUsername"
$SERVERPASSWORD="your password here"

Replace the values above with your custom values. For example, replace mycontainerregistryname with the name of your Azure container registery. Get your the SERVERUSER and SERVERPASSWORD from the Azure Container Registery section of the Azure portal. The RUNTIME and IMAGENAME should be identical except for the DOCKER|

To see a list all of the available subscriptions run az account list -o table

Pricing for the different plan SKUs is here.

To get a list of Azure locations (regions) where a particular VM size (sku) is avaialble run: az appservice list-locations --linux-workers-enabled --output table --subscription $SUBSCRIPTION --sku B1

List of potentially available regions for the LOCATION parameter: centralus, eastasia, southeastasia, eastus, eastus2, westus, westus2, northcentralus, southcentralus, westcentralus, northeurope, westeurope, japaneast, japanwest, brazilsouth, australiasoutheast, australiaeast, westindia, southindia, centralindia, canadacentral, canadaeast, uksouth, ukwest, koreacentral, koreasouth, francecentral

  1. Set the default subscription for subsequent operations

    az account set --subscription $SUBSCRIPTION

  2. Create a resource group for your application

    az group create --name $RESOURCEGROUP --location $LOCATION

  3. Create an app service plan (a virtual machine) where your site will run

    az appservice plan create --name $PLANNAME --location $LOCATION --is-linux --sku $PLANSKU --resource-group $RESOURCEGROUP

  4. Create the web application (app service) on the plan. specify the node version your app requires

    az webapp create --name $SITENAME --plan $PLANNAME --deployment-container-image-name $IMAGENAME --resource-group $RESOURCEGROUP Pulling and running your image may need some time. Add or update the setting: WEBSITES_CONTAINER_START_TIME_LIMIT = 600

  5. Add two new app configurations: az webapp config appsettings set -g MyResourceGroup -n MyUniqueApp --settings WEBSITES_ENABLE_APP_SERVICE_STORAGE=true

If the WEBSITES_ENABLE_APP_SERVICE_STORAGE setting is false, the /home/ directory will not be shared across scale instances, and files that are written there will not be persisted across restarts.

az webapp config appsettings set -g MyResourceGroup -n MyUniqueApp --settings WEBSITES_CONTAINER_START_TIME_LIMIT =600 Pulling and running your image may need some time. Add or update the setting: WEBSITES_CONTAINER_START_TIME_LIMIT = 600

  1. Configure the container information

    az webapp config container set --docker-custom-image-name $IMAGENAME --docker-registry-server-url $SERVERURL --docker-registry-server-user $SERVERUSER --docker-registry-server-password $SERVERPASSWORD --name $SITENAME --resource-group $RESOURCEGROUP

  2. FTP into your app service (aka web app) and update settings.php to reflect your Drupal database location. Instructions on how to FTP are here.

How to Deploy Code Changes to your Azure App Service

  1. Set up continuous delivery as described here.

Troubleshooting

  1. Turn on diagnostics inside of your app service. To do so, in the Azure portal, navigate to your app service. Under settings scroll down until you see Diagnostic logs.
  2. Full documentation is here.
  3. Read the FAQ.

About

Running Drupal 7.1 with PHP 7 as an Azure App Service

License:MIT License


Languages

Language:PHP 91.4%Language:JavaScript 4.9%Language:CSS 3.1%Language:Shell 0.5%Language:HTML 0.0%Language:Hack 0.0%