Skip to content
Follow
Ubuntu Linux

How to Install LAMP on Ubuntu Linux

Richard
Written by
Richard
Sep 15, 2021 Updated Jul 14, 2026 5 min read
How to Install VMware Workstation Player on Ubuntu Linux
How to Install VMware Workstation Player on Ubuntu Linux

A LAMP stack on Ubuntu Linux sets up a complete environment for running websites and web apps.

LAMP stands for Linux, Apache, MySQL (or MariaDB), and PHP. These are key open-source programs that work together to make dynamic sites function.

This combination, often running on Ubuntu 22.04 LTS, powers popular platforms like WordPress. It lets you host your own PHP projects right from your computer.

To get started, you’ll need Ubuntu Linux, Apache 2.4 or newer, MySQL 8.0 or newer, and PHP 8.1 or newer.

⚡ Quick Answer

Install LAMP on Ubuntu by updating packages and installing Apache, MariaDB, and PHP. Use `sudo apt update` and `sudo apt install apache2 mariadb-server php libapache2-mod-php php-mysql`.

How to install Ubuntu Linux

Installing Ubuntu Linux is the first step before you can set up LAMP. Ubuntu is a user-friendly operating system, making it a good choice for beginners who want to build a web server. After installing Ubuntu, you’ll run a couple of commands to update your system and prepare it for the next parts of the LAMP installation.

Ubuntu Linux installation is the first task for LAMP configuration. Users new to Ubuntu can follow a linked guide to learn how to install the Ubuntu operating system.

Once Ubuntu is installed, run the commands below to update it.

🐧Bash / Shell
sudo apt update
sudo apt dist-upgrade
sudo apt autoremove

There are lots of other settings and configurations to apply that apply to Ubuntu. However, the post is only concerned with installing LAMP.

How to install Apache on Ubuntu Linux

Apache is the web server that runs your website files when you install LAMP on Ubuntu. Installing Apache is simple using a few commands. This section shows you how to install the apache2 package and then explains how to manage the Apache service, like starting, stopping, or making it start automatically when your computer boots up.

🐧Bash / Shell
sudo apt update
sudo apt install apache2
⚠️Warning
After installing Apache, the commands below can be used to stop, start and enable Apache service always to start up when the server starts.
🐧Bash / Shell
sudo systemctl stop apache2
sudo systemctl start apache2
sudo systemctl enable apache2

To see if Apache is installed, open a web browser and browse to the server hostname or IP address.

http://localhost

Apache2 test page on Ubuntu
apache2 test page

If you see the above Apache welcome page, it means Apache is installed and functioning.

How to install MariaDB on Ubuntu Linux

MariaDB is the database server that stores all your website’s data for your LAMP setup. Installing MariaDB on Ubuntu is a straightforward process using just a few commands. This guide will walk you through installing MariaDB, which is a popular alternative to MySQL, and how to confirm it’s working correctly after the installation.

For this post, we will install MariaDB instead of MySQL.

To install MariaDB, run the commands below.

🐧Bash / Shell
sudo apt update
sudo apt install mariadb-server

After installing, you can run the commands below to view the MariaDB service status.

🐧Bash / Shell
sudo systemctl status mariadb

After running the command above, it should output similar lines.

💻Code
mariadb.service - MariaDB 10.3.31 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2021-09-15 16:40:20 CDT; 22s ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
   Main PID: 3007 (mysqld)
     Status: "Taking your SQL requests now..."
      Tasks: 31 (limit: 4651)
     Memory: 65.6M
     CGroup: /system.slice/mariadb.service
             └─3007 /usr/sbin/mysqld

Sep 15 16:40:20 ubuntu2004 /etc/mysql/debian-start[3045]: mysql
Sep 15 16:40:20 ubuntu2004 /etc/mysql/debian-start[3045]: performance_schema

MariaDB and MySQL have a script allowing you to perform security operations.

Run the commands below to invoke the script and perform some recommended tasks to secure the database.

🐧Bash / Shell
sudo mysql_secure_installation

MariaDB and MySQL servers have the root user set to use the auth_socket authentication method by default.

The auth_socket plugin authenticates users that connect from the local host through the Unix socket file. You can’t authenticate as a root by providing a password.

Simply run the command below to log on to MariaDB and MySQL servers as root. You don’t need a password since it’s using the auth_socket method.

To log on to MariaDB, run the commands below.

🐧Bash / Shell
sudo mysql

The server console should come up.

💻Code
Welcome to the MySQL monitor.  Commands end with ; or g.
Your MySQL connection id is 8
Server version: 8.0.26-0ubuntu0.20.04.2 (Ubuntu)

Copyright (c) 2000, 2021, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

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

mysql> 

How to install PHP on Ubuntu Linux

PHP is the programming language that makes your website dynamic within a LAMP setup. You can easily install PHP on Ubuntu along with Apache using simple commands. This section covers installing PHP and the necessary Apache module, and also explains how to add a special software source if you need a different PHP version than what Ubuntu provides by default.

🐧Bash / Shell
sudo apt update
sudo apt install php libapache2-mod-php

To install the latest PHP versions unavailable in the Ubuntu repository, run the commands below to install a third-party PPA repository that includes multiple versions of PHP.

At the time of this writing, the latest version of PHP is 8.0.

🐧Bash / Shell
sudo apt install software-properties-common
sudo add-apt-repository ppa:ondrej/php

After adding the repository above, you can then install another PHP version.

🐧Bash / Shell
sudo apt install php8.0 php8.0-common php8.0-cli php8.0-gd php8.0-curl php8.0-mysql

That should do it!

For more on LAMP, read individual posts on the LAMP components

Conclusion:

The LAMP stack installation guide provides instructions for installing the LAMP stack on Ubuntu Linux. You can submit errors or suggested additions to the LAMP stack installation guide using the comment form located below.

Was this guide helpful?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

📚 Related Tutorials

How to Install Ubuntu Linux
Ubuntu Linux How to Install Ubuntu Linux
How to Install Apache on Ubuntu Linux
Ubuntu Linux How to Install Apache on Ubuntu Linux
How to Install PHP on Ubuntu Linux
Ubuntu Linux How to Install PHP on Ubuntu Linux
How to Install GNOME Desktop on Ubuntu 24.04
Ubuntu Linux How to Install GNOME Desktop on Ubuntu 24.04

2 Comments

Leave a Comment

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