Demo mode This site is not live. It is currently being tested and developed. Nothing on here represents an offer.
← Exit course WEB-301 Full-Stack Web Development with PHP and Laravel
Course progress, 0 of 17 parts done0%
Practical work

5 tasks, about 7.5 hours

Download as PDF

Prepare a Linux environment, install PHP 8.5, Composer and PostgreSQL 18 with the course's database and roles, set up the editor and tools, and verify the whole stack in a repository merged by pull request.

This week you build the workstation you will use for the rest of the course, and prove that every part of it works. Follow one route throughout, Linux Mint or Windows with WSL 2, and do everything in a Linux terminal unless a step says PowerShell. Keep your findings in ~/projects/walks-notes/notes/module-0.md: the commands you ran, the output that mattered, every error you met and how you fixed it. Those notes become your own troubleshooting guide. You need an internet connection, about 5 GB of free disk space and a GitHub account. Together the five tasks take about seven and a half hours.

Task 1: Choose and prepare your Linux environment

  1. Decide on your route, using the comparison table in the lesson, and write two or three sentences in your notes saying which you chose and why. If you choose WSL and already have a Linux distribution in WSL, run wsl -l -v in PowerShell first and record what is there.
  2. Route A, Linux Mint: bring the system up to date with sudo apt update && sudo apt upgrade -y, restart if it asks, and record NAME, VERSION_CODENAME and UBUNTU_CODENAME from /etc/os-release. Route B, WSL 2: in PowerShell as administrator, run wsl --install, restart, create your Linux user (short, lower case), update Ubuntu, then check wsl -l -v and wsl --version in an ordinary PowerShell window. If you already had WSL, install Ubuntu 26.04 with wsl --install -d Ubuntu-26.04, or decide to keep Ubuntu 24.04 and follow the Mint instructions for PHP.
  3. In your Linux terminal, run lsb_release -ds, uname -r, whoami, pwd and sudo -v (which only checks that sudo accepts your password). Record the answers. On WSL, pwd must start with /home/.
  4. Create the course's folders with mkdir -p ~/projects/walks-notes/notes, and start your notes file with code ~/projects/walks-notes/notes/module-0.md (on WSL, this is also your first use of VS Code with the WSL extension, so install the extension first as the lesson describes). Give the file a heading and paste in what you recorded so far.
  5. WSL only: open your projects folder in File Explorer with explorer.exe ~/projects, and record the address it shows. Then run ls /mnt/c/Users to see your Windows user folder from Linux. In one sentence in your notes, say why your projects stay in ~/projects. Mint only: in one sentence, say why a set-up script made for Ubuntu might not recognise your system's code name, and which name you will give it instead.

What you produce: an up-to-date Linux system on your chosen route, the ~/projects/walks-notes folder, and the start of your notes recording your route, Linux version, kernel, user name and home folder.

How to check: lsb_release -ds names Ubuntu 26.04 LTS (WSL) or Linux Mint 22.3 (Mint), and ls ~/projects/walks-notes/notes lists module-0.md.

Time: 1 hour 30 minutes.

Task 2: Install PHP 8.5 and Composer

  1. Mint (or Ubuntu 24.04): open the ondrej/php PPA's page on Launchpad and record, in your own words, which Ubuntu versions it says it supports and what it says about its move to packages.sury.org. Then add it with sudo add-apt-repository ppa:ondrej/php and run sudo apt update. Ubuntu 26.04 in WSL: run apt policy php8.5-cli and record which version Ubuntu's own repository offers.
  2. Install php8.5-cli, php8.5-pgsql, php8.5-mbstring, php8.5-xml, php8.5-curl, php8.5-zip, php8.5-intl, php8.5-bcmath and unzip in one apt install command. Do not install the plain php or php8.5 package. Afterwards, check that Apache was not installed: dpkg -l | grep apache2 should print nothing.
  3. Run php -v, php -m | grep -E 'pgsql|mbstring|xml|curl|zip|intl|bcmath' and php --ini, and record the version, the extensions found, the loaded php.ini and the conf.d folder.
  4. Create /etc/php/8.5/cli/conf.d/99-dev.ini with the three development settings from the lesson. Prove it worked: php --ini lists it last, php -i | grep -E 'display_errors|date.timezone' shows the new values, and php -r 'echo date("j F Y, H:i"), PHP_EOL;' prints South African time.
  5. Install Composer in your home folder with the installer and its checksum check, as in the lesson. Before you run the installer, prove the check works: copy it with cp composer-setup.php broken.php, add a line with echo '// changed' >> broken.php, compare the hash of broken.php with the expected checksum, and record that it no longer matches. Delete broken.php, then run the real installer.
  6. Move composer.phar to /usr/local/bin/composer with sudo, delete the installer, and run composer -V. Add Composer's global vendor/bin folder to your PATH in ~/.bashrc, open a new terminal, and check it with echo "$PATH". Record the Composer version and the PHP it reports.

