How to Install the LAMP Stack on Ubuntu 26.04

The LAMP stack remains one of the most widely deployed web application platforms in the world, and learning how to lamp stack install ubuntu 26.04 gives you a reliable foundation for hosting dynamic websites, content management systems, and custom PHP applications. LAMP combines four mature, open-source components: Linux as the operating system, Apache as the web server, MySQL as the relational database, and PHP as the server-side scripting language. On Ubuntu 26.04 Resolute Raccoon, all three user-space components are available directly from the default repositories, making the installation process straightforward.

This tutorial focuses on bringing the stack together. Rather than duplicating detailed installation instructions that already exist for each component, this guide walks you through the prerequisite steps, then concentrates on integration: configuring Apache to process PHP, connecting PHP to MySQL, testing the complete stack end to end, and applying basic security measures. By the end, you will have a working LAMP server ready to host your first PHP application.

In this tutorial you will learn:

  • What the LAMP stack is and how its components work together
  • How to install Apache, MySQL, and PHP on Ubuntu 26.04
  • How to configure Apache to process PHP files
  • How to connect PHP to a MySQL database
  • How to test the complete stack end to end
  • How to apply basic security measures to a LAMP server
Installing and configuring the LAMP stack on Ubuntu 26.04 Resolute Raccoon

Software Requirements

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Ubuntu 26.04 Resolute Raccoon
Software Apache 2.4, MySQL Server, PHP 8.5 (all from default Ubuntu 26.04 repositories)
Other Privileged access to your Linux system as root or via the sudo command. Internet connection to download packages.
Conventions # – requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ – requires given linux commands to be executed as a regular non-privileged user

PREREQUISITES

Before starting this tutorial, make sure you have completed the following component guides on your Ubuntu 26.04 system:

This tutorial focuses on tying the three components together. If you prefer a quick combined install, the next section provides the condensed commands.

TL;DR
Install all three LAMP components with one command, then enable PHP processing in Apache.

Quick Steps to Install the LAMP Stack on Ubuntu 26.04
Step Command/Action
1. Update package index $ sudo apt update
2. Install Apache, MySQL, and PHP $ sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
3. Secure the MySQL installation $ sudo mysql_secure_installation
4. Restart Apache to load PHP $ sudo systemctl restart apache2

What Is the LAMP Stack?

LAMP is an acronym for the four components that make up this classic web platform: Linux, Apache, MySQL, and PHP. Each layer plays a specific role in handling a web request. Linux provides the underlying operating system, Apache receives HTTP requests from browsers, PHP executes server-side logic, and MySQL stores and retrieves application data.

When a visitor opens a PHP page served by a LAMP server, Apache receives the request, passes the script to the PHP interpreter, which in turn may query MySQL for data. PHP then generates HTML output that Apache returns to the browser. This architecture has powered a huge portion of the modern web for more than two decades, and it still runs many of the world’s most popular applications, including WordPress, Drupal, Joomla, phpBB, and countless custom business applications.

Although newer stacks exist, such as LEMP (which replaces Apache with Nginx) or container-based deployments, LAMP remains relevant because it is well documented, widely supported, easy to debug, and compatible with virtually every PHP application ever written. Additionally, Ubuntu 26.04 ships stable, up-to-date versions of every component, so you get current security patches without relying on third-party repositories. If you prefer a fully open-source database without Oracle involvement, you can substitute MySQL with MariaDB, a drop-in compatible fork maintained by the community.

Install the LAMP Stack on Ubuntu 26.04

Because each component has its own dedicated article linked in the prerequisites box above, this section gives you a condensed, single-command approach for readers who want to get the whole stack running quickly. However, if you want deeper coverage of configuration options for any individual component, refer to the corresponding prerequisite guide.

  1. Refresh the package index: Ensure APT pulls the latest available versions of each package.
    $ sudo apt update
  2. Install all LAMP components in a single command: This installs Apache, MySQL, PHP, the Apache PHP module, and the PHP MySQL extension together.
    $ sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql

    Confirm when prompted. APT resolves all dependencies automatically. During installation, both the Apache and MySQL services start automatically and are enabled to run at boot.

  3. Verify each service is running: Use systemctl to confirm that Apache and MySQL are active.
    $ sudo systemctl status apache2
    $ sudo systemctl status mysql

    Both services should report active (running). PHP does not run as a persistent service in this configuration because it is loaded as an Apache module.

  4. Run the MySQL hardening script: Set a root password, remove anonymous users, and disallow remote root login.
    $ sudo mysql_secure_installation

    Answer the prompts as recommended in the MySQL prerequisite guide. Skipping this step leaves the database server in an insecure default state.

