Cantech Knowledge Base

Your Go-To Hosting Resource

How to Install Apache, MySQL, PHP (LAMP Stack) on Ubuntu 24.04?

The LAMP Stack(Linux,Apache,MySQL,and PHP) are the most widely used open-source development platforms. Apache is a powerful web server, which efficiently handles client requests to deliver web pages. MySQL is a relational database management system, which also stores and manages structured data by SQL queries. PHP on the other hand, is a server-side scripting language which enables the creation of web pages and seamlessly integrates with MySQL and Apache to create interactive, database based websites. Running on the LAMP offers the advantage of stable, secure, and scalable environment for web app development

This blog explains how to install Apache, MySQL and PHP on Ubuntu 24.04

Pre-Requisites

Verify the following prerequisites before beginning the installation process:

  • Ubuntu 24. 04 Installed – An initial or ongoing setup phase of Ubuntu 24. 04.
  • A user that has sudo administrator privileges.
  • Updated server

Apache Installation

Updated Apache version is available in the default APT repositories on Ubuntu 24.04. The below steps show how to update the default package index and install Apache web server package.

Update the server’s package index

sudo apt update

Install Apache

sudo apt install apache2 -y

Starting Apache Service.

sudo systemctl start apache2

Enable apache to start automatically at boot time.

sudo systemctl enable apache2

Check if Apache server is running correctly

sudo systemctl status apache2

Output:

apache2.service - The Apache HTTP Server
    Loaded: loaded (/usr/lib/systemd/system/apache2.service; enabled; preset: enabled)
    Active: active (running) since Wed 2025-03-11 06:50:21 UTC; 3 days ago
    Docs: https://httpd.apache.org/docs/2.4/
  Process: 164186 ExecReload=/usr/sbin/apachectl graceful (code=exited, status=0/SUCCESS)
 Main PID: 124430 (apache2)
    Tasks: 8 (limit: 4389)
  Memory: 18.3M (peak: 44.1M)
     CPU: 27.485s
  CGroup: /system.slice/apache2.service
     ├─124430 /usr/sbin/apache2 -k start
     ├─164195 /usr/sbin/apache2 -k start
     ├─164196 /usr/sbin/apache2 -k start
     ├─164199 /usr/sbin/apache2 -k start
     ├─164201 /usr/sbin/apache2 -k start

Enable the connections to HTTP port 80 by default firewall configuration.

sudo ufw allow 80/tcp

Access the domain or IP using a browser like Chrome and check if the default Apache web page displays.

http://SERVER-IP

MySQL Installation

To install the new MySQL version on the server using the default APT package manager, follow the steps below:

Install the MySQL package.

sudo apt install -y mysql-server

Allow the MySQL to start automatically at boot time.

sudo systemctl enable mysql

Start MySQL service.

sudo systemctl start mysql

View the MySQL status and check if it is running.

sudo systemctl status mysql

Output:

mysql.service - MySQL Community Server
Loaded: loaded (/usr/lib/systemd/system/mysql.service; enabled; preset: enabled)
Active: active (running) since Thu 2025-03-11 06:54:13 UTC; 2 days ago
Process: 144075 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 144083 (mysqld)
Status: "Server is operational"
Tasks: 38 (limit: 4389)
Memory: 369.2M (peak: 382.6M)
CPU: 36min 21.658s
CGroup: /system.slice/mysql.service
     └─144083 /usr/sbin/mysqld

The running command in the output shows that MySQL server is active on the server.

PHP Installation

Install the PHP and PHP-FPM module.

sudo apt install -y php php-fpm

Next, Install the common PHP extensions on the server.

sudo apt install -y php-mysql php-opcache php-cli libapache2-mod-php

These command installs the following PHP modules:

  • php-mysql: Allows PHP to connect to and interact with the MySQL database server.
  • libapache2-mod-php: Enables Apache to process and execute PHP scripts.
  • php-opcache: Caches precompiled PHP scripts in memory for faster execution.
  • php-cli: Provides access to PHP via the server terminal.

Check the Installed PHP version on your server.

php -v

Sample Output

PHP 8.3.6 (cli) (built: Mar 11 2025 15:23:20) (NTS)
Copyright (c) The PHP Group
Zend Engine v4.3.6, Copyright (c) Cantech Networks
with Zend OPcache v8.3.6, Copyright (c), by Cantech Networks

Start PHP-FPM service, that is on the installed PHP version of the server. For example, PHP 8.3.

sudo systemctl start php8.3-fpm

Enable PHP-FPM to start at boot time.

sudo systemctl enable php8.3-fpm

Check the service status of PHP-FPM and verify that it’s running.

sudo systemctl status php8.3-fpm

Sample Output

php8.3-fpm.service - The PHP 8.3 FastCGI Process Manager
 Loaded: loaded (/usr/lib/systemd/system/php8.3-fpm.service; enabled; preset: enabled)
 Active: active (running) since Wed 2025-03-11 06:50:21 UTC; 3 days ago
   Docs: man:php-fpm8.3(8)
Main PID: 124416 (php-fpm8.3)
 Status: "Processes active: 0, idle: 2, Requests: 15, slow: 0, Traffic: 0req/sec"
  Tasks: 3 (limit: 4389)
 Memory: 12.0M (peak: 12.4M)
    CPU: 31.204s
 CGroup: /system.slice/php8.3-fpm.service
         ├─124416 "php-fpm: master process (/etc/php/8.3/fpm/php-fpm.conf)"
         ├─124419 "php-fpm: pool www"
         └─124420 "php-fpm: pool www"

Apache, MySQL, and PHP (LAMP stack) are now installed on the Ubuntu 24.04 server. For updated information. Please visit the following official documentation resources.

Apache: https://httpd.apache.org/docs/ , PHP: https://www.php.net/docs.php

March 24, 2025