What you produce: PHP 8.5 with the eight packages the course needs and your development settings, Composer 2 installed globally after a verified download, and notes recording each version and file location.

How to check: php -v starts with PHP 8.5, php -m lists pdo_pgsql, and composer -V reports Composer 2 running on PHP 8.5.

Time: 1 hour 15 minutes.

Task 3: Install PostgreSQL 18 and create the Walk Office's database

  1. Install postgresql-common, add the PGDG repository with /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh (adding noble on Mint), and install postgresql-18 by its number. On Mint, run the script once without noble first and record the error it gives.
  2. Run pg_lsclusters, sudo systemctl status postgresql --no-pager and psql --version. Record the cluster, its port and the log file. If 18/main is not on port 5432, follow "Two PostgreSQL clusters" in the lesson before going on.
  3. Run psql and record the error. Create a superuser role with your Linux user name and a database of the same name, then run psql again. Inside psql, run SELECT version();, \conninfo and \du, and record them.
  4. Still in psql, create the login role walks_app, set its password with \password walks_app (a long one you use nowhere else, saved in your password manager), and create the database mandlas_walks with OWNER walks_app. Check both with \du and \l mandlas_walks.
  5. Connect as walks_app three ways and record each result: without -h, with -h localhost and a deliberately wrong password, and with -h localhost and the right password. Inside the working connection, create and drop a table called smoke_test to prove the owner's rights, and run \dt before and after.
  6. Add a line for walks_app to ~/.pgpass, set its permissions to 600, and connect with the URI postgresql://walks_app@localhost:5432/mandlas_walks without being asked for a password. Run SHOW server_version;.
  7. Find pg_hba.conf with SHOW hba_file; (as your own superuser role), and print its active lines with sudo grep -Ev '^\s*(#|$)' /etc/postgresql/18/main/pg_hba.conf. In your notes, say which line matched each of the three connections in step 5, and why.

What you produce: PostgreSQL 18 running on port 5432, your own superuser role, the walks_app login role and the mandlas_walks database it owns, a working ~/.pgpass, and notes explaining peer and password authentication from your own results.

How to check: psql postgresql://walks_app@localhost:5432/mandlas_walks -c 'SELECT current_user;' answers walks_app without asking for a password.

Time: 1 hour 30 minutes.

Task 4: Set up the editor and tools

  1. Install nvm with the command from nodejs.org, open a new terminal, and run nvm install --lts. Record node -v, npm -v and which node. On WSL, also run which -a node npm: every path listed first must be under /home.
  2. Set your Git name, private GitHub email address, default branch and editor, as in the lesson, and check them with git config --global --list. Install the GitHub CLI, sign in with gh auth login, and record what gh auth status reports.
  3. In VS Code, install PHP Intelephense, Microsoft's PostgreSQL extension and EditorConfig (on WSL, installed in WSL: Ubuntu). Disable the built-in PHP Language Features extension and leave PHP Language Basics on. Record the extensions with code --list-extensions.
  4. Create ~/projects/walks-notes/.editorconfig with the contents from the lesson. Open a new .php file and a new .json file in that folder, and check in VS Code's status bar that they show 4 and 2 spaces and LF line endings. Delete the test files.
  5. Connect to mandlas_walks as walks_app with a graphical client: the PostgreSQL extension in VS Code, or pgAdmin 4 or DBeaver Community if you prefer (on WSL, installed on Windows). Run SELECT current_user, version(); in it and record the answer, and which kind of connection, socket or TCP, the client made.

