QGIS Server on EC2

feature-image

I’ve always followed QuantumGIS (recently QGIS) but only after the last release, 2.0 Dufour, I decided to use it as my main GIS software, at home.

I even participated to a QGIS workshop at GFOSS DAY 2013, and I was really impressed by QGIS easy web-mapping capabilities, through Lizmap plugin.

While recently many web-mapping services, such as ArcGIS online, CartoDB or Mapbox, are giving everyone the web-map experience, I wanted to go hardcore and put up my own web server. In order to do that without spendig lots of money, I found out about AWS free options, but I recently I got a 0.41 cent billin.

So, First thing first, you wanna start running a ec2 micro instance on AWS.

Go to the web-site and follow instruction.
Select the “Free tier only” flag on the left pane.
Then select Ubuntu 12.04, I was only able to have this thing running so I accept any review to the article for a better understanding.
On “Step 5: Tag Instance” For the instance tag, I simply selected “GeoServerTest”
On “Step 6: “Configure Security Group” Just be sure to add SSH, HTTP and HTTPS to the protocol options and leaving the parameters untouched, they come andy to log into the remote server and do cool stuff…
When presented create a new security key and save it to a folder, I choose to save the .pem file into Documents\ec2 for the name, I didn’t get creative and used “GeoServerTest”
Finally, cross your fingers and press launch Instance

[REFERENCE]

At this point you should be able to view your instance running…then what??
Now we need to ssh into the instance and install some GIS software.
In order to ssh from the terminale, you want to highlight the instance in AWS control panel and copy “Public DNS”, something that looks like this:

ec2-54-xxx-xx-xx.eu-west-1.compute.amazonaws.com

Now that you now where to ssh, don’t wait and open the terminal!
navigate to the folder with .pem file

cd Dcuments\ec2

before using .pem file you need to change file permission using this command

chmod -R 700 GeoServerTest.pem

[REFERENCE]

Now you can finally ssh into your instance typing:

ssh -i Geoserver5.pem ubuntu@ec2-54-194-39-18.eu-west-1.compute.amazonaws.com

and then you wanna make sure everything is up to date typing:

sudo apt-get update

Then you need all the pretty little thing that make run on a server, so go ahead and type:

apt-get install apache2 php5 curl php5-curl php5-sqlite php5-gd

It’s now time for the first test, go to your browser and enter your instance address:

ec2-54-XXX-XX-XX.eu-west-1.compute.amazonaws.com

The answer should be pretty straightforward:
It works!

To install the sweet GIS pieces, you need to add a repository, with this line:

sudo add-apt-repository ppa:ubuntugis/ubuntugis-unstable

After that you can update:

sudo apt-get update

And install qgis on the server:

sudo apt-get install qgis

And then the map-server:

sudo apt-get install qgis-mapserver libapache2-mod-fcgid

Now we need to move to the var/www folder to install the lizmap-web-client

MYAPP=lizmap-web-client
VERSION=2.9
wget https://github.com/3liz/lizmap-web-client/archive/$VERSION.zip

Ok, now we need to unzip the file and so…we need to install unzip capabilities to the server:

sudo apt-get install unzip

Unzip the software:

unzip $VERSION.zip

Delete the temporary archive:

rm $VERSION.zip

and move deep into the client folder:

cd /var/www/$MYAPP-$VERSION
chown :www-data temp/ lizmap/var/ lizmap/www lizmap/install/qgis/edition/ -R
chmod 775 temp/ lizmap/var/ lizmap/install/qgis/edition/ -R

Now you can type in your browser address bar :

http://ec2-54-XXX-XX-XX.eu-west-1.compute.amazonaws.com/lizmap-web-client-2.9/lizmap/www/

and see the example page.

[REFERENCE]

Assuming you created a map on QGIS and then prepared the necessary files using LizMap, you are now ready to publish a map.

[REFERENCE]

You need to use a FTP software, such as Filezilla.
Open it, go to preferences select SFTP from the left panel, press “Add key..” button and select your .pem file, It will ask you to transform in a different format, continue and save the file on the usual ec2 director.
Create a new connection, enter the server public DNS, use ubuntu as user, select SFTP as connection type and normal, don’t enter any password.
[REFERENCE]

You may think that this is it but, if you try and upload the map files, you’ll get a permission error.
Enter the terminal and ssh into the running instance, create a folder to host the files:

mkdir var/www/maps

Take care of the permissions:

sudo chown ubuntu:ubuntu /var/www/maps

this will allow Filezilla to transfer files.
[REFERENCE]