image

Installation and Set-up of Apache2 Web Server + PHP + MySQL + PHPMyAdmin (LAMP) on Ubuntu 16.04

image
Volodymyr Hodiak
September 4, 2019|10 min read|7938 views

Software installation on Ubuntu 16.04 is done in several stages described below.
Remember to issue sudo command (sudo su -) when following the instruction.

Update the software

sudo apt-get update

Install Apache 2

apt-get install apache2

Configure Apache2

nano /etc/apache2/apache2.conf ## Fix the warning when restarting Apache ServerName localhost ## Enable php AddType application/x-httpd-php .php .phtml ## Set up UTF-8 encoding AddDefaultCharset UTF-8

Restart Apache

service apache2 restart

Open http://localhost/ and enjoy.

Set up virtual hosts (VirtualHost)

For lazybones, we have a bitbucket template (only for local hosts).
Download the file. Put it into /var/www.
Give permission to execute the script: 

chmod +x /var/www/vhosts.sh

The example of creating a host file:

sudo /var/www/vhosts.sh mysite.loc

You can skip the next steps regarding virtual hosts.
Write in the hosts /etc/hosts (nano /etct/hosts)

127.0.0.1    mysite.loc

Go to “/etc/apache2/” directory.
Take a look what's inside:

root@HP:/etc/apache2# ls -l total 88 -rw-r--r-- 1 root root  7728 apr 26 22:55 apache2.conf -rw-r--r-- 1 root root  7691 apr 26 22:34 apache2.conf~ drwxr-xr-x 2 root root  4096 apr 26 22:52 conf-available drwxr-xr-x 2 root root  4096 apr 26 22:52 conf-enabled -rw-r--r-- 1 root root  1782 jan  3 16:48 envvars -rw-r--r-- 1 root root 31063 jan  3 16:48 magic drwxr-xr-x 2 root root 12288 apr 26 22:27 mods-available drwxr-xr-x 2 root root  4096 apr 26 22:27 mods-enabled -rw-r--r-- 1 root root   320 jan  7 15:23 ports.conf drwxr-xr-x 2 root root  4096 apr 26 22:43 sites-available drwxr-xr-x 2 root root  4096 apr 26 22:44 sites-enabled

In the “sites-available” directory you'll find configurations of the available hosts and in the “sites-enabled” directory there are links to active hosts.

Go to available hosts and create a configuration file for mysite.loc. By the way, if your default configuration file ends with .conf, create a new configuration files with *. conf extension.

nano sites-available/mysite.conf

There we write the following:

   ServerName mysite.loc     DocumentRoot /var/www/mysite.loc             AllowOverride All

This is enough to get your local host working. Now you should create a link on it in sites-enabled.

a2ensite mysite.conf

Mind the trap: if you get an error and you can't create a link, you can fix it this way:

ln /etc/apache2/sites-available/mysite.conf /etc/apache2/sites-enabled/

Now, you just need to reload the Apache2 configurations:

service apache2 reload ## or, if needed service apache2 restart

So Apache2 is working, the first host has been added.

Install MySQL

MySQL is available in the Ubuntu repositories. It is divided into several packages.
To install the MySQL server, run the following command:

sudo apt-get install mysql-server

The configure script will ask a user for an admin password (root) of the database. 

Install PHP 5.6

First of all, you have to delete all older versions if you have any.

sudo apt-get purge `dpkg -l | grep php| awk '{print $2}' |tr "\n" " "`

Add PPA

sudo add-apt-repository ppa:ondrej/php

Update

sudo apt-get update

Install  PHP

sudo apt-get install php5.6

Install additional modules

sudo apt-get install php5.6-mbstring php5.6-mcrypt php5.6-mysql php5.6-xml

Review the version:

sudo php -v PHP 5.6.26-1+deb.sury.org~xenial+1 (cli) Copyright (c) 1997-2016 The PHP Group Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies    with Zend OPcache v7.0.6-dev, Copyright (c) 1999-2016, by Zend Technologies

Install PhpMyAdmin

apt-get install phpmyadmin

Configure it to your needs: point out that you use Apache2, write the database password and the PhpMyAdmin password.
Trap 1: http //localhost/phpmyadmin not found ubuntu
Solution:

nano /etc/apache2/apache2.conf ## add it at the end of the file Include /etc/phpmyadmin/apache.conf

Trap 2: http //localhost/phpmyadmin  HTTP ERROR 500

sudo apt-get install php-mbstring php-gettext sudo phpenmod mcrypt sudo phpenmod mbstring sudo service apache2 restart

If you've done everything right, you'll have a configured ready-to-use local server. Good luck!

Share

Related articles

image
August 10, 2022|9 min read
Healthcare Management System (HMS): Features and Benefits
HMS (Healthcare Management System) AKA Hospital Management Upgrade Over the last few decades, the need to digitize the healthcare services industry has increased immensely. Having a system in plac...
image
July 29, 2022|10 min read
What’s New in Flutter 3.0? The Ultimate Guide For You
Flutter 3 release. What's new? Oh, you’ve heard it right! The new massive Flutter update is here, and it’s world-shaken the whole app development industry. Release of Flutter has been a rollercoas...
image
January 4, 2020|2 min read
How to Remove .idea Directory from .git
How to Remove .idea Directory from .git If you have accidentally added the .idea directory to .git repository, and you don’t want it to be there, then there is an easy way to remove it. You just h...
Interested in other posts?

CONTACT US

How can we help you? *
No more than 5 files up to 5MB each
Contact details
Only for communication
Phone
Your budget *

By submitting this form I consent to processing my personal data as described in thePrivacy Policy

Every great project needs more than a vendor — it needs an ally. That’s exactly the role my team and I take on.
Natalie Kostyshak
Business Growth Executive
Let's Connect
image
Moving forward together, step by step
1
Expect a reply within 24 hours
2
We’ll schedule a quick intro call
3
Our team will craft a tailored proposal
4
Once aligned, we’ll get to work
Trusted by more than 160 companies