What you produce: Node LTS through nvm, Git and the GitHub CLI signed in, VS Code with the course's extensions, a .editorconfig in walks-notes, and a graphical connection to the Walk Office's database.

Time: 1 hour 15 minutes.

Task 5: Verify the stack and commit the walks-notes repository

  1. In ~/projects/walks-notes, create a short README.md saying what the repository is for, and a .gitignore that ignores .env, *.log and .vscode/. Run git init, commit these with .editorconfig and your notes on main, create the repository on GitHub with gh repo create walks-notes --private --source=. --push (or --public, as you prefer), and check it on github.com.
  2. Create a branch called stack-check. Write stack-check/info.php and stack-check/db-check.php as in the lesson, typing them rather than pasting, so that Intelephense has a chance to help. Start the server from walks-notes with php -S localhost:8000 -t stack-check, open both pages in your browser (on WSL, your Windows browser), and record the versions db-check.php shows.
  3. Break it on purpose four times, and record each message and its fix. Rename ~/.pgpass for a moment and reload. Change the DSN's database name to mandlas_walk and reload. Start a second server on port 8000 in another terminal. And start a server that loads no extensions with php -n -d extension=pdo -S localhost:8001 -t stack-check, then open db-check.php on port 8001. Put everything back and check the page works again.
  4. Write bin/versions.sh, a Bash script that prints one line for each tool (Linux, PHP, Composer, psql, the server version, Node, npm and Git), saying "NOT FOUND" for any tool that is missing. Make it executable and run it.
  5. Write notes/environment.md, your environment report: the date, your route, the script's output, where php.ini, 99-dev.ini, pg_hba.conf and the PostgreSQL log are, the ports used, your project folder, and the three set-up problems that took you longest, with their fixes. Do not write any password in it.
  6. Commit on the branch with a clear message, such as git commit -m "Add stack check pages, versions script and environment report", push it, and open a pull request with gh pr create --fill. Read the pull request's diff on GitHub as if reviewing someone else's work, merge it, then update your local main with git switch main and git pull.

What you produce: a walks-notes repository on GitHub holding a phpinfo page, a database check page showing PHP 8.5 and PostgreSQL 18, a versions script, your notes and an environment report, merged through a pull request.

How to check: db-check.php shows walks_app, mandlas_walks and a PostgreSQL 18 version, bin/versions.sh prints no "NOT FOUND", and git log --oneline on main shows your merge.

Time: 2 hours.

Show the model answer

Task 1: Choose and prepare your Linux environment

Either route is a good answer. A sound reason is about your own computer: "I use Windows 11 every day and my PC has 16 GB of memory, so WSL 2 lets me keep it" or "I already use Linux Mint from WEB-201". The commands for each route:

Route A, Linux Mint
$ sudo apt update && sudo apt upgrade -y
$ grep -E '^(NAME|VERSION_CODENAME|UBUNTU_CODENAME)=' /etc/os-release
NAME="Linux Mint"
VERSION_CODENAME=zena
UBUNTU_CODENAME=noble
$ lsb_release -ds
Linux Mint 22.3
Route B, PowerShell as administrator, then Ubuntu
PS> wsl --install
# restart Windows, then create your Linux user when Ubuntu opens
$ sudo apt update && sudo apt upgrade -y
$ lsb_release -ds
Ubuntu 26.04.1 LTS
$ pwd
/home/lerato
# in an ordinary PowerShell window:
PS> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Running         2

uname -r prints the kernel's version number followed by -microsoft-standard-WSL2. The number changes, because WSL updates its kernel itself, but that ending tells you this is WSL 2. On WSL, explorer.exe ~/projects shows an address such as \\wsl.localhost\Ubuntu\home\lerato\projects, and ls /mnt/c/Users lists your Windows user folder among a few system ones.

A good notes file at this point:

notes/module-0.md, the start
# Module 0 notes: my workstation