At this point, all three software components are installed. The next sections focus on making them talk to each other.

Configure Apache to Process PHP Files

After installing libapache2-mod-php, Apache is already capable of handing .php files to the PHP interpreter. Nevertheless, it is good practice to verify this with a small test page before moving on.

  1. Confirm the PHP module is enabled in Apache: Ubuntu enables the module automatically at install time, but you can verify explicitly.
    $ sudo apache2ctl -M | grep php

    The output should include a line referencing the active PHP module, such as php_module.

  2. Create a PHP info test page: Write a tiny script to Apache’s default document root.
    $ echo '<?php phpinfo(); ?>' | sudo tee /var/www/html/info.php

    The phpinfo() function prints a full report of the active PHP configuration, which is extremely useful for confirming that Apache is actually invoking PHP rather than serving the file as plain text.

  3. Restart Apache to ensure all modules are loaded: Although not strictly required after a fresh install, a restart is safe.
    $ sudo systemctl restart apache2
  4. Open the test page in a browser: Navigate to the server’s IP address followed by /info.php. For example, on a local machine you would visit http://localhost/info.php, and on a remote server http://192.168.1.7/info.php. You should see the familiar purple-and-gray PHP information page showing the PHP version, loaded extensions, and configuration directives.

    Browser window showing PHP 8.5.4 phpinfo output page served by Apache on Ubuntu 26.04 at 192.168.1.7/info.phpBrowser window showing PHP 8.5.4 phpinfo output page served by Apache on Ubuntu 26.04 at 192.168.1.7/info.php
    Apache successfully processing a PHP file and rendering the phpinfo() output

SECURITY ALERT

The info.php page exposes detailed information about your server configuration, installed modules, and file paths. Therefore, always delete this file after testing is complete: sudo rm /var/www/html/info.php. Leaving it accessible is a common mistake that gives attackers a reconnaissance advantage.

If the browser displays the raw PHP source code instead of the rendered page, then Apache is not passing the file to PHP. Consequently, verify that libapache2-mod-php is installed, that sudo a2enmod php8.5 reports the module as enabled, and that Apache was restarted after installation.

Connect PHP to MySQL on Ubuntu 26.04

With Apache and PHP working together, the next integration step is giving PHP the ability to talk to MySQL. The php-mysql package (installed in the previous section) provides the mysqli and PDO_MySQL extensions, which are the two standard interfaces PHP uses to communicate with MySQL.

  1. Verify the MySQL extension is loaded by PHP: Query PHP’s active modules from the command line.
    $ php -m | grep -i mysql

    You should see mysqli, mysqlnd, and pdo_mysql in the output. If none appear, confirm that php-mysql is installed and restart Apache.

  2. Create a test database and a dedicated user: Log in to MySQL as root and set up a database the PHP test script can connect to.
    $ sudo mysql

    At the MySQL prompt, run the following statements:

    mysql> CREATE DATABASE linuxconfig_db;
    mysql> CREATE USER 'linuxconfig_user'@'localhost' IDENTIFIED BY 'StrongPassword123!';
    mysql> GRANT ALL PRIVILEGES ON linuxconfig_db.* TO 'linuxconfig_user'@'localhost';
    mysql> FLUSH PRIVILEGES;
    mysql> EXIT;

    This creates a database named linuxconfig_db and a user linuxconfig_user with full privileges on that database only, following the principle of least privilege.

  3. Add a sample table with data: So there is something to query during testing.
    $ mysql -u linuxconfig_user -p linuxconfig_db

    Enter the password you set. Then at the prompt:

    mysql> CREATE TABLE greetings (id INT AUTO_INCREMENT PRIMARY KEY, message VARCHAR(255));
    mysql> INSERT INTO greetings (message) VALUES ('Hello from LinuxConfig.org');
    mysql> EXIT;
  4. Write a PHP script that queries the database: Create a file that demonstrates the full PHP-to-MySQL round trip.
    $ sudo nano /var/www/html/dbtest.php

    Paste the following content:

    <?php
    $host="localhost";
    $db       = 'linuxconfig_db';
    $user="linuxconfig_user";
    $pass="StrongPassword123!";
    $charset="utf8mb4";
    
    $dsn = "mysql:host=$host;dbname=$db;charset=$charset";
    try {
        $pdo = new PDO($dsn, $user, $pass);
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $stmt = $pdo->query('SELECT message FROM greetings');
        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
            echo htmlspecialchars($row['message']) . "<br>";
        }
    } catch (PDOException $e) {
        echo 'Database connection failed: ' . $e->getMessage();
    }
    ?>

    Save and exit. This script uses PDO (PHP Data Objects), the modern recommended interface for database access in PHP.

  5. Load the test script in a browser: Visit http://192.168.1.7/dbtest.php. If everything is configured correctly, the page displays the greeting message stored in the database.

    Browser window showing dbtest.php page rendering "Hello from LinuxConfig.org" retrieved from the MySQL database on Ubuntu 26.04Browser window showing dbtest.php page rendering "Hello from LinuxConfig.org" retrieved from the MySQL database on Ubuntu 26.04
    The dbtest.php script reads a record from the MySQL database and displays it through Apache

