Published October 11, 2017 by

Install LAMP Stack (Apache, Mysql, php, phpMyAdmin) On Ubuntu/Linux

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.

1 Install apache

Apache is an open-source multi-platform web server. It provides a full range of web server 

Install Apache

# sudo apt-get install apache2

Enable and start your apache

# systemctl enable apache2
# systemctl start apache2
# systemctl status apache2

Test apache

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




2 Install MySQL

# sudo apt-get update
# sudo apt-get install mysql-server


Re-enter the password.


Remeber mysql server automatic configure default port 3306.

# sudo mysql_secure_installation

Here mysql asks some few questions for configuration, give (yes/no) answers according your requirement.  

Check status of mysql

# sudo mysql_secure_installation

Access mysql

# mysql -u root -p

Enter a Password of you set for root at installation time.

Quit/Exit mysql


mysql>exit

Uninstall/Remove MySQL on Ubuntu/Linux

# apt-get remove -y mysql-*
# apt-get purge -y mysql-*


3 Install PHP

Install PHP with following command:

# sudo apt-get update
# sudo apt-get install php libapache2-mod-php php-mcrypt php-mysql

In most cases, we'll want to modify the way that Apache serves files when a directory is requested. Currently, if a user requests a directory from the server, Apache will first look for a file called index.html. We want to tell our web server to prefer PHP files, so we'll make Apache look for an index.php file first.

To do this, type this command to open the dir.conf file in a text editor with root privileges:

# sudo vim /etc/apache2/mods-enabled/dir.conf

Erase all data and paste below Code:

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

Test your php version

root@subhash:# php -v

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

# sudo vim  /var/www/html/testphp.php

Add the following lines:

<?php
phpinfo();
?>

Restart apache2 service.

# sudo systemctl restart apache2

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




4 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.


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.


Enter password of the database’s administrative user.

Enter MySQL application password for phpmyadmin:

Re-enter password:


Success! phpMyAdmin installation is installed.

Configure phpMyAdmin

# sudo vim /etc/apache2/apache2.conf

Add the following line at the end.

Include /etc/phpmyadmin/apache.conf

Save and Exit. Restart apache service:

# sudo systemctl restart apache2

Access phpMyAdmin Web Console

Now, you can access the phpmyadmin console by navigating to http://localhost/phpmyadmin/ from your browser.