## Task 1: route and Linux

- Route: B, Windows 11 with WSL 2. I keep Windows for everything else,
  and the course deploys to Ubuntu, which is what WSL runs.
- Linux: Ubuntu 26.04.1 LTS, kernel ending microsoft-standard-WSL2
- User: lerato, home /home/lerato, sudo works
- Projects live in ~/projects, never /mnt/c: across the bridge files are
  slow, permissions do not work properly and file watchers miss changes.
- From Windows: \\wsl.localhost\Ubuntu\home\lerato\projects

On Mint, the code-name sentence is something like: "Extra repositories build packages for Ubuntu's releases, so they know noble but not Mint's own zena, and I give scripts noble instead."

Common mistakes and fixes:

  • wsl --install prints help text. WSL is already installed. Run wsl --list --online and wsl --install -d Ubuntu-26.04.
  • Error 0x80370102, or "Please enable the Virtual Machine Platform". Virtualisation is off. Turn on Intel VT-x or AMD SVM in your PC's firmware settings, reached by a key such as F2 or Del while it starts, then run wsl --install again.
  • "Nothing happens" when typing the Linux password. Linux shows nothing while you type a password. Type it and press Enter.
  • Forgotten Linux password. In PowerShell, wsl -u root opens Ubuntu as root, where passwd lerato sets a new one.
  • Working in /mnt/c. If pwd shows /mnt/c/..., type cd ~. Windows Terminal can open Ubuntu in your home folder by default.

Task 2: Install PHP 8.5 and Composer

The PPA's page says it is being merged into packages.sury.org, that Ubuntu 26.04 users should use that, and that Ubuntu 22.04 and 24.04 users can keep using the PPA. On Ubuntu 26.04, apt policy php8.5-cli shows a candidate such as 8.5.4-0ubuntu1.5 from Ubuntu's own repository. The installation:

Linux Mint 22 (or Ubuntu 24.04): add the PPA first
$ sudo add-apt-repository ppa:ondrej/php
$ sudo apt update
Both routes
$ sudo apt install -y php8.5-cli php8.5-pgsql php8.5-mbstring \
    php8.5-xml php8.5-curl php8.5-zip php8.5-intl php8.5-bcmath unzip
$ dpkg -l | grep apache2
$ php -m | grep -E 'pgsql|mbstring|xml|curl|zip|intl|bcmath'
bcmath
curl
intl
libxml
mbstring
pdo_pgsql
pgsql
xml
xmlreader
xmlwriter
zip
$ sudo nano /etc/php/8.5/cli/conf.d/99-dev.ini
$ php -i | grep -E 'display_errors|date.timezone'
display_errors => STDOUT => STDOUT
date.timezone => Africa/Johannesburg => Africa/Johannesburg
$ php -r 'echo date("j F Y, H:i"), PHP_EOL;'
2 November 2026, 04:38

The grep for apache2 should print nothing. On the command line, PHP reports display_errors = On as STDOUT, meaning errors are printed with the output. Before the file existed it showed Off, and the time zone was empty or UTC. The file itself:

/etc/php/8.5/cli/conf.d/99-dev.ini
; Development settings for this machine only, never for a server
display_errors = On
error_reporting = E_ALL
date.timezone = Africa/Johannesburg

Composer, with the deliberate test of the checksum. These are real values from 2 November 2026: the checksum changes whenever Composer releases a new installer, so yours may differ, but the broken copy never matches.

Terminal, in your home folder
$ cd ~
$ SIG_URL="https://composer.github.io/installer.sig"
$ EXPECTED="$(php -r "copy('$SIG_URL', 'php://stdout');")"
$ php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
$ echo "$EXPECTED"
c8b085408188070d5f52bcfe4ecfbee5f727afa458b2573b
8eaaf77b3419b0bf2768dc67c86944da1544f06fa544fd47
$ cp composer-setup.php broken.php
$ echo '// changed' >> broken.php
$ php -r "echo hash_file('sha384', 'broken.php'), PHP_EOL;"
e873a26c61b42121d665fec76d5aeb6ede5e30ca316127b0
2ea4bc364c9fe64a6faac9efd5284a8c8e3b9e523a926860
$ rm broken.php
$ ACTUAL="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
$ [ "$EXPECTED" = "$ACTUAL" ] && echo "Installer verified" \
    || echo "Installer corrupt: do not run it"
