We’re going to walkthrough how to set up a LAMP stack from scratch, install further dependencies for DKAN, and set everything up for actually installing the platform.
Choosing your Server
The vast majority of the web is contained in third-party servers from companies like, Amazon, DigitalOcean, and Google. For a relativly low cost you can spin-up a virtual server inside one of their massive data warehouses. For most of my projects I use DigitalOcean, mainly because their' VMs are easy to set up, the user interface on their site is nice and simple, and it’s only $5 a month for simple server. Amazon and Google also have a similar products for around the same price, but I like to stick with DigitalOcean (they’ve been doing this sort of thing for ages, and they always look out for little developers).
Using your own Hardware
Saying all that, feel free to set up your own server in-house. I won’t be walking through how to install any of the physical hardware (you’ll have to do that on your own), but the rest of the steps will be pretty much the same.
Installing a LAMP Stack
A LAMP stack is a group of open-source software (Linux, Apache, MySQL, PHP) that all work together to make an excellent web server. LAMP is the default server configuration for about 50% of the internet, but that is decreasing over time with the rise of LEMP stacks (I’ll get into LEMP in another post). We’ll be using Ubuntu 16.04, Apache2, MySQL, and PHP7 for our stack.
This section closely follows the guide created by Brennen Bearnes over at DigitalOcean, with a few personalisation changes along the way.
This guide assumes you have your user accounts and firewall already set up. I won’t go into details on how to do this, but you can follow this guide by DigitalOcean.
SSH into your server.
Update the available packages on your system, and install
sudo apt-get update sudo apt-get install apache2
Tip: When running certain commands (like
remove), Ubuntu will ask you to confirm the installation. So if nothing much is happening in the terminal, just check that you’ve confirmed by entering
sudo ufw allow in "Apache Full"to adjust the firewall to all web traffic.
dkan@server:~$ sudo ufw allow in "Apache Full" [sudo] password for dkan: Rules updated Rules updated (v6)
- You should now be able to view the default apache web page by visiting your server address:
- If you don’t know what your IP address is run:
sudo apt-get install curl curl http://icanhazip.com
It should output the IP address of your server:
dkan@server:~$ curl http://icanhazip.com 126.96.36.199
So that’s the Apache service installed. Now let’s get MySQL sorted.
If you don’t already know, MySQL is the database system that DKAN is going to run on. While you don’t have to be fluent in MySQL to run DKAN, knowing a few basic commands can prove useful. I’d suggest taking a look at W3Schools' SQL tutorials when you get a chance.
- Download and run the installer
sudo apt-get install mysql-server mysql_secure_installation
- Enter a password for your root MySQL account. I recommend using a password manager to generate and store your passwords.
nwhen asked if you want to install the
VALIDATE PASSWORD PLUGIN.
nwhen asked if you want to change the root MySQL password.
yfor the rest of the questions.
dkan@server:~$ mysql_secure_installation Securing the MySQL server deployment. Enter password for user root: VALIDATE PASSWORD PLUGIN can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD plugin? Press y|Y for Yes, any other key for No: n Using existing password for root. Change the password for root ? ((Press y|Y for Yes, any other key for No) : n ... skipping. By default, a MySQL installation has an anonymous user, allowing anyone to log into MySQL without having to have a user account created for them. This is intended only for testing, and to make the installation go a bit smoother. You should remove them before moving into a production environment. Remove anonymous users? (Press y|Y for Yes, any other key for No) : y Success. Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network. Disallow root login remotely? (Press y|Y for Yes, any other key for No) : y Success. By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment. Remove test database and access to it? (Press y|Y for Yes, any other key for No) : y - Dropping test database... Success. - Removing privileges on test database... Success. Reloading the privilege tables will ensure that all changes made so far will take effect immediately. Reload privilege tables now? (Press y|Y for Yes, any other key for No) : y Success. All done!
PHP: Hypertext Preprocessor is the backend language that DKAN runs off. All the login and data management is written in PHP, so I’d advise that you familiarise yourself with it’s syntax at some point. Again, W3Schools has a great tutorial you can follow.
- Install PHP and it’s dependencies:
sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql php-dom php-xml php-mbstring php-gd
- Next we want to tell Apache to look for
.phpfiles before looking for .
/etc/apache2/mods-enabled/dir.confin a text editor. I tend to use Vim, but you can use Nano or some other editor if you prefer.
sudo vim /etc/apache2/mods-enabled/dir.conf
- Change the 2nd line to read:
DirectoryIndex index.php index.html index.cgi index.pl index.xhtml index.htm
- Save and exit the file. If you are using Vim press
escand then type
:wq, then press
sudo systemctl restart apache2
That is the final step. You should now have a fully functioning LAMP stack running on your server. You can now visit your website in your browser.
DigitalOcean offer pre-built Stacks, so you can click and single button and you’ll get a fully-fledged LAMP stack up and running in seconds. If you want to learn more about how to create a LAMP stack from scratch then I’d recommend not using this option. However if you don’t really care about learning how to build a LAMP stack, then by all means use the pre-built option! Select LAMP on 16.04.