There are multiple options to hosting your Content management solutions (CMS) like WordPress , Drupal , Magento etc. with Linux App Service . The blog post below will cover the key decisions and implementation guidelines when using Web App for Containers for a CMS solution like WordPress or Drupal.
Built images :
App Service team provides your bare bone docker images for PHP , and other frameworks. These images are very basic and help you quickly get started but as your apps grows , these images may be limited to your needs as you are limited from making any changes to these images .
Custom images :
Custom docker images provides you with more flexibility to grow as your apps grows. You have more control on the docker image itself and can modify it with new modules or extensions if and when your app needs these changes . This option make lift and shift of your application more easy since you can replicate you current dependencies as close as possible in the cloud. Checkout an example of using a Python Application with a Custom image.
The recommended approach is using custom images with Web App for Containers when using a CMS solution.
App Service come with a shared file storage . You must use this storage if :
- The application writes to the file system frequently and needs these files to be persisted.
- You want to use auto-scaling features and you want all the instances to share the same file storage
In order to use the App Service Storage , explicitly include an app setting
WEBSITES_ENABLE_APP_SERVICE_STORAGE = true
To better understand this , let me elaborate with an example : If you have a WordPress app , note that WordPress CMS installs minor version updates to make sure your app has any important fixes needed. This means new files being added or existing files being modified to your application. In such cases , the application needs the files to persist so that you have the latest patches/fixes for WordPress hence this scenario requires the use of App Service Storage .
Most CMS solutions have a variation of this type of application updates . Have a better understating of your application to decide if you want to use App Service storage.
Can I use local storage instead of App Service Storage for CMS solutions
By using the local storage rather than App Service Storage you do get better stability and there is less impact if the app service storage has issues. To use local storage , set the app setting
WEBSITES_ENABLE_APP_SERVICE_STORAGE = false
Lets use WordPress as an example here again. You can use local storage for WordPress app , but this requires a few changes in your code and how the application is used. Here are a few things you would need to do :
- Turn off auto update for WordPress
- Manually deploy the latest WordPress code updates with your docker image
- Do not install plugins , themes etc. from production site’s WordPress administration dashboard
For other CMS solutions like Drupal , Joomla etc ; you need to understand if there are options on turn on auto-update . The steps #2 and #3 mentioned above will still apply to any other application. This is a key decision to make before taking the next step.
There are many deployment options available for your custom images:
- Continuous Delivery with VSTS
- Continuous Deployment with Azure Container Registry (ACR) or Docker Hub
Choose a deployment option
There are two common terms with deployment as seen above :
- Continuous Deployment : Every change made to your docker image is pushed out to production automatically.
- Continuous Delivery: Provides you with a deployment release pipeline. This solution does not mean your code is pushed to production automatically . The goal here is to build a process that can allow code to be deployed any time . Most Continuous Delivery processes include automated tests and criteria that needs to be met before the changes go to production.
Based on your needs , pick either Continuous Delivery which we provide using VSTS or Continuous Deployment with ACR/DockerHub.
Can I deploy my code via GIT
You can have your application source code as part of the docker image or you can have the application code on a git based repository and your docker image on ACR or Docker Hub . Continuous Delivery with VSTS supports both these scenarios.
If you are not using Continuous Delivery with VSTS , the other option you have is Continuous Deployment feature that support GitHub, Bitbucket, Local GIT etc.
Note :You must use App Service Storage for your files if your application code is separate from your docker image and you choose to deploy the source code separately than the docker image. If your application code is large , there may be some issues with Git deployment for such apps. In those cases use Zip deploy API
Planning Migration or setting up a new site
The question listed below should help you make the key decisions before implementing a migration of an existing site or setting up a new site:
- Should I use a built in image or customer image ? Review your dependencies or requirements to answer this question
- Should I use App Service Storage or Local Storage ? Does the app need file persistence ?
- Do I need to run the app on multiple instances with auto-scale or Can I run the app on single instance ? When running in single instance , you can include local mysql , local redis etc without having to use a cloud service for MySQL and Redis . Note to use Local mysql you need file persistence
- What deployment strategy works best for this application ? Keep in mind to choose an option that helps make deployment even after the site is in production. This will provide a stable , repeatable deployment process.
- What external dependencies are needed ? Do I need a cloud based service for my database , twitter/Facebook API etc .
Migration of an application from On-premise or other cloud solution providers can be challenging tasks. Here is migration process that is articulated for Web App for Containers.
- Identify your application dependencies on premise or local development machine . Such as , webserver , php version , php extensions , web server modules etc . If you are using apache server with say php , you can build a custom image with apache server , php etc to run on Web app for containers. If you are using nginx in your current architecture , you can build a custom image with nginx for web app for containers.
- Identify external dependencies like Database , Redis cache , CDN etc. Find appropriate solutions for these external dependencies in Azure
- For CMS solutions always build a Custom docker image based on the dependencies you identified from the above step. You can find many samples here to help get started . Enable SSH in your docker image which can help as a tool to debug your app.
- Create a Web App For Container from Azure portal
- Create your external dependencies with the appropriate solutions available in Azure . For example , if your app needs MySQL you can use Azure database for MySQL for better reliability and performance
- Make the decision to use Local storage or App Service Storage. To use App Service Storage , edit the app setting WEBSITES_ENABLE_APP_SERVICE_STORAGE = true
- Select a deployment option for your application : Continuous Delivery or Continuous Deployment or Git Deployment. Deploy your code to the application and make sure the application code is updated appropriately to use the new dependencies for database , cdn etc in Azure
- Browse your application once deployed
- Turn on Diagnostic logs to view your docker logs to investigate any issues if you don’t get the expected results. Troubleshoot your application further using SSH .
- Tweak your Docker image as needed to resolve any issues . Reiterate the process from step 7 .
If you are still unable to resolve any issues for a given step or have questions , reach out via support forums to get help.
Setting up CMS solution on Web App for Containers
ü Create a Web App using Web App for Containers using Nginx-fpm and Drush CLI toolThis image does not have Drupal source code as part of the image. Note : When using your custom docker image , make sure it is available in either Docker Hub or Azure Container registry as a private or public repository . Make sure you application has SSH enabled which can help in troubleshooting.
If you are planning to migrate a WordPress or Joomla or Moodle CMS solution , the process is exactly the same except for the custom image you plan to use . Here are some samples you can use :
There are multiple bake some caching into your docker image , such as using PHP ‘s caching options such as :
- Server level caching based on which web server you are using leverage any modules or configuration that can help boost performance.
- Framework level caching such as PHP supports various options for caching
- Using Compression , for example including mod_deflate apache module helps with boosting performance on your application running on Apache web server by reducing the bandwidth on the file and reduces load on the server . This differs based on your web server
- Enable back-end database caching using Azure Redis Cache service. If you are not using auto-scale feature with web app for containers , you can run a local redis baked into your docker image. Note this will only work if your app is running on one instance
- Add a CDN to boost performance of your app.
Here are a few other configurations you can add to you application