How To Install LAMP Stack On Ubuntu 15.04


Please shareShare on Facebook349Share on Google+34Tweet about this on Twitter38Share on LinkedIn2Share on Reddit0Digg thisShare on StumbleUpon1Share on VKBuffer this page

LAMP is a combination of operating system and open-source software stack. The acronym LAMP came from the first letters of Linux, Apache HTTP Server, MySQL or MariaDB database, and PHP/Perl/Python. This tutorial describes how to install LAMP stack on Ubuntu 15.04, and previous versions such as Ubuntu 14.10/14.04/13.10 etc.

Install LAMP Stack On Ubuntu

1. Install Apache

Apache is an open-source multi-platform web server. It provides a full range of web server features including CGI, SSL and virtual domains.

To install Apache, enter:

sudo apt-get install apache2
Test Apache:

Open your web browser and navigate to http://localhost/ or http://server-ip-address/.

Apache2 Ubuntu Default Page: It works - Mozilla Firefox_012

2. Install MySQL

MySQL is a relational database management system (RDBMS) that runs as a server providing multi-user access to a number of databases, though SQLite probably has more total embedded deployments

sudo apt-get install mysql-server mysql-client

During installation, you’ll be asked to setup the MySQL “root” user password. Enter the password and click Ok.

sk@server: ~_001

Re-enter the password.

sk@server: ~_002

MySQL is installed now.

You can verify the MySQL server status using command:

On Ubuntu 15.04:

sudo systemctl status mysql

On Ubuntu 14.10 and previous versions:

sudo service mysql status

Sample output:

● mysql.service - MySQL Community Server
   Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
   Active: active (running) since Wed 2015-04-29 13:33:09 IST; 7s ago
 Main PID: 3740 (mysqld_safe)
   CGroup: /system.slice/mysql.service
           ├─3740 /bin/sh /usr/bin/mysqld_safe
           └─4087 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --...

Apr 29 13:33:08 server systemd[1]: Starting MySQL Community Server...
Apr 29 13:33:08 server mysqld_safe[3740]: 150429 13:33:08 mysqld_safe Can't ....
Apr 29 13:33:08 server mysqld_safe[3740]: 150429 13:33:08 mysqld_safe Loggin....
Apr 29 13:33:08 server mysqld_safe[3740]: 150429 13:33:08 mysqld_safe Starti...l
Apr 29 13:33:09 server systemd[1]: Started MySQL Community Server.
Hint: Some lines were ellipsized, use -l to show in full.

3. Install MariaDB

In case you want to use MariaDB instead of MySQL community edition, follow the steps given below.

MariaDB is a drop in replacement for MySQL. It is a robust, scalable and reliable SQL server that comes rich set of enhancements.

First you have to remove existing MySQL packages if any. To completely uninstall MySQL along with its configuration files, enter the following commands one by one:

sudo systemctl stop mysql
sudo apt-get remove --purge mysql-server mysql-client mysql-common
sudo apt-get autoremove
sudo apt-get autoclean
sudo rm -rf /var/lib/mysql/
sudo rm -rf /etc/mysql/

After removing MySQL, run the following command to install MariaDB.

sudo apt-get install mariadb-server

Alternatively, you can install it using MariaDB repository if you want to try most recent version of MariaDB. Run the following commands to add PPA. As of writing this, MariaDB PPA is not yet updated to Ubuntu 15.04. However, we can use the repository of Ubuntu 14.10 instead.

sudo apt-get install software-properties-common
sudo apt-key adv --recv-keys --keyserver hkp:// 0xcbcb082a1bb943db
sudo add-apt-repository 'deb utopic main'

Update the software sources list and install MariaDB using following commands:

sudo apt-get update
sudo apt-get install mariadb-server

During installation you will be asked to set mysql ‘root’ user password. Enter the password twice, and complete the installation.

Note: In Ubuntu 15.04, MariaDB won’t ask you to set root user password during installation.

Also, you can’t set password using command:


It will throw the following error.

ERROR 1698 (28000): Access denied for user 'root'@'localhost'

To fix this error, log in to mysql prompt without password as root user:

sudo mysql -u root

Then, run the following commands one by one in the mysql prompt:

use mysql;
update user set plugin='' where User='root';
flush privileges;

That’s it. Now, set database administrative “root” user password using command. Press Enter and go with the default settings.


Sample output:


In order to log into MariaDB to secure it, we'll need the current
password for the root user.  If you've just installed MariaDB, 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 MariaDB
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 MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB 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] 
 ... 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] 
 ... Success!

By default, MariaDB 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] 
 - 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] 
 ... Success!

