Steps to install WordPress on Azure Virtual Machine running Ubuntu

I have moved my blog to Azure Website for a while and I am quite happy with it. However, recently I have decided to move my blog to an Azure VM running Ubuntu.

I have to say Azure Website is very fast, convenient and easy to set up: you just have to create a new website, chose the WordPress template and go though the WordPress’s 5-minute setup. However, that require you to scale up to Shared, Basic or Standard plan (which cost at least 10 USD/month) to get some more advanced features such as setting custom domains. Besides, the free MySQL database by ClearDB provides you with only 20MB, and the cheapest upgrade is another 9 USD/month for 1GB (quite huge for my blog).

Recently, I happened to create a Ubuntu VM for my research. And most of the time the VM is idle. So instead of turning it on an shutting it down all the time to save cost, I decided to move my blog again to the VM, and buy a new domain for it: www.nguyenquyhy.com.

However, setting WordPress up on a Virtual Machine with Ubuntu 14.04 is not really as joyful as on an Azure Website. It cost me almost 3 days to solve all the issues, so I decided to note down all the steps I take here in case I need to move my blog again in the future, or someone else gets the same problems.

Setting Up LAMP (Linux-Apache-MySQL-phpMyAdmin)

To setup Linux, I just choose a Ubuntu images when creating the VM. No hitch here.

Setting up Apache, MySQL and phpMyAdmin is as simple as running

Enable phpMyAdmin (so that it can be accessed via yourdomain.com/phpmyadmin) by adding the following line to etc/apache2/apache2.conf

Setting Up WordPress

Again, we can use apt-get here

Most of the blog engine will be installed at /usr/share/wordpress and some common contents are put at /var/lib/wordpress.

You can copy the content inside /usr/share/wordpress into Apache web directory /var/www/html. However, I believe it is better to create a symbolic link inside the html folder.

This will allow your user to visit your blog by going to yourdomain.com/wordpress.

Change the owner of the WordPress directory to Apache user and group (you can check APACHE_RUN_USER and APACHE_RUN_GROUP in /etc/apache2/envvars) to enable uploading files, installing themes and plugins:

Copy the sample configuration file to create configuration for your domain

Add a new user and database to your MySQL server using phpMyAdmin

Modify config-yourdomain.com.php accordingly

Go to yourdomain.com/readme.html to see more or go directly to yourdomain.com/wp-admin/install.php to continue with the installation steps.

Change Apache config to allow visiting directly at yourdomain.com

Currently I do not have a website yet. So nguyenquyhy.com/wordpress or nguyenquyhy.com/blog are too complicated; featuring the blog directly at nguyenquyhy.com is better for now. And this can be done by some simple Apache configuration changes.

Duplicate default site config:

Change the blog.conf:

Disable the default site and enable the new blog site:

Change WordPress and Apache configurations to enable Permalink

Enable mod_rewrite in Apache

Enable Permalink in WordPress dashboard

Enable rewrite rules in .htaccess file in WordPress main directory:

Set Overrides All (to enable rewrite rules inside .htaccess file)

Migrate blog contents

Last time when moving my blog to Azure Website, I migrated my blog’s contents by duplicating the database and copying all the files using FTP. That turned out to be not so efficient for me because all the images pointing to the old domain (will not be a problem if you are using CDN of keeping the old domain and URL structures).

This time I happened to learn that WordPress already has a built-in import/export function. Using that function is also very simple, and you can easily modify the exported XML file before importing. Images and attachments can also be imported automatically.

Installing Plugins & Reconfigure Settings

Unfortunately, those things will not come with the built-in import/export tool. It cost me some time manually reinstall all WordPress plugins and reconfigure all the settings. However, if you do not move your sites very frequently, maybe it is a good time to review all your plugins and configurations.

Finally

So my blog is now officially move to www.nguyenquyhy.com (much better than nguyenquyhy.azurewebsites.net last time). I will start working on redirecting all the traffic from the old site to the new site, and that will probably have a separate blog post.

Some interesting read

https://help.ubuntu.com/community/WordPress

http://movingtofreedom.org/2007/05/09/how-to-wordpress-on-ubuntu-gnu-linux/

http://linoxide.com/ubuntu-how-to/easy-steps-installing-wordpress-on-ubuntu-using-apt-get/

https://www.digitalocean.com/community/articles/how-to-install-wordpress-on-ubuntu-12-04

http://codex.wordpress.org/Using_Permalinks

2 thoughts to “Steps to install WordPress on Azure Virtual Machine running Ubuntu”

  1. Hello,
    Nice post!.
    Can you tell me how did you point your new domain to your Apache on the new vm on Azure, I mean DNS part setup?
    Thank you,

    1. The specific steps depend on the DNS service you are using. Normally I would add a CNAME record pointing to the VM domain.

      I usually have 2 records like below

      • Host name: @. IP/URL: http://www.nguyenquyhy.com. Type: URL Redirect
      • Host name: www. IP/URL: ubuntu-hy.cloudapp.net. Type: CNAME

      The URL in the second record is the domain of your VM provided by Azure. For classic VM, you will get something like your_vm_name.cloudapp.net, and for newer VM with Resource Manager stack, the domain will be like your_vm_name.your_region.cloudapp.azure.com. You can check the exact domain of your VM in the Azure portal.
      This setup allows nguyenquyhy.com and http://www.nguyenquyhy.com to point to my VM.

      You may also want to replace that 2 records by an A (address) record instead, so that any subdomains can point to the same VM.

      • Host name: @. IP/URL: xxx.xxx.xxx.xxx. Type: A (address)

      xxx.xxx.xxx.xxx is the public IP address of your VM (can also be seen in the Azure portal). However, make sure that you have already purchased a static public IP address in Azure, or your domain will point to the wrong place once your VM’s public IP address changes.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.