How to Install LAMP in Ubuntu

Introduction

LAMP stands for Linux, Apache, MySQL, and PHP. It is a popular open source web development platform that is used to create dynamic websites and web applications. Installing LAMP on Ubuntu is a relatively straightforward process that can be completed in a few simple steps. In this guide, we will walk you through the process of installing LAMP on Ubuntu, from downloading the necessary packages to configuring the web server. By the end of this guide, you will have a fully functional LAMP stack running on your Ubuntu system.

How to Install LAMP in Ubuntu

1. Install Apache:

Open the terminal and type the following command to install Apache:

sudo apt-get install apache2

2. Install MySQL:

Open the terminal and type the following command to install MySQL:

sudo apt-get install mysql-server

3. Install PHP:

Open the terminal and type the following command to install PHP:

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

4. Restart Apache:

Open the terminal and type the following command to restart Apache:

sudo service apache2 restart

5. Test the Installation:

Create a file called info.php in the /var/www/html directory and add the following code:

Open a web browser and type http://localhost/info.php. If everything is installed correctly, you should see a page with information about your PHP installation.

Introduction

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

This step-by-step tutorial shows you how to install LAMP in Ubuntu.

How to install LAMP in Ubuntu.

Prerequisites

  • Ubuntu 18.04 or later
  • User with sudo privileges
  • Access to a terminal/command line

How to Install LAMP in Ubuntu

LAMP is a collection of four components that make up a fully functional web development environment. The LAMP acronym contains the initials of the components’ names:

  • Linux Operating System
  • Apache HTTP Server
  • MySQL database management system
  • PHP programming language (Pearl and Python are also sometimes used in the stack)

Follow the steps below to install each tool on your system.

Step 1: Install Apache

Apache HTTP Server is the web server running on top of Linux in the LAMP stack. The web server uses HTTP to process requests and transmit information through the internet.

Follow the procedure below to install Apache.

1. Before installing the first LAMP component, ensure the package list on the system is up to date. In the terminal, type:

sudo apt update

2. To install the Apache package, run the following command:

sudo apt install apache2 -y

Note: The -y flag allows skipping the installation confirmation prompt.

Installing Apache web server in Ubuntu.

3. Check if Apache installed correctly by checking the Apache service status:

sudo service apache2 status

The service shows as running in the output:

Checking if the Apache service is running in Ubuntu.

Exit the status screen by pressing Ctrl + C on the keyboard.

4. Next, make sure that the UFW firewall contains the Apache profiles by typing in the following command:

sudo ufw app list
Checking if Apache profiles exist in ufw.

5. Ensure the Apache Full profile allows the traffic on ports 80 and 443 by running the command:

sudo ufw app info "Apache Full"

The output should look similar to the following example:

Checking the ports of the Apache Full profile in ufw.

6. To confirm that Apache is running, enter the IP address of your server in the address bar of an internet browser and press ENTER.

The test Apache web server page should display as below.

Apache2 Ubuntu Default Page.

Note: You can also access the Apache test page by typing localhost in the address bar.

Step 2: Install MySQL and Create a Database

MySQL is a relational database management system for creating and maintaining dynamic enterprise-level databases. It is compatible with all major OS platforms, which makes it a good fit for web application development.

Install MySQL by typing the following command:

sudo apt install mysql-server -y
Installing MySQL server in Ubuntu.

Step 3: Install PHP

Although other programming languages, such as Python and Pearl, also work well within LAMP, PHP is usually the final layer of the stack because it integrates well with MySQL. As a dynamically typed language, PHP embeds into HTML, improving the speed and reducing the complexity of web applications.

Install PHP by following the steps below.

1. Obtain the necessary PHP packages by typing:

sudo apt install php libapache2-mod-php php-mysql -y
Installing PHP in Ubuntu.

2. Modify the way Apache serves files by opening the dir.conf file in a text editor with root privileges:

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

The configuration file looks like in the example below:

Editing the dir.conf file in Ubuntu.

By default, Apache first looks for an index.html file card.

