How Can We Help?

How to install LAMP on Ubuntu 18.10

Table of Content

The LAMP stack is a set of open-source software used for web application development. For a web application to work, it has to include an operating system, a web server, a database, and a programming language. Each layer of software is vital for creating a database-driven and dynamic website.

The name LAMP is an acronym of the following programs:

  • Linux Operating System
  • Apache HTTP Server
  • MySQL database management system
  • PHP programming language

1. Login the server with the root credential on the putty.

2-After login,Make sure to update the package repository cache to ensure it installs the latest versions of the software. To do so, type in the following command.

# sudo apt-get update

Step 2: Install Apache

To install Apache, run the following command in the terminal:

# sudo apt-get install apache2 

Press (yes) and hit ENTER to permit the installation.

Check if Apache is installed correctly by running the Apache service status. Use the following the command.

# sudo systemctl status apache2

To install MySQL, type in the following command:

sudo apt-get install mysql-server 

Press y to allow the installation.
During the installation, you will be prompted to set the root user password.
Note: Although it is not mandatory to set the root password, it is recommended as a precautionary safety measure.

Step 4: Install PHP

 To install PHP, run the following command.

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

Press and ENTER to allow the installation.2. Next, you should modify the way Apache serves files when directories are requested. By default, Apache first looks for a file card named index.html. However, we want it to look for the index.php file instead.

To change this, open the dir.conf file in a text editor with root privileges:

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

In the configuration file, you will see the information as in the image below.

Then, move the PHP index file to the first position.

Press CTRL + X to save and close the file. Press y and ENTER to confirm.

5.Restart Apache

For the changes to take effect, you must restart the Apache service.

Enter the command.

#  sudo systemctl restart apache2 

Step 6: Test PHP Processing on Web Server

1. Create a basic PHP script and save it to the “web root” directory. This is necessary for Apache to find and serve the file correctly. This directory is located at /var/www/html/.

To create a file in that directory, type in the following command:

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

This command opens the bank file.

#

<?php

phpinfo (); 

?>

Press CTRL + X to save and close the file. Press y and ENTER to confirm.

Open a browser and type in your IP address/info.php
The output should display the details of the LAMP stack, as seen in the image below

Thank you 🙂

Table of Contents