What Is the LAMP Stack?
By the end of this lesson you will be able to name the job of each part of the LAMP stack, trace one web request from the browser to the database and back, and explain when LAMP is a good choice. You will also meet ShikshaPortal, the school app we build in this course, and its folder layout.
What you should know first: basic PHP from the PHP tutorial, basic SQL from the SQL tutorial, and a little of the Linux terminal from the Linux tutorial. This course does not teach those from zero. It teaches how they work together.
Four parts, one job each
LAMP is a set of four free, open-source programs that together run a website. The name is the first letter of each:
| Letter | Program | Its job | Version taught | Learn the basics |
|---|---|---|---|---|
| L | Linux (Ubuntu) | The operating system that runs everything else | Ubuntu 26.04 LTS | Linux Introduction |
| A | Apache HTTP Server | Receives web requests and sends back responses | 2.4 | Apache lesson in this course |
| M | MySQL (or MariaDB) | Stores data in tables | MySQL 8.4 LTS | SQL Introduction |
| P | PHP | Runs your code and builds each page | 8.5 | PHP Introduction |
A stack is just a group of tools that are commonly used together, one on top of the other.
Think of a school office in Lucknow. The building is Linux: without it, nobody can work. The gatekeeper is Apache: he meets every visitor, reads the slip, and sends them to the right desk. The clerk is PHP: she reads the request, takes files out of the record room, and writes the answer. The record room with its steel almirahs is MySQL. Each person does one job well, and the office works only when they pass work to each other correctly.
Following one request
Say Priya, a teacher, opens http://shiksha.test/classes on her laptop. Here is what happens, in order:
Priya's browser
| 1. sends: GET /classes Host: shiksha.test
v
Linux server
+-- Apache (listens on port 80, or 443 for HTTPS)
| 2. finds the virtual host named shiksha.test
| 3. .htaccess rule: /classes is not a file, so run index.php
|
+-- PHP (inside Apache as mod_php, or a separate PHP-FPM service)
| 4. runs public/index.php, which asks the database for classes
|
+-- MySQL (port 3306, reachable only from this server)
| 5. returns the rows from the classes table
|
6. PHP turns the rows into HTML, Apache sends "200 OK" with it
v
Priya's browser draws the tableSteps 2 and 3 are Apache's work, which the Apache lesson covers. Steps 4 and 5 are PHP talking to MySQL through PDO, covered in PHP & MySQL with PDO.
You can watch step 6 yourself. curl -i prints the response headers and the body. This is the real start of the response from our test server for the home page:
curl -i http://shiksha.test/HTTP/1.1 200 OK Date: Sun, 15 Nov 2026 17:23:19 GMT Server: Apache/2.4.58 (Win64) PHP/8.4.27 X-Powered-By: PHP/8.4.27 Content-Length: 652 Content-Type: text/html; charset=UTF-8 <!DOCTYPE html> <html lang="en">
The browser never receives PHP code, only the HTML that PHP printed. Notice also that the Server and X-Powered-By headers tell every visitor the exact versions in use. That helps attackers pick old bugs to try, so the security lesson hides them.
How Apache runs PHP
Apache cannot run PHP by itself. There are two common ways to connect them:
- mod_php: PHP is loaded as a module inside Apache. Every Apache worker can run PHP directly. This is simple and is how XAMPP works.
- PHP-FPM: PHP runs as its own service (FPM means FastCGI Process Manager). Apache passes PHP requests to it through
mod_proxy_fcgi. This uses memory better on busy servers and lets each site run as its own Linux user.
This course uses mod_php on both XAMPP and Ubuntu while you learn, because it needs the least setup. Your PHP code is exactly the same either way. If you later move to Nginx, the LEMP Stack course uses PHP-FPM.
When LAMP is a good choice
LAMP has run a large share of the web for over twenty years. WordPress, many school and college portals, and most small business sites in India run on it.
| Choose LAMP when | Consider another stack when |
|---|---|
| You want cheap shared hosting or a small VPS to work out of the box | You need live updates to many users at once (chat, live scores) |
| The pages are mostly forms, tables and reports | The front end is a large single-page app built in React or Angular |
| Your team already knows PHP and SQL | Your team works only in JavaScript, for example MERN |
The big strengths are simple deployment (copy files, they run), mature tools, and hosting almost everywhere. The main weakness is that each request starts fresh, so very interactive apps need extra pieces.
The running example: ShikshaPortal
Every lesson in this course adds to one app, ShikshaPortal. It keeps classes, students, subjects, exams and marks for a school in Lucknow. Teachers enter marks, and the office prints report cards. The three projects at the end are separate, bigger builds.
Here is the folder layout we use from the first lesson to the last. Later lessons add files, but they do not move these folders.
shiksha-portal/
.env real settings and passwords, never committed to Git
.env.example the same keys with dummy values, committed
.gitignore
bin/ command-line scripts (check-db.php, report-card.php)
config/
config.php turns .env values into a settings array
database/
schema.sql CREATE TABLE statements
seed.sql made-up sample data for development
public/ Apache's DocumentRoot: the ONLY folder with URLs
.htaccess sends every request to index.php
index.php the front controller: every page starts here
assets/css/app.css
src/
bootstrap.php loads helpers, config and the database function
helpers.php env(), config(), e(), render()
db.php db(): the single PDO connection
templates/
layout.php the shared page frame
home.php, classes.php, error.php ...The most important rule is in the middle: only public/ is visible on the web. Apache's DocumentRoot (the folder it serves files from) points at public/, so .env, config/ and src/ have no URL at all. Even if someone types http://shiksha.test/.env, there is no such file inside public/ to send.
The code style rules every lesson follows:
- Every PHP file starts with
declare(strict_types=1);. - All SQL uses PDO prepared statements when any value comes from outside.
- All output goes through
e(), our short wrapper aroundhtmlspecialchars(). - Database names are lowercase
snake_case; tables are plural (students,marks). - Secrets live in environment variables or
.env, never in code or Git.
You will create this layout in the next lesson, Set Up LAMP on Linux & XAMPP.
What the browser finally sees
Below is the real HTML our server sent for /classes, with the stylesheet pasted into a <style> element so it runs here. Open it in the editor and look: there is no PHP and no SQL in it, only the result.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Classes | ShikshaPortal</title>
<style>
body { font-family: system-ui, sans-serif; margin: 0 auto; max-width: 48rem; padding: 1rem; }
header { display: flex; gap: 1rem; align-items: baseline; }
table { border-collapse: collapse; }
th, td { border: 1px solid #ccc; padding: 0.25rem 0.75rem; text-align: left; }
</style>
</head>
<body>
<header>
<a href="/" class="logo">ShikshaPortal</a>
<nav aria-label="Main">
<a href="/classes">Classes</a>
<a href="/about">About</a>
</nav>
</header>
<main>
<h1>Classes</h1>
<table>
<thead><tr><th>Class</th><th>Session</th></tr></thead>
<tbody>
<tr>
<td><a href="/class?id=1">Class 9-A</a></td>
<td>2026-27</td>
</tr>
<tr>
<td><a href="/class?id=2">Class 9-B</a></td>
<td>2026-27</td>
</tr>
<tr>
<td><a href="/class?id=3">Class 10-A</a></td>
<td>2026-27</td>
</tr>
<tr>
<td><a href="/class?id=4">Class 10-B</a></td>
<td>2026-27</td>
</tr>
</tbody>
</table>
</main>
<footer>ShikshaPortal, Lucknow</footer>
</body>
</html>The four rows came from MySQL, the table markup came from templates/classes.php, and the frame came from templates/layout.php. The browser cannot tell any of that. To the browser, it is just a page.
Common mistakes
- Putting the whole project inside
htdocsor/var/www/html. Thenconfig/and.envget URLs. Serve onlypublic/. - Thinking "PHP shows in the browser". If you see PHP code in the browser, Apache is not running PHP for that file. Check that PHP is installed and that the file ends in
.php. - Opening MySQL's port 3306 to the internet. Only PHP on the same server needs it.
- Treating XAMPP as a server for the public. It is built for development on your own computer.
Interview questions
1. What does each letter of LAMP stand for, and what does each part do?
Linux is the operating system, Apache is the web server that receives HTTP requests, MySQL (or MariaDB) stores the data, and PHP runs the application code that builds each response. Apache passes PHP files to PHP, and PHP talks to MySQL over a connection such as PDO.
2. What is the difference between mod_php and PHP-FPM?
mod_php loads PHP inside every Apache worker process, which is simple but uses more memory and runs all sites as the Apache user. PHP-FPM runs PHP as a separate pool of processes that Apache reaches through FastCGI. It scales better, works with the faster event MPM, and lets each site run as its own user.
3. Why should the web server's document root be a public/ folder rather than the project root?
Anything inside the document root can be requested by URL. Keeping configuration, secrets and source code outside it means a mistake in server settings cannot expose them. Only the front controller and static assets need to be public.
4. Is MariaDB the same as MySQL?
MariaDB started as a copy of MySQL in 2009 and stays compatible for everyday SQL and the client protocol, so PHP's PDO MySQL driver works with both. Newer features, default collations and some functions differ, so you should test on the same database you deploy to.
Key points
- Linux runs everything, Apache answers HTTP, PHP builds the page, MySQL stores the data.
- A request goes browser, Apache, virtual host, rewrite rule, PHP, MySQL, and back as HTML.
- Apache runs PHP through mod_php (simple) or PHP-FPM (better for busy servers); your code is the same.
- The browser only ever receives the output, never PHP code or SQL.
- ShikshaPortal serves only
public/; secrets stay in.env, outside the web root. - Use PDO prepared statements and
e()for output in every lesson.
Exercise
Aarav's tuition centre in Rohtak wants a site that lists batches, students and fee receipts. Write the request flow for a parent opening http://tuition.test/receipts in the same style as the diagram in this lesson, naming the job of each part at each step. Then list which of the ShikshaPortal folders the parent's browser can reach by URL, and which it cannot.
Show solution
Parent's browser
| 1. GET /receipts Host: tuition.test
v
Linux server
+-- Apache: picks the tuition.test virtual host,
| .htaccess sends /receipts to public/index.php
+-- PHP: index.php validates the request and runs a
| prepared SELECT on the receipts table
+-- MySQL: returns the matching rows
|
PHP prints HTML, Apache sends 200 OK, the browser shows the listOnly public/ (its index.php and assets/) has URLs. .env, bin/, config/, database/, src/ and templates/ sit outside the document root, so no URL can reach them.
Quick Quiz
1. In the LAMP stack, which part receives the HTTP request first?
Apache listens on ports 80 and 443 and decides what to do with each request.
2. A visitor opens "View source" on a ShikshaPortal page. What do they see?
PHP runs on the server; the browser receives only its output.
3. Why does ShikshaPortal point Apache's DocumentRoot at public/?
Files outside the document root cannot be requested by URL.
4. Which way of running PHP does XAMPP use?
XAMPP loads PHP as an Apache module, which is simple for local development.
Learn LAMP Stack with a mentor
Free lessons get you started. Our Full Stack Web Development training adds real projects and code reviews from working developers.
- Project-based learning
- Mentor code reviews
- Free counselling call
