MAMP is a popular choice for macOS, bundling Apache, MySQL, and PHP. However, for simplicity and ease of use, we recommend using Homebrew to install PHP directly.
Start MAMP and navigate to http://localhost:8888 to verify the installation.
MAMP localhost shows the MAMP welcome page.
Tools: XAMPP (Windows/Linux/macOS) or MAMP (macOS/Windows) or Laragon (Windows) Good for: quick start, no Docker knowledge required.
Steps (students):
Put project files in the web folder:
C:\xampp\htdocs\yourproject (Windows) or /opt/lampp/htdocs/ (Linux)/Applications/MAMP/htdocs/ (macOS)C:\laragon\www\yourprojecthttp://localhost/yourproject in the browser.When to use: first 2–3 weeks (HTML, simple PHP scripts, forms, GET/POST, simple DB CRUD).
Tools: Docker + docker-compose (students will need Docker Desktop or Docker Engine) Good for: reproducible environment, matching production, group projects.
Here’s a minimal docker-compose.yml you can give students to run a PHP + Nginx + MariaDB stack:
version: "3.8"
services:
web:
image: php:8.2-fpm
container_name: php-fpm
volumes:
- ./www:/var/www/html
- ./php.ini:/usr/local/etc/php/conf.d/custom.ini
depends_on:
- db
nginx:
image: nginx:stable
ports:
- "8080:80"
volumes:
- ./www:/var/www/html
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
depends_on:
- web
db:
image: mariadb:10.11
environment:
MYSQL_ROOT_PASSWORD: rootpw
MYSQL_DATABASE: class_db
volumes:
- db_data:/var/lib/mysql
phpmyadmin:
image: phpmyadmin/phpmyadmin
environment:
PMA_HOST: db
ports:
- "8081:80"
depends_on:
- db
volumes:
db_data:
(Students place their PHP files under ./www and visit http://localhost:8080.) For a more complete Docker teaching guide see Docker’s PHP development docs. (Docker Documentation)
VS Code extensions:
composer init, composer require, and PSR-4 autoloading early. (getcomposer.org)www/index.php
<?php
// index.php - simple safe DB example using PDO
require_once __DIR__.'/config.php';
try {
$pdo = new PDO($DB_DSN, $DB_USER, $DB_PASS, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
]);
} catch (Exception $e) {
echo "DB connection error.";
exit;
}
// Simple prepared statement (prevents SQL injection)
$stmt = $pdo->prepare('SELECT id, name, email FROM users LIMIT 10');
$stmt->execute();
$users = $stmt->fetchAll();
?>
<!doctype html>
<html>
<head><meta charset="utf-8"><title>Class demo</title></head>
<body>
<h1>Users</h1>
<ul>
<?php foreach ($users as $u): ?>
<li><?= htmlspecialchars($u['name']) ?> — <?= htmlspecialchars($u['email']) ?></li>
<?php endforeach; ?>
</ul>
</body>
</html>
www/config.php
<?php
// config.php - simple credentials for local development
$DB_DSN = 'mysql:host=db;dbname=class_db;charset=utf8mb4'; // for Docker example
$DB_USER = 'root';
$DB_PASS = 'rootpw';
(If using XAMPP/MAMP put host=localhost and DB creds accordingly.)
htmlspecialchars() when printing HTML.password_hash() / password_verify() for passwords.Week 1 — HTML & CSS basics, browser devtools, file structure (MDN + small static page). (MDN Web Docs)
Week 2 — Intro PHP: echo, variables, control flow, embedding PHP in HTML (php.net simple tutorial). (PHP)
Week 3 — Forms, GET/POST, basic validation, and XSS prevention.
Week 4 — Databases: MySQL/MariaDB basics (use phpMyAdmin), CRUD with PDO prepared statements.
Week 5 — Sessions, login/logout, password_hash, simple auth flow.
Week 6 — Small group project: a simple “student directory” web app (create/read/update/delete and search).
Each lab should include a short spec, starter repo (or zip) and an automated test or checklist (staff can review with a rubric).
(If you want a printable reading list / slide deck I can produce one now — say “Make me a 1-page student handout” and I’ll generate it.)
docker-compose up) and open http://localhost.www folder.<?php ?> tags and server output.I can:
docker-compose.yml, nginx/default.conf, and starter www/ folder (zippable), orTell me which of those you want and I’ll generate the files and code in this chat right now (no waiting).
docker-compose.yml + nginx/default.conf + zip-ready file tree, or