In this article I will guide you How to setup a working Apache server on Ubuntu 16.04. We will have Apache, MariaDB, and definitely the fastest version of PHP, the PHP 7 – this setup is known as LAMP Stack.
In this guide we’ll replace conventional MySQL server with its drop-in replacement, MariaDB server to have better and more sleek performance in handling your database.
- A SSH client like Putty and basic knowledge about how to use it.
- Basic knowledge about common Linux SSH commands.
- A server or VPS.
- About 30 minutes of your time with a cup of coffee.
Step 1 – Login to your server via SSH.
Step 2 – Type this command to change default hostname . Use proper FQDN hostname format:
hostname host.domain.tld ## example : hostname cpanelplesk.com
Step 3 – Close Putty and re-login and now you will see it has changed.
Step 1 – Installing Apache web server on Ubuntu is very simple . 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.
Step 2 – Now enable Apache2 service and start it.
systemctl enable apache2 systemctl start apache2
Step 3 – Verify the status of Apache whether it has run properly or not.
systemctl status apache2
Step 4 – Open your favorite web browser (e.g: Firefox) and access your server through the IP address. You should see Apache’s default page.
If you are using fresh Ubuntu server, so go straight forward with the steps. Otherwise, if you have already MySQL running then you have to stop and remove its service at first.
Step 1 – Again, we will simply use apt-get command because its package is available in default repository.
apt-get install mariadb-server
Step 2 – During the process, you will be asked to enter database root password. . However, if the system does not ask you to define database root password for MariaDB, then you can simply issue following command :
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
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 case if you see the problem:
Error message :
[Warning] ‘user’ entry ‘root@localhost’ has both a password and an authentication plugin specified.
Then you have to 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 effective yet:
mysql -u root use mysql; update user set plugin='' where User='root'; flush privileges; \q
Next, issue this command again and follow the steps accordingly:
Step 1 – Before installation, First update your apt database :
apt-get update -y
Step 2 – Now we will install PHP7 on our 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
Step 3 – Verify that you have truly installed php 7 by issuing this command :
Step 4 – Now create a PHP test file :
Step 5 – Then put this code :
<?php phpinfo(); ?>
Save and exit the editor.
Step 6 – Now open your web browser again and try accessing that file :
Step 7 – You should now see detailed PHP information page. If u 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
Now restart apache2 service and try it again on your browser
service apache2 restart
That’s all. Now your server is basically ready to use. Next you can simply create virtual hosts file to add your website on it. We already discuss that in another article. If you want, you can simply read my previous similar article about but that same thing was done on older Ubuntu version.
That’s all you have to do, now you know how its simple to setup a working apache server on Ubuntu 16.04. You also like to know How To Install Webuzo CP On Ubuntu 15.04 VPS . Please check my previous article on this and also give your opinion below if you experience any issues or to discuss your ideas and experiences.