Recommended VPS Complete list of best VPS hosting providers.

Full Setup A Working Apache Server on Ubuntu 16.04

So Ubuntu has received newer major update making it version 16.0 which also known as Xenial Xerus. Some people also say that this new update is the best Ubuntu release so far. In this article I show you how to install full Apache stack on it. We will have Apache, MariaDB, and of course the fastest version of PHP, the PHP 7 – this setup is also known as LAMP Stack. Usually the abbreviation stands for Linux, Apache, MySQL and PHP but in this guide we’ll replace conventional MySQL server with its drop-in replacement, MariaDB server to give better and more sleek performance in handling your apps’ database.

Also read : How to setup nginx with HTTP/2 and free SSL at Ubuntu.

Prerequisites

  1. A SSH client like Bitvise or Putty and basic knowledge about how to use it.
  2. Basic knowledge about common Unix command to SSH to your server.
  3. A server or VPS with at least 256MB of RAM (OpenVZ) but 512MB is recommended if you are using KVM or Xen.
  4. About 30 minutes of your time.
  5. a cup of coffee or tea.

Confused on choosing which VPS provider to setup an Apache based hosting server? Read my recommended VPS providers or this list of top low end cloud server providers. Quick recommendation: Digital Ocean, Atlantic.net or Ramnode.

In this guide I am using a 512MB RAM Cloud VPS from Atlantic running Ubuntu 16.04 x64.

Do not forget to always replace domain.tld with your own domain name and replace x.x.x.x with your server IP address.

Provision a cloud server

Step 1 – Login to Atlantic.net > click on Servers > Add Server.

2016-04-17_210817

Step 2 – Give your server a name and choose in which location you want it to be hosted at. Currently, Atlantic.net has 6 different locations available: New York, Dallas, Orlando, San Fransisco, Toronto (CA), and London (UK).

Create A Server on Atlantic

Step 3 – Choose Ubuntu 16.04 as the operating system for your cloud vps.

Ubuntu 16.04 Atlantic Server

Step 4 – Decide which plan you want (and you need).

Choose VPS Plan

Step 5 – Finally, click on the Create Server button.

2016-04-17_211935

Step 6 – The process should take less than 1 minute to complete.

building cloud server

Step 6 – Once done, the login details will be emailed to your inbox.

Check Email

Step 7 – Login to your server via Putty.

Login Putty

Step 8 – Type this command to change default Hostname. Use proper FQDN hostname format:

hostname host.domain.tld

## example :
hostname atlantic.servermom.org

Change Hotsname Ubuntu

Step 9 – Close Putty and re-login using new session and you should now see it has changed. It is also a good practice to change given root password with your own.

relogin putty

Install Apache

Step 1 – As usual, installing Apache webserver on Ubuntu is as easy as a piece of cake. By default, Ubuntu has included the package and it is available in default repository. Just issue following command :

apt-get install apache2

Do not forget to always answer Y when asked.

install apache2 ubuntu 1604

Step 2 – Now let’s enable Apache2 service and start it.

systemctl enable apache2
systemctl start apache2

enable start apache2 ubuntu 1604

Step 3 – Verify the status of Apache whether it has run properly or not.

systemctl status apache2

Verify Apache2 Status

Step 4 – Open up your favorite web browser (e.g: Firefox) and access your server through the IP address. You should then see Apache’s default page like this one :

Apache Ubuntu Default Page

You may read that page if you want because it contains very useful basic information about Apache on Ubuntu.

Install MariaDB Server

Assuming that you use fresh Ubuntu server, so I’ll go straight forward with the steps. Otherwise, if you have MySQL running then you have to firstly stop and remove its service.

Step 1 – Again, we can simply use apt-get command because its package is available in default repository.

apt-get install mariadb-server

install mariadb ubuntu 1604

Step 2 – During the process, you may be asked to enter database root password. Remember, database root user is not the same as your server root user. Therefore, it is always a good idea to have different password set for each. However, if the system does not ask you to define database root password for MariaDB, then you can simply issue following command :

mysql_secure_installation

Step 3 – You’ll be asked to answer a series of questions.

Enter current password for root (enter for none):  <-- Just hit enter because we don't have any password
Set root password? [Y/n] y <-- answer Y and hit enter
New password: <-- type in your password here
Re-enter new password: <-- type in again
Remove anonymous users? [Y/n] <-- just hit enter
Disallow root login remotely? [Y/n] <-- just hit enter
Remove test database and access to it? [Y/n] <-- just hit enter
Reload privilege tables now? [Y/n]  <-- just hit enter

See this screenshot pic :

mariadb first setup configuration

mariadb first setup configuration 2

Step 4 – Let’s check the status of your newly installed MariaDB server.

service mysql status

You should see no critical error listed. However, in rare cases you may also see this problem :

mariadb server error

error message :

mariadb server error message

[Warning] ‘user’ entry ‘root@localhost’ has both a password and an authentication plugin specified.

The follow this additional step :

Try to login to MariaDB server as root but without password. Successful login means the root password you have specified before is not taking place yet.

mysql -u root

use mysql;
update user set plugin='' where User='root';
flush privileges;
\q

fixing mariadb error ubuntu 1604

Next, issue this command again and follow the steps thoroughly:

mysql_secure_installation

Install PHP7

Step 1 – Before we install it, let’s firstly update your apt database :

apt-get update -y

Step 2 – Now let’s install PHP7 on your Ubuntu 16.04 server plus few of its common PHP7 modules:

apt-get install php7.0-mysql php7.0-curl php7.0-json php7.0-cgi php7.0

install php7 ubuntu 1604

The command above will automatically install following packages : php7.0, libcurl3, php-common, php7.0-cli, php7.0-common, php7.0-opcache, php7.0-readline, php7.0-cgi, php7.0-curl, php7.0-mysql, and soon.

Step 3 – Verify that you have truly installed php 7 by issuing this command :

php -v

You’ll then get following message :

PHP v7.0.4

as you can see above, in my case it is PHP v7.0.4.

Step 4 – Now create a PHP test file :

nano /var/www/html/testphp.php

Step 5 – Then put this code :

<?php
phpinfo();
?>

Do not forget to hit Control+O to save the file and Control+X to exit Nano editor.

php test file

Step 6 – Now open up your web browser again and try accessing that file :

http://x.x.x.x/testphp.php

Step 7 – You should now see detailed PHP information page. What if I got a blank page? Then it means the .php file you’ve just created is not rendered and PHP is not working properly. Now install this additional php module :

apt-get install libapache2-mod-php

libapache2-mod-php7.0 module

Now restart apache2 service and try it again on your browser

service apache2 restart

PHP7 Installed Succesfully

Next : Install phpMyAdmin on Ubutu 16.04 LAMP Server

That’s all. From this point your server is basically ready to use. What’s next to do is simply creating virtual hosts file to add your website on it. We’ll discuss that in another article. However, if you want, you can simply read my previous similar article about the same goal but was done on older Ubuntu version. Anyway, do not forget to follow me on twitter to get faster update or subscribe with your email.

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.