Installing Apache 2.4

sudo apt-get install apache2
1

To create a new virtual host, firstly, you need to create appropriate directories:

sudo mkdir -p /var/www/test.loc/www
sudo mkdir -p /var/www/test.loc/logs
2
Usage of -p allows the creation of nested directories specified in the path.
TIP

Apache comes with a default virtual host called 000-default.conf which it uses by default, but we are going to create a new one - test.loc.conf for our domain test.loc:

sudo nano /etc/apache2/sites-available/test.loc.conf
3
<VirtualHost *:80>
    ServerName test.loc
    ServerAlias www.test.loc

    DocumentRoot /var/www/test.loc/
    <Directory /var/www/test.loc/>
        AllowOverride All
    </Directory>

    CustomLog  /var/www/test.loc/logs/access.log common
    ErrorLog /var/www/test.loc/logs/error.log
    LogLevel warn
</VirtualHost>
4
Save and Save As are both accomplished with the Write Out command, Ctrl+O. When prompted, press enter to accept the existing file name.
TIP

In order to allow the usage of the domain, execute the following command which creates a symbolic link between sites-available and sites-enabled to activate the host we’ve created:

sudo a2ensite test.loc
5

Make changes in hosts file. To open it as usual use nano:

sudo nano /etc/hosts
6

Add the following line:

127.0.1.1 test.loc
7

Installing MySQL

You need install MySQL as follows:

sudo apt-get install mysql-server mysql-client
8

During the installation, MySQL will ask you to set a root password. It's very important to keep it, but if you missed this step, it's very easy to set the password later, using MySQL shell.

Installing PHP

Using the repository of Ondřej Surý, we can install both stable versions of Apache 2.4 and PHP 5.5.x just following this simple steps. Add the launchpad repository to your system:

sudo apt-get install software-properties-common python-software-properties
sudo add-apt-repository ppa:ondrej/php5
sudo apt-get update
9
sudo apt-get install php5
10

Add a simple PHP script to test out virtual host:

sudo nano /var/www/test.loc/index.php
11

With the following code:

<?php
   phpinfo();
12

Finally, restart Apache:

sudo service apache2 restart
13

Now you can check test.loc in your browser. This file will display lots of useful details about your PHP installation.

To get MySQL support in PHP, you can install the php5-mysql package. Also install some other PHP5 modules which possible need for your applications:

sudo apt-get install php5-mysql php5-curl php5-gd php5-intl php-pear php5-imagick php5-imap php5-mcrypt php5-memcache php5-ming php5-ps php5-pspell php5-recode php5-snmp php5-sqlite php5-tidy php5-xmlrpc php5-xsl
14

Installing phpMyAdmin

Before installation unit you need to make sure that you have MySQL server and php with required modules installed.

TIP

Installing phpMyAdmin as follows:

sudo apt-get install phpmyadmin
15

During the installation, you will be prompted to choose the type of web server, just choose apache2.

After the installation has been completed, you need to include phpmyadmin to the apache configuration:

sudo nano /etc/apache2/apache2.conf
16

Add the next line to end of the file:

Include /etc/phpmyadmin/apache.conf
17

To go down to the end of the file, press Ctrl+V.

TIP

Restart Apache:

sudo service apache2 restart
18

You can reach phpmyadmin by opening test.loc/phpmyadmin in your browser.