Recommended VPS Complete list of best VPS hosting providers.

How to Install Apache, PHP and MariaDB on Ubuntu 15.04


This is a quick and clear version of how to build a working LAMP server to host your websites with it. As a refresh, LAMP stands for Linux, Apache, MySQL and PHP which in this guide we’ll replace it with MariaDB that is faster than traditional MySQL server. As what I can remember, I wrote about LAMP installation on CentOS 7 already but never write the same thing for new Ubuntu version which is now version 15.04 codename Vivid Vervet. So, read on!


  1. A server / VPS running Ubuntu 15.04 which in this guide I use its x86_64 version from DigitalOcean.
  2. SSH client app like Putty and proper knowledge to use the app.
  3. Some basic knowledge about common unix command.
  4. A cup of tea or coffee as always.

How to Install Apache 2

Step 1 – First thing first, login to your server as root (I assume you knew how to use SSH / Putty). If you are using a droplet from DO like me, you will be asked to change default root password:

Step 2 – Update Ubuntu’s packages to latest version using this command:

apt-get update -y
apt-get upgrade -y


Step 3 – Now here’s the main command to install Apache 2 webserver on Ubuntu 15.04:

apt-get install apache2 -y

You’ll see something similar to this:

How to Install PHP 5

Step 1 – For the first step, you can start installing PHP5 and MySQL PHP modules using this command:

apt-get install php5 php5-mysql -y

the process will be done in few seconds. Pic:

Step 2 – Install other PHP5 modules your app / script may need. There are many modules available and your app/script may need specific ones. However, you can install most common modules many apps usually need it. Here’s the command you can issue:

apt-get install php5-cgi php5-cli php5-common php5-curl php5-dev php5-gd php5-tidy php5-xmlrpc php5-xsl php5-mcrypt php5-imap php5-imagick php5-json php5-intl php5-mcrypt libapache2-mod-php5 -y



Step 3 – That’s it. You can now check which PHP version is installed using this magic command:

php -v

In my example it is PHP 5.6.4


How to Install MariaDB Server

Step 1 – The command to install MariaDB is still the same which is:

apt-get install mariadb-server -y



Step 2 – Once the install process is finished, you have to firstly setup your MariaDB install with new root password (default is blank). Issue this command:


Simply hit Enter on your keyboard if asked with current password then answer next questions accordingly. Do not forget to create new password and remember it (It is your database password for user root).

Step 3 – Now login to MariaDB to test your newly created root password:

mysql -u root -p

enter your MySQL root password


As you can see from the pic above, it is MariaDB v10.0.17 which is equivalent to MySQL 5.6 & 5.7

Finally, do not forget to restart Apache 2 webserver:

service apache2 restart

that’s it. You can now start hosting your websites / blogs on it which shortly can be done this way:

How to Host A Website on Ubuntu LAMP Server

Step 1 – Create the directory where you put all your site’s files in it (web directory):

mkdir -p /var/www/
mkdir /var/www/

the output simply looks like this:


Step 2 – So you have now a directory where you can store all files including scripts and medias of your website. What’s next to do is to make sure Apache will know where to access when a domain name is called. Hence, you have to create a new Virtual Hosts file, a configuration block of Apache for each of your domain / sub-domain.

nano /etc/apache2/sites-available/

The command tells nano editor to create a new file called Do not forget to change every in this tutorial with your own domain name. Also, if you have no Nano installed yet, you can install it easily with this command:

apt-get install nano -y

Step 3 – Now a blank editor page will show up. Next, copy paste configuration below and adjust few lines accordingly:

<VirtualHost *:80> 
     DocumentRoot /var/www/
     ErrorLog /var/www/ 
     CustomLog /var/www/ combined
     <Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Order allow,deny
        allow from all

here’s an example:


Save it and exit Nano editor (Control+O then Control+X).

Step 4 – Reload Apache to be able to read a new configuration file.

service apache2 reload

Step 5 – You can then enable the Virtual Hosts (configuration) file using this command:



You can then test it by creating a phpinfo file:

nano /var/www/

and put this line in there:

<?php phpinfo(); ?>


Save it and exit Nano editor (Control+O then Control+X).

Open up your browser and type:

then you will now see a bunch of configuration details of your installed PHP.

Step 6 – This is optional but you may need it if you are using WordPress:

chown www-data:www-data -R /var/www/
chmod 755 /var/www/

That’s all. Do not forget to follow me on twitter to get quicker notification of new update.


Add a Comment

Your email address will not be published. Required fields are marked *

Get more stuff like this
in your inbox

Subscribe and get interesting stuff plus faster updates to your email.