Cleaning up...

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

Thanks for using MariaDB!

Check if mariadb is running or not, using the following command:

sudo service mysql status

Sample output:

● mysql.service - LSB: Start and stop the mysql database server daemon
   Loaded: loaded (/etc/init.d/mysql)
   Active: active (running) since Wed 2015-04-29 13:57:57 IST; 15min ago
     Docs: man:systemd-sysv-generator(8)
   CGroup: /system.slice/mysql.service
           ├─2527 /bin/bash /usr/bin/mysqld_safe
           ├─2528 logger -p daemon.err -t /etc/init.d/mysql -i
           └─2684 /usr/sbin/mysqld --basedir=/usr --datadir=/var/lib/mysql --...

Apr 29 13:57:58 server /etc/mysql/debian-start[2735]: mysql.servers          ...
Apr 29 13:57:58 server /etc/mysql/debian-start[2735]: mysql.table_stats      ...
Apr 29 13:57:58 server /etc/mysql/debian-start[2735]: mysql.tables_priv      ...
Apr 29 13:57:58 server /etc/mysql/debian-start[2735]: mysql.time_zone        ...
Apr 29 13:57:58 server /etc/mysql/debian-start[2735]: mysql.time_zone_leap_se...
Apr 29 13:57:58 server /etc/mysql/debian-start[2735]: mysql.time_zone_name   ...
Apr 29 13:57:58 server /etc/mysql/debian-start[2735]: mysql.time_zone_transit...
Apr 29 13:57:58 server /etc/mysql/debian-start[2735]: mysql.time_zone_transit...
Apr 29 13:57:58 server /etc/mysql/debian-start[2735]: mysql.user             ...
Apr 29 13:57:58 server /etc/mysql/debian-start[2790]: Triggering myisam-recov...
Hint: Some lines were ellipsized, use -l to show in full.

4. Install PHP

PHP (recursive acronym for PHP: Hypertext Preprocessor) is a widely used open-source general purpose scripting language that is especially suited for web development and can be embedded into HTML.

Install PHP with following command:

sudo apt-get install php5 php5-mysql libapache2-mod-php5

To test PHP, create a sample “testphp.php” file in Apache document root folder.

sudo nano /var/www/html/testphp.php

Add the following lines.


Restart apache2 service.

On Ubuntu 15.04:

sudo systemctl restart apache2

On Ubuntu 14.10 and lower versions:

sudo service apache2 restart

Navigate to http://server-ip-address/testphp.php. It will display all the details about php such as version, build date and commands etc.

phpinfo() - Mozilla Firefox_003

If you want to install all php modules at once, enter the command sudo apt-get install php* and restart the apache2 service. To verify the modules, open web browser and navigate to http://server-ip-address/testphp.php. You will able to see all installed php modules.

5. Manage MySQL Databases (Optional)

Install phpMyAdmin

phpMyAdmin is a free open-source web interface tool used to manage your MySQL databases. It is available in the Official Debian repositories. So install it with command:

sudo apt-get install phpmyadmin

Select the Web server that should be automatically configured to run phpMyAdmin. In my case, it is apache2.

sk@server: ~_004

The phpMyAdmin must have a database installed and configured before it can be used. This can be optionally handled by dbconfig-common.

Select ‘Yes’ to configure database for phpmyadmin wjth dbconfig-common.

sk@server: ~_006

Enter password of the database’s administrative user.

sk@server: ~_007

Enter MySQL application password phpmyadmin.

sk@server: ~_008

Re-enter the password.

sk@server: ~_009

Success! phpMyAdmin installation is installed.

Additional Note: if you followed all steps carefully, phpMyAdmin should work just fine. In case phpMyAdmin is not working, please do the following steps.

Open terminal, and type:

sudo nano /etc/apache2/apache2.conf

Add the following line at the end.

Include /etc/phpmyadmin/apache.conf

Save and Exit. Restart apache service:

On Ubuntu 15.04:

sudo systemctl restart apache2

On Ubuntu 14.10 and lower versions:

sudo /etc/init.d/apache2 restart

6. Access phpMyAdmin Web Console

Now, you can access the phpmyadmin console by navigating to http://server-ip-address/phpmyadmin/ from your browser.

Enter your MySQL username and password which you have given in previous steps. In my case its “root” and “ubuntu”.

phpMyAdmin - Mozilla Firefox_010

You will be redirected to PhpMyAdmin main web interface. - localhost | phpMyAdmin 4.2.12deb2 - Mozilla Firefox_011

From here, you can manage your MySQL databases from phpMyAdmin web interface.

That’s it. Your LAMP stack is ready to use.