Installation and Set-up Apache2 Web Server php mysql phpmyadmin (LAMP) on Ubuntu 16.04
- 29 September 2016
- Volodymyr Hodiak
- Administration
- 18902
Although my previous article about Ubuntu server installation and configuration has become outdated, it's still very popular. So I've decided to share with you my experience of software installation on Ubuntu 16.04.
Some steps were taken from the previous article.
Remember to issue sudo command (sudo su -) to follow all the steps below.
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 Встановлюємо кодування UTF-8 по замовчуванню AddDefaultCharset UTF-8
Restart Apache
service apache2 restart
Open http://localhost/ and enjoy.
Set up virtual hosts (VirtualHost)
For lazybones, I have a template bitbucket (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 virtualhosts.
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 number 88 -rw-r--r-- 1 root root 7728 кві 26 22:55 apache2.conf -rw-r--r-- 1 root root 7691 кві 26 22:34 apache2.conf~ drwxr-xr-x 2 root root 4096 кві 26 22:52 conf-available drwxr-xr-x 2 root root 4096 кві 26 22:52 conf-enabled -rw-r--r-- 1 root root 1782 січ 3 16:48 envvars -rw-r--r-- 1 root root 31063 січ 3 16:48 magic drwxr-xr-x 2 root root 12288 кві 26 22:27 mods-available drwxr-xr-x 2 root root 4096 кві 26 22:27 mods-enabled -rw-r--r-- 1 root root 320 січ 7 15:23 ports.conf drwxr-xr-x 2 root root 4096 кві 26 22:43 sites-available drwxr-xr-x 2 root root 4096 кві 26 22:44 sites-enabled
In the “sites-available” directory you'll find configurations of the available hosts and in the “sites-available” directory, there are links to active hosts. Go to available hosts and create a configuration file for mysite.loc. By the way, ifyou default configuration file ends with .conf then create a new configuration files with *. conf extension.
nano sites-available/mysite.conf
There we write:
This is enough to get your local host working. 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
## або, якщо необхідно
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 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!