Installer verified
$ php composer-setup.php
$ rm composer-setup.php
$ sudo mv composer.phar /usr/local/bin/composer
$ composer -V
Composer version 2.11.1 2026-10-30 14:52:10
PHP version 8.5.12 (/usr/bin/php8.5)
Run the "diagnose" command to get more detailed diagnostics output.
$ echo 'export PATH="$HOME/.config/composer/vendor/bin:$PATH"' >> ~/.bashrc

The two long checksums are each one line in the terminal, broken here to fit. Adding eleven characters changed every part of the checksum, which is the point: no one can change the file without the check noticing. If the checksum download fails, EXPECTED is empty and the check says "corrupt", which is the safe way to fail. On Ubuntu 26.04, composer -V reports Ubuntu's PHP number, such as 8.5.4.

Common mistakes and fixes:

  • Apache was installed. You installed php8.5 or php. Remove it with sudo apt purge apache2 'apache2-*' libapache2-mod-php8.5, then sudo apt autoremove, and check that php8.5-cli is still there.
  • E: Unable to locate package php8.5-cli. On Mint, the PPA was not added, or sudo apt update was skipped afterwards.
  • mv: cannot move 'composer.phar' to '/usr/local/bin/composer': Permission denied. The move needs sudo. It is the only Composer step that does.
  • 99-dev.ini ignored. It must be in the cli/conf.d folder of the PHP version you run, end in .ini, and be created with sudo. php --ini shows whether it was read.
  • PATH unchanged. ~/.bashrc is read when a terminal opens, so open a new one, or run source ~/.bashrc.

Task 3: Install PostgreSQL 18 and create the Walk Office's database

