Setting Up WordPress With An Azure VM

This guide will walk though setting up a WordPress site using an Azure VM. Some of the perks of doing this are:

  • Cost-wise, you can spend as little as ~$8 a month to get a fully functional WordPress site running. If you try using MySQL and App Services in Azure, you’ll looking to spend ~$40 a month for worse specs.
  • You can scale the site up as needed if performance demands arise.


Step 1: Create An Azure VM

First, create an Azure VM with the following specs:

  • Image of Ubuntu 18.04 LTS
  • Size of B1s (anything less and you’ll run into issues)
  • Azure Backup (optional, provides a means to restore VM from scratch)

Once the VM is set, set the following Network Security Group rules:

  • Public Access – ports 80/443
  • Private Access (such as your IP address) – ports 22/3306

Step 2: Set up LAMP Server

SSH into the server and install a LAMP server with the following:

sudo apt update && sudo apt -y install lamp-server^ php-curl php-dom php-mbstring php-imagick php-zip

After installation, verify correct installation:

apache2 -v && mysql -V && php -v

Step 3: Configure MySQL

Run the following:

sudo mysql_secure_installation

Do the following:

  • Install the Validate Password Plugin at “Medium”
  • Say yes to all options except “Disallow root login remotely”

Run a query to allow access:

sudo mysql -u root -p



Edit the file /etc/mysql/mysql.conf.d/mysqld.cnf and comment out the bind-address line.

Restart MySQL:

sudo service mysql restart

Finally, test connecting to the database server using a tool like MySQL Workbench. When connected to the database server, do the following:

  • Create a DB (either copied from a migration or a fresh database)
  • Create a user that has access to the DB above.

Step 4: Install WordPress

Download and unzip WordPress into /var/www/html:

sudo tar -xzf latest.tar.gz -C /var/www/html --strip-components=1

Configure /etc/apache2/apache2.conf and allow AllowOverride to All in the /var/www directory.

Set the correct permissions for Apache:

sudo chown -R www-data:www-data /var/www/html
sudo find /var/www/html -type d -exec chmod 755 {} \;
sudo find /var/www/html -type f -exec chmod 644 {} \;

sudo a2enmod rewrite && sudo systemctl restart apache2

As a final step, delete the index.html file from Apache:

sudo rm /var/www/html/index.html

You should now be able to run the WordPress installer and connect the database.

Once the WordPress Installer has run, log into the backend and check the site health to see if there are any misconfigurations within the system:

Optional Steps

Setting Up SSL With Let’s Encrypt

Before setting up SSL, you’ll need to set up a domain and set the appropriate DNS settings to be able to run the Let’s Encrypt process.

Enable SSL and restart Apache:

sudo a2enmod ssl && sudo a2ensite default-ssl && sudo systemctl reload apache2

Run the commands provided by CertBot.

Enable Mail

The easiest way to enable mail is to use the WP Mail SMTP plugin. Once configured, you can use the plugin to set up alongside the email carrier of choice and test the submission functionality.

Increase Upload Size

To increase upload size (for things like uploading themes/plugins/media), edit the /etc/php/7.2/apache2/php.ini file:

upload_max_filesize = 16M
post_max_size = 16M

Then restart Apache:

sudo service apache2 restart

Restore from a Backup

If opted into backup when creating the VM, the VM will have an automatic daily backup progress that you can use to restore the VM at any point.

To restore a new VM, access the Recovery Vault and go to Backup Items -> Your VM Name -> Restore VM. Once you go this, you have two options:

  • Completely create a new VM with the data restored.
  • Restore the disks into your current VM (VM must be turned off to do this).

Leave a Reply

Your email address will not be published. Required fields are marked *