Installing Apache 2.4
sudo apt-get install apache21
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/logs2
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.conf3
<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
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.loc5
Make changes in hosts file. To open it as usual use nano:
sudo nano /etc/hosts6
Add the following line:
You need install MySQL as follows:
sudo apt-get install mysql-server mysql-client8
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.
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 update9
sudo apt-get install php510
Add a simple PHP script to test out virtual host:
sudo nano /var/www/test.loc/index.php11
With the following code:
Finally, restart Apache:
sudo service apache2 restart13
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-xsl14
Before installation unit you need to make sure that you have MySQL server and php with required modules installed.
Installing phpMyAdmin as follows:
sudo apt-get install phpmyadmin15
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.conf16
Add the next line to end of the file:
To go down to the end of the file, press Ctrl+V.
sudo service apache2 restart18
You can reach phpmyadmin by opening test.loc/phpmyadmin in your browser.