Install LAMP Stack (Apache, MariaDB, php, phpMyAdmin) in Debian 7/8

LAMP is stand for Linux, Apache, MySQL & PHP and now its called Linux, Apache, MySQL, MariaDB, MongoDB, PHP, PERL, PYTHON, PhpMyAdmin. In real world 60% of websites serving by LAMP. LAMP is bunch of opensource software which is developed by different organization. Also read LAMP installation on other distributions, Setup Apache Virtual Hosts on Debian based systems & Setup Apache Virtual Hosts on RHEL based systems.

1) Update your system upto date

Use the below command’s to make your system upto date.

$ sudo apt-get update && upgrade

2) Apache installation

Use the below command to install apache web server. The Apache HTTP Server is called Apache, Apache is a Web server application which is suitable for All LINUX and UNIX distribution and also support for windows. Its serving .html, .php, .pl, .cgi, etc ,..Apache is developed and maintained by open community of developers under Apache Software Foundation.

# Install Apache #
$ sudo apt-get install apache2 -y

# For Systemd Systems Debian 8 #
$ sudo systemctl start httpd.service
$ sudo systemctl enable httpd.service

# For SysVinit Systems Debian 7 & lower #
$ sudo service httpd start
$ sudo chkconfig httpd on

Open your web browser and navigate to http://localhost/ or http://your-server-ip-address/ or http://127.0.0.1/
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-1

3) MariaDB installation

MariaDB is a drop-in replacement for MySQL. MariaDB is opensource relational database management system (RDBMS) which is supporting database access. By default all the distribution included MariaDB 5.x to own repository, if you want to install, simply you can run apt-get install mariadb-server and i want to install MariaDB 10 Which is not included in distribution repository. So, i’m going to add MariaDB repo to our system.

# Add MariaDB 10.x Repo #
$ sudo apt-get install software-properties-common
$ sudo apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
$ sudo add-apt-repository 'deb [arch=amd64,i386] http://mirrors.opencas.cn/mariadb/repo/10.1/debian '$(lsb_release -cs)' main'
$ sudo apt-get update
$ sudo apt-get -y install mariadb-server

# For Sysvinit System Debian 8 & later #
$ sudo systemctl start mariadb.service
$ sudo systemctl enable mariadb.service
$ sudo systemctl status mariadb.service

# For Sysvinit System Debian 7 & older #
$ sudo service mysqld start
$ sudo chkconfig mysqld on

While installing MariaDB server, it will ask you to set root password for MariaDB.
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-2
Confirm the root password for MariaDB.
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-3
MariaDB access.

$ sudo mysql -u root -p

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 40
Server version: 10.1.16-MariaDB-1~jessie-log mariadb.org binary distribution

Copyright (c) 2000, 2014, Oracle, SkySQL Ab and others.

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

MariaDB [(none)]>  

4) PHP installation

Use the below command to install PHP. PHP initially called Personal Home Page, now its called Hypertext Preprocessor. PHP is opensource software which is designed for web development purpose. Its used for server-side scripting language as well as general-purpose programming language.

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

Create test php file to check whether php is working with apache or not.

$ nano /var/www/phpinfo.php
<?php phpinfo(); ?>

Open your web browser and navigate to http://localhost/phpinfo.php or http://your-server-ip-address/phpinfo.php or http://127.0.0.1/phpinfo.php
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-4

5) Install phpMyAdmin

phpMyAdmin is a free open-source web-based administration tool for managing the MySQL, MariaDB servers which will help us to manage the database easily.

$ sudo apt-get -y install phpmyadmin

Make sure your system should have database installed (MySQL, MariaDB, etc) before proceeding phpMyAdmin installation. Here choose Yes to configure database for phpmyadmin with dbconfig-common.
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-5
Enter MySQL root password to create phpmyadmin database.
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-6
Enter password for phpmyadmin database.
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-7
Confirm the password for phpmyadmin database.
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-8
Select the webserver to configure phpMyAdmin automatically. We knows, we are using apache.
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-9
open the file /etc/phpmyadmin/apache.conf and find the value Require ip or Allow from based on your Apache version, you will get two location. Modify like below. so that you access anywhere.

# Configure phpMyAdmin #
$ nano /etc/phpmyadmin/apache.conf
Require All granted
Require All granted

# Restart apache service #
$ sudo systemctl restart apache2.service    # [For Systemd Systems] #
$ sudo service apache2 restart    # [For Systemd Systems] #

Open your web browser and navigate to http://localhost/phpMyAdmin or http://your-server-ip-address/phpMyAdmin or http://127.0.0.1/phpMyAdmin
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian-7-10
Enter the Mysql root password to login phpmyadmin.
install-lamp-stack-apache-mariadb-php-phpmyadmin-on-debian7-11

We are preparing all articles in-depth to understand by all level/stage Linux administrators. If the article is useful for you, then please spend less than a minute to share your valuable comments in our commenting section.

Please stay tune with us…Good Luck.

About Magesh Maruthamuthu

Love to play with all Linux distribution

View all posts by Magesh Maruthamuthu

Leave a Reply

Your email address will not be published. Required fields are marked *