Installing (add noble to the script's line on Linux Mint)
$ sudo apt install -y postgresql-common
$ sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
$ sudo apt install -y postgresql-18
$ pg_lsclusters
Ver Cluster Port Status Owner    Data directory              Log file
18  main    5432 online postgres /var/lib/postgresql/18/main /var/log/postgr...

The log file is /var/log/postgresql/postgresql-18-main.log. On Mint, running the script without noble stops with this message from the script itself:

The script on Linux Mint, without a code name
Your system is using the distribution codename zena, but zena-pgdg
does not seem to be a valid distribution on
https://apt.postgresql.org/pub/repos/apt/dists/

We abort the installation here. If you want to use a distribution different
from your system, you can call this script with an explicit codename, e.g.
"/usr/share/postgresql-common/pgdg/apt.postgresql.org.sh precise".

Your own role, the application's role and the database:

Terminal and psql
$ psql
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432"
failed: FATAL:  role "lerato" does not exist
$ sudo -u postgres createuser --superuser "$USER"
$ createdb "$USER"
$ psql
lerato=# CREATE ROLE walks_app WITH LOGIN;
lerato=# \password walks_app
lerato=# CREATE DATABASE mandlas_walks OWNER walks_app;
lerato=# \l mandlas_walks
     Name      |   Owner   | Encoding | ...
---------------+-----------+----------+----
 mandlas_walks | walks_app | UTF8     | ...
lerato=# \q

The three connections as walks_app, with the real messages:

Terminal
$ psql -U walks_app -d mandlas_walks
psql: error: connection to server on socket "/var/run/postgresql/.s.PGSQL.5432"
failed: FATAL:  Peer authentication failed for user "walks_app"
$ psql -h localhost -U walks_app -d mandlas_walks
Password for user walks_app:
psql: error: connection to server at "localhost" (127.0.0.1), port 5432 failed:
FATAL:  password authentication failed for user "walks_app"
$ psql -h localhost -U walks_app -d mandlas_walks
Password for user walks_app:
mandlas_walks=> \dt
Did not find any relations.
mandlas_walks=> CREATE TABLE smoke_test (id integer);
CREATE TABLE
mandlas_walks=> \dt
 Schema |    Name    | Type  |   Owner
--------+------------+-------+-----------
 public | smoke_test | table | walks_app
(1 row)
mandlas_walks=> DROP TABLE smoke_test;
DROP TABLE

The long error lines are one line each in the terminal. Then the password file and the URI:

Terminal (your own password in place of the example)
$ echo 'localhost:5432:mandlas_walks:walks_app:your-long-password' \
    >> ~/.pgpass
$ chmod 600 ~/.pgpass
$ psql postgresql://walks_app@localhost:5432/mandlas_walks \
    -c 'SHOW server_version;'
          server_version
-----------------------------------
 18.6 (Ubuntu 18.6-1.pgdg24.04+1)
(1 row)

The text in brackets names the package, so it says pgdg26.04 on Ubuntu 26.04. The explanation for your notes, using the active lines of pg_hba.conf:

  • Without -h: a socket connection, so PostgreSQL tried the local lines. The first is only for the user postgres, so the second, local all all peer, matched. Peer compared the Linux user lerato with the role walks_app, and they differ, so it refused.
  • With -h localhost and a wrong password: a TCP connection from 127.0.0.1, which matched host all all 127.0.0.1/32 scram-sha-256. The password was checked and was wrong.
  • With -h localhost and the right password: the same line, and the password was right. If localhost had resolved to the IPv6 address ::1, the ::1/128 line would have matched instead, with the same method.

The output also shows three replication lines, which are for copying a whole server to another and do not apply to ordinary connections.

Common mistakes and fixes:

  • Installed postgresql instead of postgresql-18. On Mint without the PGDG repository that gives PostgreSQL 16, and from PGDG it will give the newest version. Install postgresql-18 and check pg_lsclusters.
  • The new cluster is on port 5433. An older cluster already holds 5432. Follow "Two PostgreSQL clusters" in the lesson.
  • The password typed into CREATE ROLE. CREATE ROLE walks_app WITH LOGIN PASSWORD '...' works, but the password stays in psql's history file, ~/.psql_history. \password avoids that.
  • permission denied for schema public. The database was created without OWNER walks_app. As yourself, run ALTER DATABASE mandlas_walks OWNER TO walks_app;.
  • WARNING: password file "/home/lerato/.pgpass" has group or world access. libpq ignores the file until you run chmod 600 ~/.pgpass.

Task 4: Set up the editor and tools

Terminal, both routes
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh \
    | bash
# open a new terminal
$ nvm install --lts
$ node -v
v26.13.0
$ which -a node npm
/home/lerato/.nvm/versions/node/v26.13.0/bin/node
/home/lerato/.nvm/versions/node/v26.13.0/bin/npm
$ git config --global user.name "Lerato Mokoena"
$ git config --global user.email "your-github-noreply-address"
$ git config --global init.defaultBranch main
$ git config --global core.editor "code --wait"
$ sudo apt install -y gh
$ gh auth login
$ gh auth status
$ code --list-extensions
bmewburn.vscode-intelephense-client
editorconfig.editorconfig
ms-ossdata.vscode-pgsql

On WSL, a second line under each name in which -a, starting /mnt/c/, is the Windows copy of Node: harmless as long as the /home one comes first. gh auth status should say you are logged in to github.com with Git operations over HTTPS. On WSL, code --list-extensions in the Ubuntu terminal lists the extensions installed in WSL, and the WSL extension itself appears in the Windows list.

The .editorconfig is the lesson's listing. With it, VS Code's status bar shows "Spaces: 4" and "LF" for a .php file and "Spaces: 2" for a .json file. Without the EditorConfig extension, it shows VS Code's own defaults instead.

The graphical connection uses host localhost, port 5432, database mandlas_walks, user walks_app and its password, and is a TCP connection: graphical clients connect to a host and port, and on WSL the client runs on Windows, so it cannot use Ubuntu's socket file at all. SELECT current_user, version(); answers walks_app and a line starting PostgreSQL 18.6.

Common mistakes and fixes:

  • nvm: command not found. The installer adds nvm to ~/.bashrc, which only new terminals read. Open a new terminal.
  • PHP extensions installed on the wrong side. On WSL, an extension installed only on Windows shows "Install in WSL: Ubuntu" in the Extensions view. Click it.
  • Every PHP suggestion appears twice. Two PHP extensions are active, or the built-in PHP Language Features is still on. Keep only Intelephense.
  • The client cannot connect from Windows. Check that PostgreSQL in Ubuntu is running and that no PostgreSQL installed on Windows holds port 5432.

Task 5: Verify the stack and commit the walks-notes repository

The finished repository:

~/projects/walks-notes
walks-notes/
  .editorconfig
  .gitignore
  README.md
  bin/
    versions.sh
  notes/
    environment.md
    module-0.md
  stack-check/
    db-check.php
    info.php
.gitignore
.env
*.log
.vscode/
README.md
# walks-notes

My notes, environment report and stack checks for WEB-301,
Full-Stack Web Development with PHP and Laravel.

- notes/ holds my notes for each module and my environment report.
- stack-check/ holds two development-only pages. Run them with
  php -S localhost:8000 -t stack-check
- bin/versions.sh prints the versions of the course's tools.

The two pages are the lesson's listings, repeated here complete:

stack-check/info.php
<?php

declare(strict_types=1);

// Development only: phpinfo() shows how PHP is set up on this machine.
// Never leave a page like this on a public server.
phpinfo();
stack-check/db-check.php
<?php

declare(strict_types=1);

// Development only: proves PHP can reach PostgreSQL through PDO.
// The password is not written here: PDO's PostgreSQL driver uses libpq,
// which reads it from ~/.pgpass, just as psql does.

$dsn = 'pgsql:host=localhost;port=5432;dbname=mandlas_walks';
$user = 'walks_app';

$rows = [];
$error = null;

try {
    $pdo = new PDO($dsn, $user, null, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
    ]);
    $result = $pdo->query(
        'SELECT current_user AS who, current_database() AS db, '
        . "current_setting('server_version') AS version"
    );
    $row = $result->fetch(PDO::FETCH_ASSOC);
    $rows = [
        'PHP version' => PHP_VERSION,
        'PDO drivers' => implode(', ', PDO::getAvailableDrivers()),
        'Connected as' => $row['who'],
        'Database' => $row['db'],
        'PostgreSQL version' => $row['version'],
    ];
} catch (PDOException $e) {
    $error = $e->getMessage();
}

