Welcome to the part 2 of the tutorial How to run blazingly fast WordPress on Microsoft Azure. In the first part, we discussed setting up a Virtual Machine on your Azure account. And in this post, we will see how to connect to your server and start downloading and installing WordPress on it.
Install & setup WordPress on Microsoft Azure
This post will include a lot of terminal commands, so please try to follow the tutorial step by step and try not to skip any step.
Setting up your server
Step 1: To communicate with your virtual machine, you need to establish an SSH connection and use an SSH client.
What is SSH?
According to Wikipedia, Secure Shell (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. The best known example application is for remote login to computer systems by users.
We are using PuTTY, a free SSH and telnet client in this tutorial. So for this step, you are required to download and install PuTTY from here.
Step 2: Login to your Azure panel, open the virtual machine, we created in the first part and hit ‘Start’. Then click on ‘Connect’ to start the connection. Now a pop-up will display your username and the public IP address of your machine. Copy the entire SSH hostname (e.g. [email protected]). You may click on the images to see the larger version.
Now open PuTTY and paste this hostname in the Host Name field and select connection type as SSH and hit open with all other settings as default. A new terminal window would open and will prompt you for the password. Enter the password that was chosen in part 1 while creating a virtual machine. Now you are finally connected to your virtual server over an SSH connection. All you need to do now is enter some commands in this terminal window to install proper software and WordPress.
Step 3: First of all, you need to make sure that all the packages on your installation of Ubuntu are up to date. Run the following command to update them:
sudo apt-get update
Now we’ll install Apache, a free HTTP server software. Basically, Apache will be the one listening to someone’s request to display your website’s content. Read more about Apache here. Run the following command to install Apache:
sudo apt-get install apache2
Now navigate to the directory where Apache’s configuration file is saved and open it using the text editor.
sudo nano /etc/apache2/apache2.conf
At the end of this file add the following line:
Restart the Apache service:
sudo service apache2 reload
And grant permissions to Apache by executing the following command:
sudo ufw allow in “Apache Full”
Installing MySQL and PHP
Step 4: Execute the following commands in order to install MySQL and PHP on Ubuntu:
sudo apt-get install mysql-server
Choose an appropriate MySQL root password and hit ‘Enter’.
sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt php5-mysql sudo apt-get install php5-cli sudo apt-get install php5-gd libssh2-php
PHP files are to be given more priority than the HTML files, so we need to alter another configuration file:
sudo nano /etc/apache2/mods-enabled/dir.conf
Now in this file, move “index.php” so that it comes before “index.html”. Restart the Apache server.
sudo service apache2 reload
Creating a MySQL database
Step 5: Follow the commands:
mysql -u root -p CREATE DATABASE test DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci; GRANT ALL ON test.* TO ‘tester’@’localhost’ IDENTIFIED BY ‘testpwd'; FLUSH PRIVILEGES; Exit;
Step 6: This is actually the step that downloads WordPress. Navigate to the root directory and then download and extract WordPress.
wget http://wordpress.org/latest.tar.gz tar xzvf latest.tar.gz
Navigate to the WWW directory where all the website files are stored and copy the entire contents of the WordPress here in a new folder of your choice.
cd /var/www sudo mkdir twcwp
Now create the wp-config.php file by creating the copy of sample configuration file and then copy the entire contents of the downloaded folder into the ‘wordpress’ folder in the www directory.
cp ~/wordpress/wp-config-sample.php ~/wordpress/wp-config.php sudo rsync -avP ~/wordpress/ /var/www/twcwp/
cd /var/www/twcwp/ sudo nano wp-config.php
Enter the database details we created in previous steps and save the file. (see screenshot below for reference)
Step 7: Now for the final step, we need to configure apache so that it knows there is a website running under our “twcwp” folder. We need to navigate to the available sites folder and create a new file called ‘twcwp.conf’ which is similar to the default configuration file.
sudo chown www-data:www-data * -R cd /etc/apache2/sites-available sudo cp 000-default.conf twcwp.conf sudo nano twcwp.conf
In this file alter the following lines
- ServerAdmin your_email_adress
- ServerName twcwp.com
- ServerAlias twcwp.com
- DocumentRoot /var/www/twcwp
ServerAlias should be the domain name you’ve registered (in our case we’ve not registered the domain name but we are just using it for reference).
Execute these final set of commands:
sudo chown -R twctestingadmin:www-data * sudo mkdir /var/www/twcwp/wp-content/uploads sudo a2ensite twcwp.conf sudo service apache2 reload
Here “twctestingadmin” is the username of admin account on our virtual machine and “twcwp” is the directory that contains WordPress files. You can replace these strings with your details.
And this is it, now you have a fully functional virtual machine running on Microsoft Azure that is hosting your WordPress website. All you need to do is now configure your DNS records so that the website points to the public IP address of the virtual machine.
If you want to temporarily run your website, you can edit the Windows hosts file and add an entry that will map the public IP address to the domain name temporarily. (see screenshot for reference)
The tutorial is pretty long and involves a lot of steps. You may feel free to ask any questions in the comments section below and we will be happy to help you out. Some terms used in this post may seem new to you, you can Google search them or just drop a message in comments.
Also, I would like to introduce you to the two personalities who brought us this wonderful Workshop in the Chandigarh area:
- Jasjit Chopra
- Divyadeep Sawhney
The workshop was collectively conducted by Microsoft Users Group Chandigarh and WordPress Chandigarh. You can get in touch with both the groups on Facebook and look for upcoming meetups in Chandigarh area on meetup.com.
How do I create a WordPress site on Azure?
To create a WordPress site on Azure, you need to follow the aforementioned guide. The summary of the process is like any other setup process. In other words, you need to create a server, upload your files, and set things up as per your requirements. However, it is recommended to follow all the above-mentioned steps minutely to get things done without any error.
Can I host WordPress on Azure for free?
No, you cannot host a WordPress site on Azure for free. However, Azure offers a free trial that you can use to test your site. Following that, you need to opt for paid plans to get started with the project.