Learn how to deploy your Web Application & Database Server to Microsoft Azure.
The decision was made to deploy your work/app to Azure1, now you have the task of making it happen.
A Step-by-Step guide to deploying your first app on Microsoft Azure.
The first part of this guide focusses on getting a Linux Virtual Machine
launched on Azure.
You can then deploy what ever you like to it
and it will work similarly to other cloud providers.
After that we move on to deploying a Phoenix Web Application (because that is our chosen technology stack @dwyl) but the process is the same for any stack.
Developers who need to deploy to Azure because their client/employer requires them to. If you have no prior "Cloud" Infrastructure experience, you will have no expectations or pre-conceptions.
If you don't already have an account on Azure, go register for one now! /register-for-azure-account.md
Visit your Azure Dashboard: https://portal.azure.com
The Azure Tutorial(s) all assume you have the CLI installed. e.g: https://docs.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-manage-vm I'm doing a step-by-step GUI tutorial instead because it's way more beginner friendly!
16.04 LTS
Virtual Machine16.04 LTS
You should then see a screen similar to this:
phoenix-prod-1
(useful if you end up having a cluster of several machines later on...)azure
(they don't let you have the username root
even though which ever username you do pick here has root priviledges
!... I use azure
so it's clear which platform my VM is hosted by/on.)SSH public key
(obviously more secure than password)pbcopy < ~/.ssh/id_rsa.pub
phoenix-cluster
West Europe
(pick what ever is closest to your end-users)Select the cheapest VM available and then click the "Select" button.
Confirm the settings for your new instance (leave the defaults they are fine):
Click on "OK" to confirm.
nothing.else.is.available@outlook.com
Once you have confirmed the details, click "OK" to launch your instance.
Now Wait ...
Sadly, Azure takes some time to launch. Go re-fill your water bottle. ;-)
Make a note of the IP address of the instance so that you can login to it in the next step. Ours VM's IP Address is: 52.232.127.28.
In our case the user for the server
(which we defined in step 4.3 above) is azure
and the IP address of our VM/instance is 52.232.127.28
.
So we login using the following command
ssh azure@52.232.127.28
You will be asked to confirm you want to continue connecting. Type Yes and then [return].
In order to allow inbound TCP traffic into the instance
From the Azure Dashboard, Select "Virtual Machines" then click on your Machine:
Once you are viewing the details for your VM:
Next you will setup a Firewall rule for the VM.
After completing the preceeding step, you will see the network security group Overview.
Click on the (nonsensical) button to Create a new inbound security rule.
Then you will see the "Inbound Security Rules" where you can click on the "+ Add" button:
You should now see the rule in the Inbound security rules list:
While logged into the remote machine (the azure VM) run the following three commands:
sudo apt-get update
sudo apt-get install nginx -y
sudo service nginx start
sudo service nginx status
You should see: Then: Then:
Now visit the IP address for your VM in a browser (in our case: http://52.232.127.28/) and you should expect to see the following:
After you've tested with NGINX, if you prefer to remove it (because you don't need it for serving your app) see: https://askubuntu.com/questions/235347/what-is-the-best-way-to-uninstall-nginx
Before deploying your app to the Azure Instance, shut down NGINX (if you still have it running from "Part 1")
sudo service nginx stop
For deploying a Phoenix Framework Web Application, see:
TODO: Link to
advanced-deployment.md
once PR containing instructions is merged!
~/.profile
File on Azure Instance to set TCP Port for PhoenixYour Phoenix Web Application expects to have an environment variable
defined for the TCP PORT which the app will listen on.
In our case we are going to stick with the default and use 4000
.
Run the following command to append the line
export PORT=4000
to your ~/.profile
file:
"echo export PORT=4000" >> ~/.profile
Then run the following command to ensure that ~/.profile
file is loaded:
source ~/.profile
You can confirm that the PORT
environment variable is now define on the VM
by running the printenv
command:
printenv
On the Azure Instance run the following command:
sudo iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 4000
To confirm the routing from port 80 to 4000 run the following command:
sudo iptables -t nat --line-numbers -L
Now when you deploy the app to this instance
it will "listen" on PORT 4000,
but the Firewall will re-route http
requests from port 80
to 4000
.
Once you have configured your Phoenix App to deploy using Edeliver,
simply update the settings of your .deliver/config
file to
to the VM IP Address and username of your Azure instance:
PRODUCTION_HOSTS="52.232.127.28"
PRODUCTION_USER="azure"
DELIVER_TO="/home/azure"
Once you have updated the .deliver/config
file with the Azure VM details,
run these two commands from inside your Phoenix Project (on your local machine):
mix edeliver deploy release to production
mix edeliver start production
You should expect to see the following output:
Visit your app by IP Address in your Web Browser. e.g: http://52.232.127.28
We are still pending a decision on this feature ... see: https://github.com/dwyl/learn-microsoft-azure/issues/5
1See: /tldr.md