When you’re setting up an Ubuntu machine to host a website, you need the server software that can serve pages and handle dynamic content. LAMP is a web stack that uses Apache to serve requests, PHP to process pages, and MySQL to store application data.
I’ll show you how to install the Ubuntu repository packages and check that Apache and PHP work locally.
TL;DR
Install Apache, MySQL and PHP from Ubuntu’s configured APT repositories, then check Apache locally and verify PHP through a served file.
- Refresh package metadata with sudo apt update.
- Install apache2, mysql-server, php, libapache2-mod-php and php-mysql.
- Check Apache at http://localhost and test a PHP page from the web root.
What Is a LAMP Stack on Ubuntu?
LAMP is shorthand for Linux, Apache, MySQL and PHP, a common group of software for hosting dynamic websites.
- Linux: the operating system hosting the services.
- Apache: the HTTP server that returns files or passes PHP requests to PHP.
- MySQL: the database service used by applications to store structured data.
- PHP: the server-side language runtime. The php-mysql package provides database connectivity.
This route installs the Ubuntu repository packages directly rather than using Tasksel or adding Oracle’s separate MySQL repository. Choose the separate repository only when a specific MySQL release or vendor package is a requirement.
How to Install LAMP on Ubuntu Step by Step
Use an Ubuntu system with an account allowed to run administrative commands and access to its configured repositories. Install the packages in one apt transaction so the package manager can resolve their dependencies together.
Step 1: Refresh Ubuntu package information
APT uses local package indexes to determine which package versions are available. Refresh those indexes before installing the stack so the transaction uses current metadata from the enabled repositories.
sudo apt update
This refreshes package metadata only. It does not upgrade installed software. Read any repository errors before continuing because an unreachable source can leave APT with incomplete package information.
Step 2: Install Apache, MySQL and PHP packages
Install Apache with the PHP module, the PHP MySQL driver and the Ubuntu MySQL server package in one command. APT displays the packages and dependencies it plans to add before it makes changes.
sudo apt install apache2 mysql-server php libapache2-mod-php php-mysql
Review APT’s proposed package list before confirming. The Apache module is included.
Run this read-only command to inspect APT’s Apache package candidate for the configured Ubuntu repositories.
apt-cache policy apache2
apache2:
Installed: (none)
Candidate: 2.4.58-1ubuntu8.17
Version table:
2.4.58-1ubuntu8.17 500
500 http://ports.ubuntu.com/ubuntu-ports noble-security/main arm64 Packages
2.4.58-1ubuntu8.16 500
500 http://ap-mumbai-1-ad-1.clouds.ports.ubuntu.com/ubuntu-ports noble-updates/main arm64 Packages
2.4.58-1ubuntu8 500
500 http://ap-mumbai-1-ad-1.clouds.ports.ubuntu.com/ubuntu-ports noble/main arm64 Packages

This example shows a Noble candidate for arm64, but APT can select another package version for a different Ubuntu release or architecture.
Step 3: Check Apache on the local machine
The default page provides one local check for Apache after installation, without testing DNS or remote network access. Open http://localhost.
Apache serves its default document directory at /var/www/html. Keep the initial check simple and use the default page before changing virtual hosts or deploying application files.
For a service-level check, ask systemd for Apache’s current state:
sudo systemctl status apache2
Look for an active service state. If it is stopped or failed, read the status details before changing configuration. A browser connection error alone does not explain why the service stopped.
Step 4: Confirm Apache processes a PHP file
A static Apache page does not prove that PHP is executing. Create a temporary file named info.php in /var/www/html with the following content, then request http://localhost/info.php.
<?php
phpinfo();
?>
The PHP information page indicates that Apache handed the file to PHP rather than returning its source as text. The output reveals server configuration, so remove the test file immediately after confirming PHP execution.
sudo rm /var/www/html/info.php
For deployment, use an application-specific health check that exposes only required status information.
What Should You Check After Installing LAMP?
Separate service checks from network checks: Apache can work on localhost while remote requests fail at a firewall or cloud network boundary. Test the local response first, then permit inbound web traffic only if another machine needs access.
| Observation | What it confirms | Next check |
|---|---|---|
| Apache default page appears locally | Apache returned its default site | Configure a site root or virtual host |
| PHP information page appears | Apache is processing PHP | Remove the temporary file |
| Local test works but remote request fails | Local service is responding | Check host firewall and upstream network rules |
A request to localhost does not require an inbound UFW rule because it stays on the same machine. If remote HTTP or HTTPS access is part of your setup and UFW is enabled, inspect its current rules and allow only the required traffic.
MySQL is intended for application data, so do not expose its database port to the public internet as part of a basic web-server setup. Create a dedicated database and account for the application when you install it, and grant only the permissions that application needs.
The default web root is shared by sites configured to use the default Apache site. Before copying an application there, check which user owns its files and which account Apache uses to read them. Avoid making the whole directory writable by every local user just to fix a permission error.
A successful package transaction also does not configure a domain name. A domain needs a DNS record that points to a reachable server address, and the server must have a matching Apache site configuration. Keep those steps separate from the local installation test so a DNS issue does not look like a failed package install.
The database package and authentication defaults can differ across Ubuntu releases. Check the package details for the release in use, and use the operating system’s local administrative access for initial maintenance rather than assuming a root database password was created.
A successful HTTP check says nothing about database connectivity. Confirm an application can authenticate with its own account before treating its data path as ready.
If you need to manage data through a browser, review the phpMyAdmin setup and security steps before exposing its interface. For component-specific setup, see the guides to installing Apache on Ubuntu and installing MySQL on Debian and Ubuntu.
When a local request fails, check Apache’s service state before changing firewall rules. When only PHP fails, confirm that the PHP module packages were installed and inspect Apache’s error details rather than leaving diagnostic files in the document root.
Conclusion: Verify Each Layer Before Adding a Site
A working LAMP base means Ubuntu has the server packages, Apache returns a local page and PHP executes through Apache. Confirm those layers first, then configure a site and a dedicated database account for the application.
Keep the MySQL service private unless a specific network design requires otherwise, and remove temporary diagnostics such as info.php. The Ubuntu PHP guide covers the package-based Apache setup, while the site-specific component guides cover the next configuration steps.
FAQ
These answers cover common package and verification choices.
Does Ubuntu install MySQL or MariaDB with mysql-server?
The package name and available database implementation depend on the Ubuntu release and configured repositories. Check the package description and candidate on your system before assuming which server will be installed.
Does the Apache localhost page mean the server is reachable remotely?
No. It confirms a local request reached Apache. Remote access also depends on the host firewall, network rules and the address used by the client.
How can I check that PHP works with Apache?
Create a temporary PHP file in the Apache document root and request it locally. A PHP information page confirms PHP execution, but remove the file immediately because it exposes configuration details.
