Linux Web

Configure and install LAMP stack on Linux – Debian and Ubuntu

Install LAMP stack

Install LAMP Server for Debian and Ubunut based system. LAMP stands for Linux, Apache, MySQL and PHP. It’s technology stack used to build and deply PHP applications. There are alternatives to LAMP for instance you can use WAMP or XAMP for windows based system and configure your application on your local machine. But if you want to set up and create your own production environment than LAMP is preferred.

Installing apache

First update the system’s software repositories.

#sudo apt-get update

Now to install apache use the following command

#sudo apt-get install apache2

Installation process will take care of starting the apache and start listening on port 80 by default. To confirm this you can go to browser and type localhost in address bar. Your can also use the loop-back address 127.0.0.1

Installing PHP

Now to install PHP type the following command in terminal.

#sudo apt-get install php

This will resolve and install all the required dependencies for PHP.

After successful installation of PHP restart apacheĀ  with following command.

#sudo systemctl restart apache2

Now it’s time to test our PHP environment. We will create a test PHP file in a directory /var/www/html since this is the directory designated to our apache web server in configuration.To learn how to change Apache Web server configuration, You can follow this link. Go ahead and create a file as shown below.

#sudo nano /var/www/html/test.php

Use the following code. Copy and paste this code in test.php

<?php

phpinfo();

?>

Save andĀ  Exit the file. Code mention above will show all the information about your PHP setup. Go to http://localhost/test.php

If you see the output shown as below, Your PHP environment is working fine.

PHP Info

Installing MySQL

Now we will install MySQL in order to have database connectivity.

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

During the setup process it will ask you to create a root password as shown below.

Create root password and hit enter.

In order to check your MySQL Installation run the following command to connect to your MySQL server.

#mysql -u root -p

At this point your LAMP Server is installed. If you are required install LAMP server for your production server just perform these steps.

Install phpmyadmin

Last thing we need to add to our system is phpmyadmin. phpmyadmin is required to easily manage your databases.

#sudo apt-get install phpmyadmin

Now go to http://localhost/phpmyadmin or http//your-ip-address/phpmyadmin

About the author

Ajay Verma

A Computer Science Graduate, who works extensively on open source projects. His Areas Of interest are: Network Security, Linux Administration, FOSS, Python, and C programming.

Add Comment

Click here to post a comment