function e(string $text): string
{
    return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
?>
<!doctype html>
<html lang="en-ZA">
<head>
<meta charset="utf-8">
<title>Database check</title>
</head>
<body>
<h1>Database check</h1>
<?php if ($error !== null): ?>
<p>Could not connect: <?= e($error) ?></p>
<?php else: ?>
<dl>
<?php foreach ($rows as $label => $value): ?>
<dt><?= e($label) ?></dt><dd><?= e($value) ?></dd>
<?php endforeach; ?>
</dl>
<?php endif; ?>
</body>
</html>

The four deliberate breaks give these messages on the page or in the terminal:

The four breaks and what they showed
BreakMessageWhy
~/.pgpass renamedSQLSTATE[08006] [7] connection to server at "localhost" (127.0.0.1), port 5432 failed: fe_sendauth: no password suppliedThe server asked for a password and libpq had none to give
Database name mandlas_walkThe same fe_sendauth: no password suppliedEach ~/.pgpass line names a database, and none matches mandlas_walk, so no password was found before the server could say the database does not exist
A second server on port 8000Failed to listen on localhost:8000 (reason: Address already in use)Only one program may listen on a port
php -n -d extension=pdoCould not connect: could not find driver-n loads no .ini files, so PDO was there but pdo_pgsql was not

The second break teaches the most: an error can name the step that failed first rather than the mistake you made. Reading the message alone suggests a password problem, and only comparing the DSN with ~/.pgpass finds the typing mistake.

A model versions script. Module 13 teaches Bash scripting properly: for now, the show function prints a label and the first line of a command's output, or "NOT FOUND" if the command does not exist.

bin/versions.sh
#!/usr/bin/env bash
# Prints the versions of the course's tools, for notes/environment.md.
set -euo pipefail

show() {
    local label="$1"
    shift
    if command -v "$1" > /dev/null 2>&1; then
        printf '%-12s %s\n' "$label" "$("$@" 2>&1 | head -n 1)"
    else
        printf '%-12s %s\n' "$label" "NOT FOUND"
    fi
}

show "Linux" lsb_release -ds
show "PHP" php -v
show "Composer" composer -V
show "psql" psql --version
show "Server" psql -h localhost -U walks_app -d mandlas_walks -tAc \
    "SHOW server_version"
show "Node" node -v
show "npm" npm -v
show "Git" git --version
Terminal
$ chmod +x bin/versions.sh
$ bin/versions.sh
Linux        Linux Mint 22.3
PHP          PHP 8.5.12 (cli) (built: ...) (NTS)
Composer     Composer version 2.11.1 2026-10-30 14:52:10
psql         psql (PostgreSQL) 18.6 (Ubuntu 18.6-1.pgdg24.04+1)
Server       18.6 (Ubuntu 18.6-1.pgdg24.04+1)
Node         v26.13.0
npm          11.20.0
Git          git version 2.43.0

Your numbers will differ a little, and npm's and Git's most of all. If the server is stopped, the Server line shows psql's error instead, and the script carries on, because the error is printed rather than ending the script.

A model environment report:

notes/environment.md
# My WEB-301 environment

Checked on 4 November 2026.

## Route

Linux Mint 22.3 (Ubuntu 24.04 "noble" base), installed on the PC.

## Versions (bin/versions.sh)

(paste the script's output here)

## Where things are

- PHP settings: /etc/php/8.5/cli/php.ini, plus my
  /etc/php/8.5/cli/conf.d/99-dev.ini
- PostgreSQL: cluster 18/main on port 5432, settings in
  /etc/postgresql/18/main/, log /var/log/postgresql/postgresql-18-main.log
- Authentication rules: /etc/postgresql/18/main/pg_hba.conf
- Database mandlas_walks, owned by walks_app, password in ~/.pgpass
- PHP development server: port 8000
- Projects: ~/projects

## Problems that took longest

1. The PGDG script rejected "zena": ran it again with "noble".
2. "Peer authentication failed" for walks_app: needed -h localhost.
3. Port 8000 in use: a php -S was still running in another terminal.

The commits, the pull request and the merge:

Terminal, in ~/projects/walks-notes
$ git init
$ git add README.md .gitignore .editorconfig notes
$ git commit -m "Start walks-notes with notes, README and editor settings"
$ gh repo create walks-notes --private --source=. --push
$ git switch -c stack-check
$ git add stack-check bin notes
$ git commit -m "Add stack check pages, versions script and environment report"
$ git push -u origin stack-check
$ gh pr create --fill
# review the diff on GitHub, merge, then:
$ git switch main
$ git pull
$ git log --oneline --graph
*   a9647de Merge pull request #1 from lerato/stack-check
|\
| * 2fc69a7 Add stack check pages, versions script and environment report
|/
* 98ebf92 Start walks-notes with notes, README and editor settings

A good pull request review checks that no password appears anywhere in the diff, that each file ends with a newline (EditorConfig sees to that), and that nothing in .gitignore's list was committed.

Common mistakes and fixes:

  • The page downloads instead of running, or shows PHP code. It was opened from the disk, with a file:// address, or with VS Code's Live Server. Open it through php -S at http://localhost:8000/.
  • 404 for db-check.php. The server was started in the wrong folder, or without -t stack-check. The terminal log shows the path it looked for.
  • A password in the repository. If one was ever committed, changing the file is not enough, because Git keeps history. Change the password with \password walks_app and update ~/.pgpass.
  • gh repo create fails with "not logged in". Run gh auth login again, as in Task 4.
  • versions.sh: Permission denied. Run chmod +x bin/versions.sh. A "bad interpreter" error means the file has Windows line endings: EditorConfig's end_of_line = lf prevents this, and VS Code's status bar can switch CRLF to LF.