How to Install LAMP on Ubuntu 24.04.1

Step 1. Update the system

Before we start with the installation of the LAMP stack we need to update the system packages to their latest versions available. To do that, execute the following commands:

sudo apt update -y && sudo apt upgrade -y

Step 2. Install Apache Web server

The Apache web server is open-source software written in C and can run on multiple operating systems such as Windows, Linux, OpenVMS, etc. According to the world statistics, the Apache web server is currently the most used, leading Nginx and Cloudflare as its concurrent.

To install the Apache web server, execute the commands below:

sudo apt install apache2 -y

Once the web server is installed, we need to start and enable the apache2 service:

sudo systemctl start apache2 && sudo systemctl enable apache2

To check the status of the service, execute the following command:

sudo systemctl status apache2

If everything is OK, you should receive the following output:

root@apache:~$ sudo systemctl status apache2
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
     Active: active (running) since Thu 2024-12-12 14:38:48 UTC; 33s ago
       Docs: https://httpd.apache.org/docs/2.4/
   Main PID: 3014 (apache2)
      Tasks: 55 (limit: 2276)
     Memory: 5.4M (peak: 5.5M)
        CPU: 23ms
     CGroup: /system.slice/apache2.service
             ├─3014 /usr/sbin/apache2 -k start
             ├─3016 /usr/sbin/apache2 -k start
             └─3017 /usr/sbin/apache2 -k start

Dec 12 14:38:48 apache systemd[1]: Starting apache2.service - The Apache HTTP Server...
Dec 12 14:38:48 apache apachectl[3013]: AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1. Set the 'ServerName' directive globally to suppress this message
Dec 12 14:38:48 apache systemd[1]: Started apache2.service - The Apache HTTP Server.

Step 3. Install MySQL database system

MySQL is an open-source relational database management system. As a component of the LAMP stack MySQL is used by many database-driven web applications such as WordPress, Drupal, Joomla, etc. To install MySQL, execute the following command:

sudo apt install mysql-server -y

Once the MySQL server is installed, we need to start and enable the service:

sudo systemctl start mysql && sudo systemctl enable mysql

To check the status of the service, execute the following command:

sudo systemctl status mysql

You should get output similar to this:

root@host:# sudo systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Wed 2024-03-13 20:40:18 CDT; 2min 55s ago
   Main PID: 59835 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 4624)
     Memory: 365.1M (peak: 379.4M)
        CPU: 2.611s
     CGroup: /system.slice/mysql.service
             └─59835 /usr/sbin/mysqld

Mar 13 20:40:17 host.test.vps systemd[1]: Starting mysql.service - MySQL Community Server...
Mar 13 20:40:18 host.test.vps systemd[1]: Started mysql.service - MySQL Community Server.

Step 4. Install PHP

PHP is a “Hypertext Preprocessor” server-side scripting language used for creating dynamic web pages. It is widely used by developers around the world. As a part of the LAMP stack on Ubuntu 24.04, the included version of PHP in the Ubuntu 24.04 repository is PHP8.3. To install PHP8.3 with its extensions, execute the following command:

sudo apt install php8.3 php8.3-cli php8.3-{bz2,curl,mbstring,intl} -y

Once installed, you can check the PHP version with the command below:

php -v

You should get the following output:

root@host:~# php -v
PHP 8.3.0-1ubuntu1 (cli) (built: Jan 19 2024 14:00:34) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.0, Copyright (c) Zend Technologies
    with Zend OPcache v8.3.0-1ubuntu1, Copyright (c), by Zend Technologies

PHP was the last software of the LAMP stack.

That’s it. You successfully installed the LAMP stack on Ubuntu 24.04