teaching_web_development

Installing PHP on macOS

Best Option

Installing web development tools

Other options

XAMPP


Option A — Beginner (recommended for first lab week)

Tools: XAMPP (Windows/Linux/macOS) or MAMP (macOS/Windows) or Laragon (Windows) Good for: quick start, no Docker knowledge required.

Steps (students):

  1. Download & install XAMPP / MAMP / Laragon. Start Apache & MySQL from the control panel. (apachefriends.org)
  2. Put project files in the web folder:

    • XAMPP: C:\xampp\htdocs\yourproject (Windows) or /opt/lampp/htdocs/ (Linux)
    • MAMP: /Applications/MAMP/htdocs/ (macOS)
    • Laragon: C:\laragon\www\yourproject
  3. Open http://localhost/yourproject in the browser.
  4. Use phpMyAdmin (bundled) to create a database for labs.

When to use: first 2–3 weeks (HTML, simple PHP scripts, forms, GET/POST, simple DB CRUD).


Option B — Modern / reproducible (recommended for course staff and advanced labs)

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)


Editor & tooling (what I recommend for teaching)


Minimal file examples (copy-paste into student projects)

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.)


Security & best practices to teach early (one slide each)


Short 6-week mini-syllabus & lab ideas (for 1st year)

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).


Assignments / assessment ideas


Teaching materials & student resources (good, up-to-date sources)

(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.)


Practical checklist for first session (copy to a lab sheet)

  1. Install XAMPP / MAMP / Laragon or Docker Desktop. (Give both options.) (apachefriends.org)
  2. Install VS Code and the recommended extensions. (Visual Studio Code)
  3. Start Apache/PHP + MySQL (or docker-compose up) and open http://localhost.
  4. Clone starter repo or unpack starter zip into www folder.
  5. Run through “Hello PHP” page -> explain <?php ?> tags and server output.

Want files / starter repos?

I can:

Tell me which of those you want and I’ll generate the files and code in this chat right now (no waiting).