COMPLETED

If the browser displays “Hello from LinuxConfig.org”, then Apache, PHP, and MySQL are all communicating correctly. Your LAMP stack is fully operational.

Test the Complete LAMP Stack

The dbtest.php script already validates the full request path: browser → Apache → PHP → MySQL → PHP → Apache → browser. However, real-world issues often show up only when things go wrong, so knowing how to diagnose common failures saves significant time.

  1. Apache returns the PHP source code instead of executing it: This means Apache is not recognizing .php files as PHP scripts.
    $ sudo apt install libapache2-mod-php
    $ sudo a2enmod php8.5
    $ sudo systemctl restart apache2

    Moreover, ensure no conflicting handler directives exist in /etc/apache2/mods-enabled/.

  2. “Database connection failed: SQLSTATE[HY000] [2002]”: PHP cannot reach MySQL on the network layer. Verify MySQL is running and bound to localhost.
    $ sudo systemctl status mysql
    $ sudo ss -tlnp | grep 3306

    You should see MySQL listening on 127.0.0.1:3306.

  3. “Access denied for user”: The username, password, or host part of the grant does not match what the script uses. Log in to MySQL and re-check the grants:
    mysql> SELECT User, Host FROM mysql.user WHERE User="linuxconfig_user";
    mysql> SHOW GRANTS FOR 'linuxconfig_user'@'localhost';
  4. Blank page with no output: PHP errors may be suppressed. Temporarily enable error display in the script by adding ini_set('display_errors', 1); error_reporting(E_ALL); at the top of the file, then reload the page to see the underlying problem.

Checking the Apache error log is often the fastest way to diagnose issues:

$ sudo tail -n 50 /var/log/apache2/error.log

Additionally, MySQL’s error log provides context for database-side failures:

$ sudo tail -n 50 /var/log/mysql/error.log

Basic Security for a LAMP Server

A working LAMP stack is only the starting point. Consequently, before exposing the server to the internet or putting real data on it, apply these baseline security measures.

  1. Remove the phpinfo test page: Delete any testing scripts that leak configuration details.
    $ sudo rm /var/www/html/info.php
    $ sudo rm /var/www/html/dbtest.php
  2. Open only the necessary firewall ports: If you have a firewall enabled, allow HTTP (port 80) and HTTPS (port 443) while blocking everything else. Refer to how to allow ports with UFW on Ubuntu 26.04 for detailed UFW configuration. In short:
    $ sudo ufw allow in "Apache Full"
    $ sudo ufw enable
    $ sudo ufw status

    The Apache Full profile opens both 80 and 443.

  3. Enable HTTPS with a real certificate: Serving a production site over plain HTTP is unacceptable. Install a free Let’s Encrypt certificate once you have a domain pointed at the server, which encrypts all traffic and prevents credential interception.
  4. Apply the principle of least privilege to database users: Never let a web application log in to MySQL as root. Furthermore, grant each application only the specific privileges on the specific database it needs, exactly as demonstrated above with linuxconfig_user.
  5. Keep the stack patched: Ubuntu 26.04 receives regular security updates through the standard update channels.
    $ sudo apt update && sudo apt upgrade

    Additionally, consider enabling unattended security upgrades so critical patches apply automatically.