3. Edit the list so that the index.php file is in the first position:

The dir.conf file edited to list the PHP page first.

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

Install PHP Modules (Optional)

If necessary, add more modules to improve the functionality of PHP. Search, view, and install various libraries and modules by following the procedure below.

1.  Get a list of available PHP modules with:

apt-cache search php- | less

The command pipes the results of the apt-cache search into less to simplify viewing the output.

The output of apt-cache in Ubuntu.

2. Scroll up and down by using the arrow keys to see all the options, including a short description for each module.

3. For example, to find out what the module php7.4-tidy does, type:

apt-cache show php7.4-tidy

The output displays the module description.

Checking package details using apt-cache.

4. To install the php7.4-tidy package after viewing its description, use the following command:

sudo apt install php7.4-tidy

5. When you finish, press q to quit.

Step 4: Restart Apache

For the changes to take effect, restart the Apache service by typing:

sudo systemctl restart apache2

If the command executes correctly, it returns no output.

Step 5: Test PHP Processing on Web Server

To test the new LAMP installation, create a basic PHP script and place it in the web root directory located at /var/www/html/, then check if the script is accessible via an internet browser. The steps below explain the procedure for performing this test.

1. Create a file in the web root directory by typing the following command:

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

2. Inside the file, type the PHP code:

<?php
phpinfo ();
?>
Creating an info.php file in Nano.

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

4. Open an internet browser and type the following address:

[server-ip-address]/info.php

Alternatively, type:

localhost/info.php

The output should display the details of the LAMP stack, as seen in the image below:

Viewing the PHP version in Firefox.

Note: Hosting a web application on our Bare Metal Cloud platform allows you to eliminate the virtualization overhead and improve the overall app performance.

Conclusion

By following this guide, you successfully installed each layer of the software required to build the LAMP stack on Ubuntu. With LAMP, you have everything necessary to start web application development.

How to Install LAMP in Ubuntu

LAMP stands for Linux, Apache, MySQL, and PHP. It is a web development platform that allows you to create dynamic web applications. Installing LAMP on Ubuntu is a relatively straightforward process. This guide will walk you through the steps of installing LAMP on Ubuntu.

Step 1: Install Apache

The first step in installing LAMP is to install Apache. Apache is a web server that is used to serve web pages. To install Apache, open a terminal window and type the following command:

sudo apt-get install apache2

Once the installation is complete, you can test that Apache is working by opening a web browser and navigating to http://localhost/. You should see a page that says “It works!”

Step 2: Install MySQL

The next step is to install MySQL. MySQL is a database server that is used to store data for web applications. To install MySQL, type the following command in the terminal window:

sudo apt-get install mysql-server

Once the installation is complete, you will be prompted to set a root password for the MySQL server. Make sure to choose a secure password.

Step 3: Install PHP

The final step is to install PHP. PHP is a scripting language that is used to create dynamic web applications. To install PHP, type the following command in the terminal window:

sudo apt-get install php5 libapache2-mod-php5

Once the installation is complete, you can test that PHP is working by creating a file called “info.php” in the /var/www/ directory. The contents of the file should be:

<?php phpinfo(); ?>

Now open a web browser and navigate to http://localhost/info.php. You should see a page that displays information about your PHP installation.

Conclusion

Congratulations! You have successfully installed LAMP on Ubuntu. You can now start developing dynamic web applications with Apache, MySQL, and PHP.

Jaspreet Singh Ghuman

Jaspreet Singh Ghuman

Jassweb.com/

Passionate Professional Blogger, Freelancer, WordPress Enthusiast, Digital Marketer, Web Developer, Server Operator, Networking Expert. Empowering online presence with diverse skills.

jassweb logo

Jassweb always keeps its services up-to-date with the latest trends in the market, providing its customers all over the world with high-end and easily extensible internet, intranet, and extranet products.

Contact
San Vito Al Tagliamento 33078
Pordenone Italy
Item added to cart.
0 items - 0.00
Open chat
Scan the code
Hello 👋
Can we help you?