Installing LAMP server on Ubuntu 22.04 LTS Noble

We can have a web server environment on Ubuntu 24.04 Linux by installing a popular LAMP stack (Linux, Apache, MySQL, PHP) for hosting various web applications such as WordPress.

The individual software components of LAMP are Linux, Apache, MySQL, and PHP, each performs different tasks and provides different functions.

Linux- Open source OS

Linux doesn’t need an introduction, it is a popular open-source operating system to control hardware and running applications. Out of the most popular Linux distros, some are Ubuntu, Debian, RedHat, Fedora, and more…

Apache Web Server

Apache web server is one of the key elements of the LAMP environment. It is a popular HTTP server that powers hundreds of hosting servers. The web server can access static content or forward dynamic requests to a server-side scripting language such as PHP, Perl, or Python.

MySQL database management system

MySQL is an open-source SQL database server used in the LAMP stack environment to store data generated by web applications. Together with the PHP scripting language, MySQL generates the dynamic content that the Apache web server then delivers to the client.

PHP scripting language

PHP stands for Hypertext Preprocessor and is a scripting language that can be used as free software. It can be used with the various Database servers and MySQL is one of them. PHP takes care of the server-side processing of the PHP code to generate the dynamic content.

Advantages of a LAMP system

1. Widely used and supported by a huge developers community.
2. Stable and Mature
3. Quickly patched if some error or vulnerabilities occur.
4. Free and open source, hence the source is open to everyone.
5. Distribution under GPL license allows users to create their useful extensions or apps around the components of Lamp stack.
6. LAMP servers offer a high degree of flexibility.
7. Provide high performance for the generation of dynamic web content.

In this article, we learn the commands to install the LAMP stack on Ubuntu 24.04 LTS

Step 1. Update Ubuntu 24.04 server

Open your Ubuntu 24.04 command terminal to run the system update and upgrade command that not only rebuilds the repository package cache but also installs the latest updates available for the system

sudo apt update && sudo apt upgrade -y

Step 2: Installing Apache (webserver)

Being a popular web server software, we can easily have the latest and well-stabled version of Apache through the default system repository of Ubuntu 24.04.

sudo apt install apache2

Start and Enable Apache:

sudo systemctl enable --now apache2

To check its service status use:

sudo systemctl status apache2 --no-pager -l

Step 3: Install MySQL or MariaDB (Database Server):

Now, there is an important thing that we want to tell you: both MySQL and MariaDB are open source and use similar command lines. However, MySQL has been developed by Oracle whereas MariaDB is forked from MySQL source code by a community of developers and maintained by them as well.

Here, we show you the installation of both, go for the one as per your choice or requirements.

Note: Install only one Database server, not both…

For MariaDB server:

sudo apt install mariadb-server

Users who are using the MariaDB server can start & enable its service using the following commands:

sudo systemctl start mariadb
sudo systemctl enable mariadb

To check the service status:

sudo systemctl status mariadb --no-pager -l

For MySQL server:

Just like MariaDB, we can also install the popular MySQL server, in case you don’t the MariaDB.

sudo apt install mysql-server

After completing the installation of the Database server as per your choice, start the MySQL service and enable it to get activated on system boot:

Similarly, those who are using MySQL instead of MariaDB can use:

sudo systemctl start mysql
sudo systemctl enable mysql

To check the service status:

sudo systemctl status mysql --no-pager -l

Step 4: Secure Your MySQL Installation

Although MySQL/MariaDB is already secured out of the box, however, to make its installation secure a bit more run the script to remove the anonymous user, disable remote login, and set the root password, if not already.

sudo mysql_secure_installation

See the screenshot to get an idea:

mysql secure installation Ubuntu 24.04

Step 5: Installing PHP on Ubuntu 24.04

PHP is the most common and widely used programming language that helps web applications deliver dynamic web pages and other functions with the help of various modules. To install the PHP and necessary modules, use:

sudo apt install php libapache2-mod-php

The above command will install the default version of PHP available through your Ubuntu 24.04 repository. However, if you want old or new versions that are not available through the system repository then add the third part repo called Sury.

Step 6: Test the LAMP Stack using PHP info

Your LAMP stack has been installed successfully on Ubuntu 24.04. Now, let’s check all the components are working fine including PHP, for that we can create a simple PHP test file to ensure that the LAMP stack is running correctly.

Use a text editor to create a new file:

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

Now, add the following line:

// Show PHP information

Save the file by pressing Ctlr+X, typing Y, and then hitting the Enter key.

Access the test page or PHP info page in our browser by pointing it to:



You should see a page with PHP information.

php test page

Note: Although the HTTP port by default is opened on Linux or cloud services’ firewalls. However, if not then don’t forget to whitelist ports 80 and 443 on your server.

For locally installed Ubuntu 24.04 servers with UFW firewall can use the following command:

sudo ufw allow 'Apache Full'

Step 7: Additional PHP Modules

Depending on your application, your PHP requirements will be different, so after setting up the LAMP server check the PHP modules needed by your application and install them.

You can search for available PHP modules using:

sudo apt search php-

To install a specific module, use a command like:

sudo apt install php-mysql

Replace “php-mysql” with the module you need.


You have seen the installation of LAMP on Ubuntu 24.04 but all this can done by using a single command – sudo apt install lamp-server^ php , in case you don’t want to install each component individually. Once you have the LAMP stack, you can start building or hosting your web application either on a local server or cloud. Don’t forget to secure your server and your applications as needed for your specific use case.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.