Home > English > Tutorials > How to install LAMP (APACHE-PHP-MYSQL) on Ubuntu 14

How to install LAMP (APACHE-PHP-MYSQL) on Ubuntu 14

 

Step1: Install Apache

Update Ubuntu software package with the latest version with the command

# apt-get update -y

The name of  Apache software on Ubuntu is apache2 so you install with this command 

# apt-get install apache2 -y

/var/www/html : directory storing the website's root data, the default of Apache on Ubuntu

/etc/apache2 : directory storing configuration files of  Apache on Ubuntu

/etc/apache2/apache2.conf  : Configuration file of Apache on Ubuntu.

You visit http://ip-vps if the screen is like this then you are successful

Step2. Install PHP

# apt-get install php5 libapache2-mod-php5 php5-mcrypt -y

Edit the file dir.conf. Add 'index.php' at the beginning to give priority to the index file index.php

# nano /etc/apache2/mods-enabled/dir.conf

<IfModule mod_dir.c>
        DirectoryIndex 
index.php  index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>

By default the root documents of the website are / var / www / html. Now you creat a small PHP file <info.php> in that directory and call it in one browser. The files will display many useful details about our PHP installation such as some PHP versions installed before 

# nano /var/www/html/info.php

In the file info.php there is a content

<?php
phpinfo();
?>

Restart the Apache.

# service apache2 restart

If you see this error, you can rectify it as follows

root@maxserver:~# service apache2 restart
 * Restarting web server apache2                                                                                                                                        
AH00558: apache2: Could not reliably determine the server's fully qualified doma                                                                                        in name, using 107.189.160.9. Set the 'ServerName' directive globally to suppres                                                                                        s this message
                                                                         [ OK ]

 

Edit the configuration 'apache2.conf'

# nano /etc/apache2/apache2.conf

Add this line

ServerName localhost

Restart the Apache.

# service apache2 restart

root@maxserver:~# service apache2 restart
 * Restarting web server apache2                                         [ OK ]

If you want to install other modules for PHP, you can search their names in installing packages by commanding

# apt-cache search php5-

To test the php visit http://ip-vps/info.php

We recommend that you should remove the file info.php after testing php for security reason

# rm nano /var/www/html/info.php

Step3: Install MySQL Server

Type this command to install MySQL Server and MySQL module for PHP.

# apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql -y

During the installation, MySQL will display an interface for you to set a root password for MySQL, you can press enter to skip it

 

Once you've installed MySQL, you should enable it by commanding

# mysql_install_db

Run this command to set Mysql

# mysql_secure_installation

It will open a list 

root@maxserver:~# /usr/bin/mysql_secure_installation


NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
      SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!


In order to log into MySQL to secure it, we'll need the current
password for the root user.  If you've just installed MySQL, and
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none):    
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.

Set root password? [Y/n] y             
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
 ... Success!


By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y                      
 ... Success!

Normally, root should only be allowed to connect from 'localhost'.  This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y               
 ... Success!

By default, MySQL comes with a database named 'test' that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y      
 - Dropping test database...
ERROR 1008 (HY000) at line 1: Can't drop database 'test'; database doesn't exist
 ... Failed!  Not critical, keep moving...
 - Removing privileges on test database...
 ... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y                 
 ... Success!

Cleaning up...

All done!  If you've completed all of the above steps, your MySQL
installation should now be secure.

Thanks for using MySQL!
 

Log in MySQL

# mysql -u root -p