For a comprehensive overview of LAMP deployment options and Ubuntu-specific recommendations, consult the official Ubuntu Server documentation on LAMP applications.

Conclusion

You now have a fully functional LAMP stack on Ubuntu 26.04 Resolute Raccoon, with Apache serving web pages, PHP processing dynamic content, and MySQL storing application data. The integration steps in this guide (enabling the PHP module in Apache, installing the php-mysql extension, creating a scoped database user, and running an end-to-end test script) are the essential glue that turns three separate packages into a working web platform.

From here, you can install popular LAMP-based applications such as WordPress, phpMyAdmin, or a custom PHP project. Most importantly, keep the components patched, close unused ports, and never leave test files accessible from the web. With those habits in place, a LAMP server on Ubuntu 26.04 gives you a stable, well-understood, and production-ready foundation.

Frequently Asked Questions

  1. What is the difference between LAMP and LEMP on Ubuntu 26.04? LAMP uses Apache as the web server, while LEMP uses Nginx (the “E” is pronounced like “engine-x”). Apache tends to be more flexible out of the box with per-directory configuration via .htaccess files, making it friendlier for traditional PHP applications. Nginx, on the other hand, generally uses less memory under high concurrency and performs well as a reverse proxy. Both stacks are fully supported on Ubuntu 26.04, and the choice depends on your workload and familiarity.
  2. Can I use MariaDB instead of MySQL in a LAMP stack? Yes. MariaDB is a community-developed fork of MySQL that is drop-in compatible for the vast majority of applications. You simply install the mariadb-server package instead of mysql-server, and PHP’s php-mysql extension works with both. Many distributions and application vendors actually recommend MariaDB as the default.
  3. Which PHP version ships with Ubuntu 26.04? Ubuntu 26.04 Resolute Raccoon ships PHP 8.5 from the default repositories. You can verify the exact version on your system by running php -v after installation. If you need a different version (for legacy applications or cutting-edge features), the Ondrej Sury PPA provides multiple PHP versions installable side by side.
  4. How do I serve multiple websites from the same LAMP server? Apache supports virtual hosts, which allow one server to respond differently based on the requested domain name. You create a separate configuration file in /etc/apache2/sites-available/ for each site, enable it with sudo a2ensite sitename.conf, and reload Apache. The Apache prerequisite guide covers virtual host setup in detail.
  5. Do I need to run mysql_secure_installation on a development machine? Yes, even for a local development server. The script sets a root password, removes anonymous accounts, and deletes the test database. Although development data is not public, building the habit of hardening MySQL every time prevents accidents when you later copy configurations or scripts to a production server.

PakarPBN

A Private Blog Network (PBN) is a collection of websites that are controlled by a single individual or organization and used primarily to build backlinks to a “money site” in order to influence its ranking in search engines such as Google. The core idea behind a PBN is based on the importance of backlinks in Google’s ranking algorithm. Since Google views backlinks as signals of authority and trust, some website owners attempt to artificially create these signals through a controlled network of sites.

In a typical PBN setup, the owner acquires expired or aged domains that already have existing authority, backlinks, and history. These domains are rebuilt with new content and hosted separately, often using different IP addresses, hosting providers, themes, and ownership details to make them appear unrelated. Within the content published on these sites, links are strategically placed that point to the main website the owner wants to rank higher. By doing this, the owner attempts to pass link equity (also known as “link juice”) from the PBN sites to the target website.

The purpose of a PBN is to give the impression that the target website is naturally earning links from multiple independent sources. If done effectively, this can temporarily improve keyword rankings, increase organic visibility, and drive more traffic from search results.

Jasa Backlink

Download Anime Batch

Leave a Reply

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