Introduction

Every now and then I was having issues with my WordPress on Linux App Service gallery application I had gotten from the Azure Marketplace. My plugins would disappear, my themes would break, and all my pictures would disappear. This article is to help users with issues like this, showing how to fix persistence issues for WordPress on Linux Azure App Services.

Explanation of Behavior

The reason that this issue occurs is due to the fact that the files are not persisted on the file system after restarts, moved to another worker, or other web app maintenance that Azure’s master node deems to be suitable for the web app. This makes it so that once there is maintenance on the web app, the cached data isn’t moved over properly. The posts are kept because they are stored on a SQL database (from my understanding).

Navigating to Kudu

Before configuring the web app to persist data, first you have to make sure that you backup your current WordPress site. This is because the setting you are going to change is going to wipe the web app and remove all WordPress content.

Before backing up your site, make sure that you have all the plugins, etc… installed.

In order to backup your current WordPress site, you’ll have to open Kudu on the WordPress application.
Kudu is a sort of dashboard to debug and connect to your app service. For more information on Kudu you can take a look at these links :
Video on Using Kudu From Microsoft
That being said, in order to access application’s Kudu please navigate to your app service > advanced tools > go.

This will bring you to the Kudu dashboard. From there, go to Debug Console > SSH.

Backing Up Your App Service

Now that we are in Kudu’s SSH console, we can start backing up the app service’s data. In the SSH Console run the following commands:
[code language=”powershell”]
cd /home/site/wwwroot
apk update
apk add zip
apk add ncftp
zip -r wwwroot.zip .
[/code]
Here we are basically going to the wwwroot for your wordpress site, and zipping up everything on the app service and putting it in the wwwroot directory.
Now that we have created a backup of our WordPress site, we still need to put it into our App Service deployment code. In order to do this, first we will need to get the username, password, and FTP site from the publish profile. To get the publish profile, go to your app service and press “Get Publish Profile” in the Azure portal.

Now go back to the SSH console that you got to through Kudu. Now use the code below, replacing YourUsername and YourFTPURL with your respective information retrieved from the Publish Profile :
[code language=”powershell”]
ncftp -u ‘YourUsername\$YourUsername’ <a href="ftp://waws-prod-bay-081.ftp.azurewebsites.windows.net">ftp://YourFTPUrl </a>site
[/code]
Enter your password, and then use the commands :
[code language=”powershell”]
cd site/wwwroot
put wwwroot.zip
[/code]
Now you should have successfully backed up your app service.

Configuring App Service to Persist

Note: Please make sure that you have backed up your app service properly. If you aren’t sure, please make sure to copy the content on your wordpress blog and back it up. This process is going to wipe your currently deployed app service.

Now that we have backed up our app service. We will have to configure our App Service to properly cache your data. In order to do this go to your app service’s app settings and simply configure the websites_enable_app_service_storage from false to true.

 
Now that we have configured this to true, save it.

Restoring Your App Service

This will now wipe your app service. Now when you go to your website now and it shows a default app service page. This is normal.
Reopen your Kudu SSH console, and unzip the file you zipped in the backup stage into your app service.
[code language=”powershell”]
unzip wwwroot.zip
[/code]
You have now restored the App Service and it will look like it used to.

Conclusion

We have gone through connecting to Kudu, backing up your app service, configuring your app service for persistence, and restoring your app service. Now your WordPress should be ready to go and your plugins won’t disappear again. If you have anymore questions feel free to post a comment or to open a support ticket with Azure, one of Microsoft’s Support Engineers will reach out to you to resolve the issue as soon as possible.
[poet-badge]