Configure FTP And Use Custom Domain On Azure VM

In my previous article,

We learned to setup Linux VM in Windows Azure. We have also learned how to install LAMP, configure and tune Apache and MySQL. Now we are going to see how can we setup FTP to upload and manage the files on our Server and how we can use our custom domain.

Login to the Azure Management Portal.

Let’s setup our system for FTP access.

FTP (File Transfer Protocol) is probably the most popular method of uploading the files to the Server. A wide array of FTP Servers, such as ProFTPD and the clients exist for every platform.

Add endpoints to your VM

Add a new endpoint on the portal, navigate to the Virtual machine, <your_virtual_machine>, Endpoints if you are using plain FTP, i.e. port 21, else SFTP will be on port 22. I am using FTP here.

endpoints

We also need to add a few arbitrary endpoints that the VM will use for connecting. The more we add, the more concurrent FTP connections you’ll be able to open. For the sake of argument, let’s add these ports; 49153, 49154, 49155, 49156 & 49156 for FTP-Passive2 onwards.

endpoints

Now, we are done with the Endpoints. Thus, let’s install ProFTPD to our VM.

Open PuTTY and log in to your VM by using your settings, done in the previous post.

Now, move to the elevated command line. Use “ sudo su “ command.

First, I will follow a simple best practice: ensuring the list of the available packages, which is up to date before installing anything new.

Run “apt-get update ” command.

Now, let’s install ProFTPD and any required packages.

Run “ apt-get –y install proftpd ” command.

You will get this screen during the installation process:

process

Select “ Standalone “ and then hit enter to finish the installation.

Configure ProFTPD

ProFTPD is now installed. Now, it's time to configure. Let’s edit the configuration file for ProFTPD:

Run “ nano /etc/proftpd/proftpd.conf ” command.

We need to enable those Passive ports that we added to the VM instance. Inside Azure control panel (change the range accordingly to your port selection), we also need to add the public DNS of the VM to the Masquerade Address. (Ref. Passive Ports & Masquerade Address):

Add These lines in the file

  1. PassivePorts 49153 49157

    MasqueradeAddress <your_public_dns>.cloudapp.net

    command
After these changes, make sure to restart ProFTPd

Run “ service proftpd restart ” Command .

Now set the ProFTPD service to start at boot,

Run “ update-rc.d proftpd defaults ”

Let’s try to connect using FileZilla now,

You can download FileZilla client from here.

Now fill your details in Quickconnect, as given in the screenshot, below:

screenshot

Congratulations! You are connected to your VM. 

Now It’s Time for Domain Setup

Let's say you have a website and you want it to be served from your Server. You need to create something called “Virtual Host” in Apache’s term. It is equivalent to IIS Website.

In this tutorial, we are taking “CONNECTTUSHAR.COM” as our domain.

Now, log In to PuTTY Window, using your credentials.

Now Move to elevated command line. Use “ sudo su “ command, and Start.

First, create the folder where all the files for our website will reside:

mkdir -p /var/www/connecttushar.com/public_html

If we want our regular user to modify the files in our Web directories, we can change the ownership by executing this command. The $USER variable will take the value of the user; you are currently logged in as, when you press enter.

chown -R $USER:$USER /var/www/connecttushar.com/public_html

By executing this command, our regular user now owns the public_html subdirectories, where we will be storing our content.

Let’s modify our permissions a little bit to ensure that read access is permitted to the general Web directory in addition to storing all the files and folders in it.

chmod -R 755 /var/www

Now, let's create sample configuration for the Website :

cp /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-available/connecttushar.com.conf

Edit the /etc/apache2/sites-available/connecttushar.com.conf file to configure the virtual host with the correct configuration, using nano:

nano /etc/apache2/sites-available/connecttushar.com.conf

Add this snippet with your domain name in it,

ServerAdmin [email protected]
ServerName connecttushar.com
ServerAlias www.connecttushar.com
DocumentRoot /var/www/connecttushar.com/public_html
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow, deny
allow from all
</Directory>

command

We have changed the occurrences of AllowOverride to AllowOverride All. This will come handy, when we will setup a .htaccess file.

Now enable the Website

a2ensite connecttushar.com
a2dissite 000-default

Lets enable some modules

a2enmod rewrite
a2enmod headers
a2enmod expires

Now, restart Apache.

service apache2 restart

If “apache2 can not reliably determine the Server's fully qualified domain", the warning comes.

warning

Then open Apache config,

nano /etc/apache2/apache2.conf

Add this line to the file,

ServerName connecttushar.com

Save by pressing Ctrl+X , Y and click enter.

Now restart Apache and again type,

service apache2 restart

Let’s verify the site, which is configured properly.

grep –R AllowOverride /etc/apache2

Your output will resemble, as shown below:

output

Now, go to your domain control panel.

Mask your VM’s Virtual IP address to the domain.

domain

Now, you can use http://connecttushar.com on the Browser and it should show:

browser
This means, we have the virtual host configured and the domain is working.

Conclusion: In this article, we have taught you to set up FTP for your VM and how to configure the custom domain for your VM.