How to Install and Configure Apache2, PHP and MySQL 5.6 on Ubuntu 14.04

Share this Article :

LAMP stack is a group of open source software that installed together to let you run a server to host dynamic websites. “L” stand for Linux, “A” stand for Apache (to host Web server), “M” stand for MySQL(to store database) and “P” stand for PHP(to process dynamic content). With the release of Ubuntu 14.04 on April 17 2014, i would share the steps to setup Apache2, PHP and MySQL on Ubuntu 14.04 in order to run a dynamic websites. This may useful for those who plan to run their websites on Virtual private server (VPS) or dedicated server.

1. Install Apache2, MySQL and PHP :

[email protected]:~$ sudo apt-get install apache2 php5 php5-cgi libapache2-mod-php5 php5-common php-pear mysql-server-5.6 -y

During this installation, you will require to set MySQL’s root password :
1

2

2. Backup the original Apache2 configuration file :

[email protected]:~$ sudo cp -p /etc/apache2/conf-enabled/security.conf /etc/apache2/conf-enabled/security.conf.bak

3. Open security.conf and modify the OS to become Prod. For security reason, Prod will tells apache to only return Apache in the Server header, returned on every page request.

[email protected]:~$ sudo vi /etc/apache2/conf-enabled/security.conf
..
..
ServerTokens Prod
..
..
ServerSignature Off
..
..

4. Add file extension that can be access :

[email protected]:~$ sudo vi /etc/apache2/mods-enabled/dir.conf
<IfModule mod_dir.c>
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

5. Specify server name :

[email protected]:~$ sudo vi /etc/apache2/apache2.conf
# Do NOT add a slash at the end of the directory path.
#
#ServerRoot "/etc/apache2"
ServerName ubuntu14.ehowstuff.local
#
# The accept se

6. Specify webmaster’s email :

[email protected]:~$ sudo vi /etc/apache2/sites-enabled/000-default.conf

        ServerAdmin [email protected]
        DocumentRoot /var/www/html

7. Restart web server apache2 :

[email protected]:~$ sudo /etc/init.d/apache2 restart
 * Restarting web server apache2                                                             [ OK ]

8. Near line 220: add extension for PHP :

[email protected]:~$ sudo vi /etc/apache2/mods-enabled/mime.conf
..
..
AddHandler php5-script .php
..
..

9. Comment and add your timezone :

[email protected]:~$ sudo vi /etc/php5/apache2/php.ini
..
..
date.timezone = "Asia/Kuala Lumpur"
..
..

After change php.ini, restart the apache :

[email protected]:~$ sudo /etc/init.d/apache2 restart
 * Restarting web server apache2                                                             [ OK ]

10. Connect to MySQL :

[email protected]:~$ sudo mysql -u root -p
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 36
Server version: 5.6.17-0ubuntu0.14.04.1 (Ubuntu)

Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql>

11. Show user info :

mysql> select user,host,password from mysql.user;
+------------------+-----------+-------------------------------------------+
| user             | host      | password                                  |
+------------------+-----------+-------------------------------------------+
| root             | localhost | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root             | ubuntu14  | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root             | 127.0.0.1 | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| root             | ::1       | *2470C0C06DEE42FD1618BB99005ADCA2EC9D1E19 |
| debian-sys-maint | localhost | *9C063813F4CC3C2E09995B0D043C7375C5E5538A |
+------------------+-----------+-------------------------------------------+
5 rows in set (0.00 sec)

12. Show databases :

mysql> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

Done!!

Leave a Reply