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%

Set up your full-stack workstation

Download as PDF

PHP, Composer, PostgreSQL and the tools of the trade, on Linux Mint or Windows with WSL 2

In WEB-201 you needed a browser, an editor and Node to build the Walk Planner. A back end needs more: a programming language that runs on the server, a database server, a package manager for the language, and tools to look inside the database. Before the course can teach any of them, they must be installed, configured and talking to each other on your own computer. That is this module's whole job.

By the end of it you will have PHP 8.5, Composer 2, PostgreSQL 18, Node.js, Git and VS Code working together inside Linux, either on Linux Mint directly or on Windows through WSL 2. You will have created the database the Walk Office uses for the rest of the course, mandlas_walks, owned by its own login role, walks_app. And you will have proved the whole chain works with two small PHP pages, one showing how PHP is set up and one reading the PostgreSQL version through a real database connection. Mandla's Mountain Walks and everyone in it are invented for the course, as in WEB-201.

Why a full-stack developer works in Linux

A full-stack developer builds both halves of a web application: the front end that runs in the browser, which WEB-201 taught, and the back end that runs on a server, receives requests, applies the business rules and keeps the data. The servers that run PHP applications such as the Walk Office are almost always Linux machines. In Module 12 you will deploy the Walk Office to an Ubuntu Server virtual machine with Nginx, PHP-FPM and PostgreSQL, and in Module 13 you will write a Bash script that installs it.

Developing on the same kind of system you deploy to removes a whole class of surprises. On Linux, file names are case-sensitive, so Walk.php and walk.php are different files. Files have owners and permissions that decide who may read, write or run them. Programs come from the same packages your server will use. PHP and PostgreSQL do run on Windows directly, but every difference between your machine and the server is a bug waiting to happen.

Distribution
A complete Linux system built around the Linux kernel, with its own installer, desktop and packages. Ubuntu and Linux Mint are distributions, and Mint is built on Ubuntu.
Package and package manager
A package is a program prepared for installing, with a list of the other packages it needs. On Ubuntu and Mint the package manager is apt, which downloads packages, installs them with what they need, and updates them later.
Repository
A server that offers packages to apt. Your distribution has its own, and you can add others, such as the PostgreSQL project's.
LTS
Long-Term Support. Ubuntu releases an LTS version every two years, such as 24.04 (April 2024) and 26.04 (April 2026), and supports each for at least five years.
sudo
Runs one command as the administrator, called root on Linux, after asking for your own password. You need it to install software and change system settings, never to edit your own projects.

The tools you will install

The workstation for WEB-301, checked on 2 November 2026
ToolVersion taughtWhat it doesFirst used
PHP8.5Runs the back-end code, and includes a small web server for developmentModule 3
Composer2 (2.11.1 on 2 November 2026)Installs PHP libraries and frameworks, such as LaravelModule 5
PostgreSQL18The database server, with psql, its command-line clientModule 1
pgAdmin or DBeaverCurrent releaseOptional graphical database clientsModule 1
Node.js26 LTS, through nvmRuns the front-end build tools Laravel usesModule 6
Git and GitHubAs in WEB-201Version control, branches and pull requestsThis module
VS CodeCurrent releaseYour editor, with extensions for PHP, PostgreSQL and EditorConfigThis module
Browser localhost:8000 VS Code edits your files pgAdmin or DBeaver (optional) PHP 8.5 built-in server: php -S pgsql, mbstring, intl and other extensions Composer 2 PostgreSQL 18 server on port 5432 psql, the client database mandlas_walks owned by walks_app PDO Node.js LTS, through nvm Git, pushing to GitHub Linux: Linux Mint, or Ubuntu in WSL 2 Your PC Linux Mint directly, or Windows 10 or 11 with WSL 2 HTTP files SQL
Figure 0.1: The full-stack workstation. Everything that will run on the server runs inside Linux on your own PC.

Two routes: Linux Mint or Windows with WSL 2

You need a Linux system, and there are two good ways to have one. Choose the one that matches the computer you already use.

The two routes compared
Route A: Linux MintRoute B: Windows with WSL 2
Who it suitsYou already use Linux Mint, as many WEB-201 learners didYou use Windows 10 or 11 and want to keep it
Linux versionLinux Mint 22.3, built on Ubuntu 24.04Ubuntu 26.04 LTS, inside Windows
Where PHP 8.5 comes fromAn extra repository, because Ubuntu 24.04 has PHP 8.3Ubuntu's own packages
Where PostgreSQL 18 comes fromThe PostgreSQL apt repositoryThe PostgreSQL apt repository
Editor and browserLinux versionsWindows versions, connected to Linux

Both routes end with the same tools, the same versions, the same folder layout and the same commands from then on. Where the course shows one command for both, it works on both.

Route A: Linux Mint

Linux Mint 22.3 "Zena", released in January 2026, is built on Ubuntu 24.04 LTS, whose code name is noble. The next major Mint release, built on Ubuntu 26.04, is planned for about Christmas 2026. If you install it later, follow Route B's PHP instructions, because its base has PHP 8.5 built in, and give the PostgreSQL script resolute, Ubuntu 26.04's code name, where this module says noble. Start by bringing your system up to date in a terminal:

Terminal, 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

That second command matters. Mint has its own code name, zena, but extra repositories are built for Ubuntu and know only Ubuntu's names. When a set-up script complains that it does not recognise zena, you give it noble instead, as you will do for PostgreSQL below.

Route B: Windows with WSL 2

WSL (Windows Subsystem for Linux) runs a real Linux system inside Windows. Version 2 runs a genuine Linux kernel in a lightweight virtual machine that starts in a second or two, shares your network and can see your Windows files. You type Linux commands in a Linux terminal, and you use your normal Windows browser and VS Code. Microsoft built it for exactly this: developers who want Linux tools on a Windows PC.

You need Windows 11, or Windows 10 version 2004 (build 19041) or later, and virtualisation switched on in your PC's firmware settings, which it usually is. Windows 10 reached the end of its support on 14 October 2025, so use Windows 11 if your PC can run it.

  1. Open PowerShell as administrator. Right-click the Start button, choose Terminal (Admin) or Windows PowerShell (Admin), and accept the prompt.
  2. Install WSL and Ubuntu. Type wsl --install and press Enter. This turns on the Windows features WSL needs and installs Ubuntu, which on 2 November 2026 means Ubuntu 26.04.1 LTS. Restart Windows when it asks.
  3. Create your Linux user. Ubuntu opens after the restart, or from the Start menu. Choose a short user name in lower case, such as lerato, and a password. Nothing appears while you type the password, which is normal on Linux. This account is separate from your Windows account, and its password is the one sudo asks for.
  4. Update Ubuntu. In the Ubuntu terminal, run sudo apt update && sudo apt upgrade -y.
  5. Check from Windows. In an ordinary PowerShell window, run wsl -l -v. Ubuntu should be listed with VERSION 2.
PowerShell, after installing
PS> wsl -l -v
  NAME      STATE           VERSION
* Ubuntu    Running         2
PS> wsl --update          # update WSL itself
PS> wsl --shutdown        # stop every running Linux system

If wsl --install only prints its help text, WSL is already installed: run wsl --install -d Ubuntu-26.04 to add the Ubuntu this course uses. If you already have Ubuntu 24.04 in WSL, you can keep it and follow Route A's PHP instructions, because it is Mint's base too. An error mentioning virtualisation, such as 0x80370102, means it is off in your firmware settings, where it is called Intel VT-x or AMD SVM.

Work in the Linux file system, not /mnt/c

Inside WSL your Windows drives appear under /mnt, so your Windows user folder is /mnt/c/Users/lerato. It is tempting to keep projects there. Do not. Every file operation across that bridge is slow, which you will feel when Composer installs thousands of files. Linux permissions do not behave properly there, and tools that watch files for changes miss them. Keep all your work in your Linux home folder, ~, which is /home/lerato, in ~/projects.

You can still reach those files from Windows. Run explorer.exe . in the Ubuntu terminal to open the current folder in File Explorer, or type \\wsl.localhost\Ubuntu\home\lerato in its address bar. Copying a file across occasionally is fine. Working across the bridge all day is not.

Windows WSL 2: Ubuntu VS Code window Browser pgAdmin or DBeaver VS Code Server PHP, port 8000 PostgreSQL, port 5432 WSL extension localhost localhost C: drive seen from Linux as /mnt/c ~/projects fast: keep your work here slow bridge One PC, two systems, one network name: localhost
Figure 0.2: Windows and WSL 2. The programs you look at run in Windows. Your code, PHP and PostgreSQL live in Linux.

Two things make this comfortable. First, a server running in WSL is reachable from Windows at localhost, so when PHP's development server listens on port 8000 in Ubuntu, Chrome or Edge on Windows opens http://localhost:8000. Second, VS Code's WSL extension splits the editor in two: the window you see runs on Windows, while a small VS Code Server runs inside Ubuntu, reading files, running the terminal and hosting the PHP extensions. Install VS Code on Windows only, never inside Ubuntu.

  1. Install the extension. In VS Code on Windows, open Extensions (Ctrl+Shift+X), search for "WSL" and install Microsoft's extension of that name.
  2. Open a Linux folder. In the Ubuntu terminal, go to a folder and type code .. The first time, it installs the VS Code Server, then a VS Code window opens with "WSL: Ubuntu" in the green corner at the bottom left.
  3. Install extensions on the right side. Language extensions, such as the PHP one below, must run where the code is. VS Code shows an "Install in WSL: Ubuntu" button for them.

Try it: find out where you are

In your Linux terminal, on either route, run uname -r, lsb_release -ds and pwd. On WSL the kernel name ends in microsoft-standard-WSL2, and pwd should show /home/ followed by your user name, not /mnt/c. On WSL, also run explorer.exe . and notice the address File Explorer shows.

Installing PHP 8.5

PHP is the language you will write the back end in from Module 3. A new major version arrives each November. PHP 8.5 was released on 20 November 2025, receives bug fixes until 31 December 2027 and security fixes until 31 December 2029. Its latest release on 2 November 2026 was 8.5.12, from 22 October 2026. Laravel 13, which you meet in Module 6, needs PHP 8.3 or later, so PHP 8.5 runs everything in the course.

PHP is a small core plus extensions, optional modules that add abilities such as talking to PostgreSQL. On Ubuntu and Mint each extension is a separate package, named php8.5- followed by the extension. These are the ones the course needs:

PHP extensions for WEB-301
PackageGives PHPNeeded for
php8.5-cliThe php command and its built-in web serverEverything
php8.5-pgsqlThe pgsql and pdo_pgsql extensionsTalking to PostgreSQL, from Module 4
php8.5-mbstringSafe handling of text in any language and script, such as accented namesLaravel
php8.5-xmlDOM, SimpleXML, XMLReader and XMLWriterLaravel, PHPUnit
php8.5-curlHTTP requests to other serversComposer, Laravel's HTTP client
php8.5-zipReading zip archivesComposer downloads
php8.5-intlFormatting dates, numbers and money for a locale such as en_ZALaravel, displaying prices
php8.5-bcmathExact arithmetic on large decimal numbersMoney calculations, some packages

Install unzip too, which Composer uses to unpack downloads quickly.

PHP on Linux Mint 22: the ondrej/php repository

Ubuntu 24.04, and therefore Mint 22, comes with PHP 8.3. For newer versions, the long-standing source is a PPA (Personal Package Archive, an extra repository hosted on Ubuntu's Launchpad) kept by Ondrej Sury, who also packages PHP for Debian. It offers every supported PHP version for Ubuntu 22.04 and 24.04, and its packages follow PHP's own releases closely.

Terminal, Linux Mint 22 (or Ubuntu 24.04)
$ sudo add-apt-repository ppa:ondrej/php
You are about to add the following PPA: ...
Press [ENTER] to continue or Ctrl-c to cancel
$ sudo apt update
$ 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

On Mint, add-apt-repository knows to use the Ubuntu name noble for the PPA, so no extra step is needed. The PPA's description says it is moving to a new home, packages.sury.org, and that Ubuntu 26.04 users should use that. Mint 22 and Ubuntu 24.04 users can keep using the PPA. Read its page before you add it, in case the advice has changed.

PHP on Ubuntu 26.04 in WSL

Ubuntu 26.04 includes PHP 8.5 in its own repositories, so you need no extra repository at all:

Terminal, Ubuntu 26.04 in WSL
$ 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

Ubuntu's PHP shows an older-looking release number, such as 8.5.4, than the PPA's. That does not mean it lacks fixes. Ubuntu's security team copies security fixes into the version it shipped, without changing the number. Either is fine for this course.

Checking PHP: php -v, php -m and php --ini

Three commands tell you what you have. php -v prints the version. php -m lists the loaded extensions, and grep filters the list to the ones you care about. php --ini shows which configuration files PHP read.

Terminal, both routes
$ php -v
PHP 8.5.12 (cli) (built: ...) (NTS)
...
$ php -m | grep -E 'pgsql|mbstring|xml|curl|zip|intl|bcmath'
bcmath
curl
intl
libxml
mbstring
pdo_pgsql
pgsql
xml
xmlreader
xmlwriter
zip
$ php --ini
Configuration File (php.ini) Path: /etc/php/8.5/cli
Loaded Configuration File:         /etc/php/8.5/cli/php.ini
Scan for additional .ini files in: /etc/php/8.5/cli/conf.d
Additional .ini files parsed:      /etc/php/8.5/cli/conf.d/10-pdo.ini,
/etc/php/8.5/cli/conf.d/15-xml.ini,
...

If pdo_pgsql is missing from the list, the database pages later in this module fail with "could not find driver". Fix it now with sudo apt install php8.5-pgsql.

Where PHP's settings live

PHP reads its settings from a file called php.ini. On Ubuntu and Mint there is one per way of running PHP: /etc/php/8.5/cli/php.ini for the php command, including its built-in server, and later /etc/php/8.5/fpm/php.ini for PHP-FPM behind Nginx in Module 12. After the main file, PHP reads every .ini file in the matching conf.d folder in name order. That is how each extension package switches itself on, with a file such as 20-pdo_pgsql.ini holding one line, extension=pdo_pgsql.so.

Leave php.ini itself alone and add your own small file at the end of the order. Ubuntu's files start from PHP's production settings, which hide error messages from the browser. On your own machine you want to see them:

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

Create it with sudo nano /etc/php/8.5/cli/conf.d/99-dev.ini, or with sudo code if you prefer. Run php --ini again and it appears at the end of the list. The time zone makes PHP's dates match South African time instead of UTC, which matters as soon as Mandla's departures have start times.

Try it: ask PHP about itself

Run php -i | grep -E 'display_errors|date.timezone' before and after creating 99-dev.ini, and note the change. Then run php -r 'echo date("j F Y, H:i"), PHP_EOL;': the -r option runs one line of PHP, and the time it prints should be South African time.

Composer 2

Composer is PHP's package manager. A PHP project lists the libraries it needs in a file called composer.json, and Composer downloads them, and the libraries they need, into a vendor folder. Laravel itself is installed with Composer. Module 5 teaches it properly. Here you only install it.

Composer's official installer is a PHP script. Because you are about to run code from the internet, you first check that the file you downloaded is exactly the file Composer published. Composer publishes the installer's checksum, a long code calculated from the file's contents with the SHA-384 method. If even one byte of the file differed, its checksum would differ. Composer's own documentation gives these steps, which fetch the current checksum instead of one typed into the page:

Terminal, both routes, 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');"
$ 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
All settings correct for using Composer
Downloading...

Composer (version 2.11.1) successfully installed to: /home/lerato/composer.phar
Use it: php composer.phar
$ 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.

Moving composer.phar to /usr/local/bin/composer is the global install: that folder is on every user's search path, so composer works in any folder. It is the only Composer command that needs sudo. Never run sudo composer in a project, because the files it creates then belong to root and your own commands cannot change them. Notice that composer -V also reports which PHP it runs on. Update Composer later with sudo composer self-update.

One more line prepares for Module 6, where Composer installs command-line tools of its own into ~/.config/composer/vendor/bin. Add that folder to your search path in ~/.bashrc, then open a new terminal:

Terminal, both routes
$ echo 'export PATH="$HOME/.config/composer/vendor/bin:$PATH"' >> ~/.bashrc

PostgreSQL 18

PostgreSQL is the database server the Walk Office uses. It runs in the background as a service, listens for connections on port 5432, and keeps its data in files only it may touch. Programs that talk to it, such as psql, pgAdmin and PHP, are its clients. PostgreSQL 18 was released on 25 September 2025 and is supported until November 2030. Its latest minor release on 2 November 2026 was 18.6.

Installing from the PostgreSQL apt repository

Ubuntu includes PostgreSQL, but each Ubuntu release freezes one major version for its whole life: 16 in Ubuntu 24.04 and Mint 22, and 18 in Ubuntu 26.04. The PostgreSQL project runs its own apt repository, called PGDG (PostgreSQL Global Development Group), with every supported version for every current Ubuntu LTS, updated as soon as each fix is released. The course uses it on both routes, so everyone has the same PostgreSQL 18 with the same updates. The postgresql-common package includes a script that adds the repository and its signing key for you:

Terminal, Ubuntu 26.04 in WSL
$ sudo apt install -y postgresql-common
$ sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh
$ sudo apt install -y postgresql-18
Terminal, Linux Mint 22: give the script Ubuntu's code name
$ sudo apt install -y postgresql-common
$ sudo /usr/share/postgresql-common/pgdg/apt.postgresql.org.sh noble
$ sudo apt install -y postgresql-18

Without noble, the script on Mint stops with "Your system is using the distribution codename zena, but zena-pgdg does not seem to be a valid distribution", which is the code-name problem from Route A. Always install postgresql-18 by its number. The plain postgresql package means "the newest version", which from the PGDG repository will soon be PostgreSQL 19, whose first release candidate appeared on 15 October 2026.

Installing the package creates and starts a cluster, PostgreSQL's word for one running server with its own data folder and port. Ubuntu names clusters by version and name, so yours is 18/main.

Terminal, both routes
$ pg_lsclusters
Ver Cluster Port Status Owner    Data directory              Log file
18  main    5432 online postgres /var/lib/postgresql/18/main /var/log/postgr...
$ sudo systemctl status postgresql --no-pager
$ psql --version
psql (PostgreSQL) 18.6 (Ubuntu 18.6-1.pgdg24.04+1)

If the status is down, start the cluster with sudo pg_ctlcluster 18 main start and read its log file for the reason.

The postgres superuser and your own role

PostgreSQL has its own users, called roles. A role that may log in is a login role, and a superuser role may do anything. Installation creates a superuser role called postgres, and a Linux account of the same name that owns the data files. You reach it by running psql as that Linux user with sudo -u postgres.

Typing sudo -u postgres every time soon gets tiresome, so create a role for yourself, named exactly like your Linux user, and a database of the same name, which psql opens by default:

Terminal, both routes (your user name in place of lerato)
$ 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 -c 'SELECT current_user, current_database();'
 current_user | current_database
--------------+------------------
 lerato       | lerato
(1 row)

The first error is the one almost everyone meets: psql logs in with a role named like your Linux user, and none existed. createuser and createdb are small programs that run the SQL for you. Your role is a superuser because this is your own development machine, where you will create and drop databases freely. The Walk Office will never use it: the application gets its own role with far fewer rights.

psql basics

psql is PostgreSQL's command-line client. You type SQL, which Module 1 teaches, and end each statement with a semicolon. You also type meta-commands, which start with a backslash, are handled by psql itself, and need no semicolon. These are the ones you need now:

psql meta-commands for every day
Meta-commandDoes
\lLists the databases, with their owners
\c mandlas_walksConnects to another database
\dtLists the tables in the current database
\duLists the roles and their attributes
\conninfoSays who you are connected as, to which database, and how
\password walks_appSets a role's password without showing it or saving it in your history
\? and \hHelp on meta-commands, and on SQL statements
\qQuits psql (Ctrl+D does too)

The prompt tells you where you are: lerato=# means you are in the database lerato, and the # means you are a superuser. An ordinary role sees =>. If the prompt changes to lerato-#, psql is waiting for the rest of a statement because you forgot the semicolon: type ; and press Enter.

The Walk Office's role and database

The Walk Office connects to PostgreSQL as its own login role, walks_app, which is not a superuser, and its database, mandlas_walks, belongs to that role. Being the owner matters. Since PostgreSQL 15, ordinary roles may no longer create tables in another role's database by default: a role that is neither the owner nor given the right gets "permission denied for schema public". The owner may do anything inside its own database, which is exactly what the application needs during development, and nothing outside it.

psql, connected as yourself
lerato=# CREATE ROLE walks_app WITH LOGIN;
CREATE ROLE
lerato=# \password walks_app
Enter new password for user "walks_app":
Enter it again:
lerato=# CREATE DATABASE mandlas_walks OWNER walks_app;
CREATE DATABASE
lerato=# \du
                             List of roles
 Role name |                         Attributes
-----------+------------------------------------------------------------
 lerato    | Superuser, Create role, Create DB
 postgres  | Superuser, Create role, Create DB, Replication, Bypass RLS
 walks_app |

An empty Attributes column for walks_app is what you want: it may log in, and nothing more. Choose a long password that you do not use anywhere else, because Modules 4 and 6 put it in configuration files, and keep it in your password manager.

How PostgreSQL decides who you are: peer and password

Try to connect as walks_app the obvious way, and PostgreSQL refuses:

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"

The rules for who may connect, from where, and how they prove who they are, live in a file called pg_hba.conf (host-based authentication). sudo -u postgres psql -c 'SHOW hba_file;' prints its location, /etc/postgresql/18/main/pg_hba.conf. Ubuntu's version starts with these active lines, after its comments and before three lines for replication, which copies a whole server and does not concern you here:

/etc/postgresql/18/main/pg_hba.conf, the active lines
# TYPE  DATABASE        USER            ADDRESS                 METHOD
local   all             postgres                                peer
local   all             all                                     peer
host    all             all             127.0.0.1/32            scram-sha-256
host    all             all             ::1/128                 scram-sha-256

PostgreSQL reads the lines from the top and uses the first one that matches the connection. There are two kinds of connection. Without -h, psql connects through a Unix socket, a special file that works only on the same machine, and that matches a local line. With -h localhost, it makes a network connection over TCP to the address 127.0.0.1, and that matches a host line.

peer
For socket connections. PostgreSQL asks the operating system which Linux user is connecting, and allows the connection only if the role has the same name. No password is involved. That is why you, as lerato, can log in as the role lerato, and why you cannot log in as walks_app that way.
scram-sha-256
For TCP connections here. PostgreSQL checks the role's password, using a method that never sends the password itself across the connection.
psql with no -h option psql -h localhost or PHP's PDO Unix socket a file, same machine only TCP connection 127.0.0.1, port 5432 local line: peer Linux user name must equal the role name host line: scram-sha-256 the role's password is checked lerato as lerato no password asked walks_app, password typed, or from ~/.pgpass PostgreSQL 18 server, cluster 18/main
Figure 0.3: Two ways in. A socket connection proves who you are by your Linux user name, a TCP connection by the role's password.

So the application's role connects over TCP with its password, which is how PHP connects too. You do not need to edit pg_hba.conf for this course. If you ever do, reload PostgreSQL afterwards with sudo systemctl reload postgresql, and never change peer or scram-sha-256 to trust, which lets anyone in without a password.

Worked example: logging in as walks_app for the first time

Lerato has just created walks_app and mandlas_walks, and wants to check that the application's login works.

  1. First attempt. psql -U walks_app -d mandlas_walks fails with "Peer authentication failed for user walks_app". Reading the message: "Peer" names the method, so this was a socket connection, and her Linux user lerato is not walks_app.
  2. Switch to TCP. psql -h localhost -U walks_app -d mandlas_walks asks "Password for user walks_app:". She types it and gets the prompt mandlas_walks=>, with => because walks_app is not a superuser.
  3. Check where she is. SELECT current_user, current_database(); answers walks_app and mandlas_walks. \dt answers "Did not find any relations.", because Module 1 creates the tables.
  4. Check the owner's rights. CREATE TABLE smoke_test (id integer); answers CREATE TABLE, and DROP TABLE smoke_test; removes it. The owner may create tables, so Module 1 will work.
  5. Stop typing the password. She saves the password in ~/.pgpass, as shown next, and the same command now connects without asking.

Had she typed the password wrongly, the message would have been "password authentication failed for user walks_app", which names a different method and so a different cause.

Connection strings and ~/.pgpass

Every client needs the same five facts: host, port, database, user and password. A connection string packs them into one piece of text. PostgreSQL understands two forms, and PHP has a third:

The same connection written three ways
FormExampleUsed by
URIpostgresql://walks_app@localhost:5432/mandlas_walkspsql, many tools
Keywordshost=localhost port=5432 dbname=mandlas_walks user=walks_apppsql, libpq
PDO DSNpgsql:host=localhost;port=5432;dbname=mandlas_walksPHP, with the user and password given separately

A URI may also hold the password, as walks_app:secret@localhost, but then it ends up in your shell history and in screenshots. Better to keep it in ~/.pgpass, a file in your home folder that PostgreSQL's client library, libpq, reads whenever a server asks for a password. Each line is host:port:database:user:password. libpq ignores the file unless only you can read it:

Terminal, both routes (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)

PHP's PostgreSQL driver is built on libpq too, so it also reads ~/.pgpass when PHP runs as you. That lets this module's test page connect without a password in its code. From Module 6, Laravel keeps the same five facts in its .env file as DB_HOST, DB_PORT, DB_DATABASE, DB_USERNAME and DB_PASSWORD.

Try it: a tour in psql

Run psql as yourself. Type \l and find mandlas_walks and its owner. Type \c mandlas_walks, then \dt, then \du, then \conninfo, and read each answer. Leave out the semicolon from SELECT 1 and watch the prompt change, then finish the statement. Quit with \q.

A graphical client, if you want one

psql is all the course needs. A graphical client shows tables and data in a window, which some people find easier when exploring. Two are free and widely used:

  • pgAdmin 4, from the PostgreSQL community, version 9.19 on 2 November 2026. On Windows, download the installer from pgadmin.org/download. On Mint, add pgAdmin's apt repository using the line its download page gives for Mint users, which names noble, then install pgadmin4-desktop. pgAdmin's team says it does not test on Mint, so DBeaver may be the easier choice there.
  • DBeaver Community, a general database tool, version 26.2.4 on 2 November 2026. On Windows, use the installer from dbeaver.io/download. On Mint, install it from the Software Manager, which offers the Flatpak version, or with flatpak install flathub io.dbeaver.DBeaverCommunity.

On the WSL route, install the client on Windows, not in Ubuntu. Either way, create a connection with host localhost, port 5432, database mandlas_walks, user walks_app and its password. That is a TCP connection, so it uses the password rule from Figure 0.3. Microsoft's PostgreSQL extension for VS Code does the same inside your editor.

Node.js and Git

Node.js through nvm

Laravel uses front-end build tools that run on Node.js, from Module 6. Install Node exactly as in WEB-201, with nvm (Node Version Manager), inside Linux. Node 26 has been the Active LTS version since 28 October 2026, and nvm install --lts gave Node 26.13.0 on 2 November 2026. Copy the current install command from nodejs.org/en/download, because the nvm version in it changes:

Terminal, both routes
$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.40.8/install.sh \
    | bash
# Close the terminal and open a new one, then:
$ nvm install --lts
$ node -v
v26.13.0
$ which node
/home/lerato/.nvm/versions/node/v26.13.0/bin/node

Git, as in WEB-201

Git is already in Ubuntu and Mint. Check with git --version, and install it with sudo apt install git if needed. On the WSL route, Linux has its own Git settings, separate from Git for Windows, so tell it who you are again, exactly as in WEB-201:

Terminal, both routes
$ 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"

To push to GitHub from Linux, sign in with the GitHub CLI: sudo apt install gh, then gh auth login, choosing GitHub.com, HTTPS, "Yes" to authenticating Git with your GitHub credentials, and logging in with a web browser. On WSL, gh prints a one-time code and a web address to open in your Windows browser. SSH keys, the other way to sign in, come in Module 12, where you need them for servers.

VS Code for PHP and PostgreSQL

VS Code understands PHP's syntax out of the box but knows little about your code. Add these extensions. On WSL, install the last three "in WSL: Ubuntu", with a folder from Ubuntu open.

VS Code extensions for WEB-301, checked on 2 November 2026
ExtensionPublisherGives you
WSL (WSL route only)MicrosoftVS Code working inside Ubuntu
PHP IntelephenseBen Mewburn (shown as Intelephense)Completion, go to definition, error checking and PSR-12 formatting for PHP. The free features are all this course needs.
PostgreSQLMicrosoftConnect to PostgreSQL, browse tables and run SQL from the editor
EditorConfigEditorConfigApplies each project's .editorconfig rules for indentation and line endings

The other well-known PHP extension, "PHP" by DEVSENSE, does a similar job. Use one PHP extension, not both, or you get every suggestion twice. Intelephense's own instructions also ask you to switch off VS Code's built-in PHP suggestions: in Extensions, search for @builtin php, and disable PHP Language Features while leaving PHP Language Basics on, which colours the code. Laravel publishes an official Laravel extension too, which Module 6 introduces.

EditorConfig is a small file format, understood by most editors, that fixes a project's basic text rules so that everyone's editor saves files the same way. Each of your projects gets this file at its top. Laravel creates a very similar one itself in Module 6:

.editorconfig
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 4
insert_final_newline = true
trim_trailing_whitespace = true

[*.{js,json,css,html,yml,yaml}]
indent_size = 2

[*.md]
trim_trailing_whitespace = false

Four spaces suit PHP, as the PSR-12 coding standard requires, and two suit the JavaScript, CSS and HTML style from WEB-201. end_of_line = lf matters on Windows: Linux ends lines with one character, LF, and Windows with two, CR and LF. A Bash script saved with Windows line endings fails on Linux with errors such as "bad interpreter".

PHP's built-in server and a first page

A browser cannot run PHP. It asks a web server for a page, and the web server runs PHP to build it. On a real server that is Nginx and PHP-FPM, in Module 12. For development PHP includes its own small web server, started with php -S:

Terminal
$ php -S localhost:8000 -t stack-check
[Mon Nov  2 02:23:15 2026] PHP 8.5.12 Development Server
(http://localhost:8000) started

-S localhost:8000 says which address and port to listen on, and -t stack-check names the document root, the folder whose files the server offers. A request for http://localhost:8000/info.php runs stack-check/info.php. The terminal then shows a line for every request with its status code, such as [200]: GET /info.php, and any PHP errors. Stop the server with Ctrl+C. The PHP manual is clear that it is for development only and must never be used on a public network.

The first page calls phpinfo(), which builds a long page describing PHP's version, settings and extensions:

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

declare(strict_types=1); is the first statement of every plain PHP file in this course: it makes PHP refuse to quietly convert values between types, which Module 3 explains. Open the page and find the version at the top, "Loaded Configuration File", and the pdo_pgsql section. A phpinfo page tells an attacker exactly what to attack, which is why it never goes near a public server.

The second page proves PHP can reach PostgreSQL. It uses PDO (PHP Data Objects), PHP's standard way to talk to databases, which Module 4 teaches properly. For now, read it for the idea: build a DSN, connect, ask one question, show the answer safely.

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 part above ?> is PHP: it tries to connect, runs one query and keeps the answers in an array, or keeps the error message if anything fails. The part below is an HTML page with small pieces of PHP in it. <?= ... ?> prints a value, and every value goes through e(), which uses htmlspecialchars so that text containing < or & cannot break the page or inject HTML. With the server running from ~/projects/walks-notes, http://localhost:8000/db-check.php shows:

The page's content, as text
Database check
PHP version          8.5.12
PDO drivers          pgsql
Connected as         walks_app
Database             mandlas_walks
PostgreSQL version   18.6 (Ubuntu 18.6-1.pgdg24.04+1)

When that page shows your versions, the whole stack works: the browser asked PHP's server for a page, PHP ran your code, PDO used the pdo_pgsql extension to reach PostgreSQL over TCP, libpq found the password in ~/.pgpass, and PostgreSQL accepted walks_app into its own database.

The course's project folders

Everything you build lives under ~/projects, in the Linux file system on both routes. Each project is its own folder and its own Git repository on GitHub:

Projects in WEB-301
FolderModulesWhat it holds
~/projects/walks-notes0 onwardsYour notes for each module, the environment report and this module's check pages
~/projects/walks-sql1 and 2The database in plain SQL: sql/schema.sql, sql/seed.sql, sql/queries.sql, the ER diagram and backups
~/projects/walks-php3 to 5The booking pages in plain PHP, later restructured with Composer, run with php -S localhost:8000 -t public
~/projects/walk-office6 to 13The Laravel 13 application, the Walk Office itself

In this module you create only ~/projects and walks-notes. Each later module creates its own folder when it starts, and Laravel's installer in Module 6 creates walk-office itself. All four projects share the one database, mandlas_walks, so the data you design in Module 2 is the data the Walk Office shows in Module 7.

Keeping versions straight

Most set-up problems are version problems: two copies of a program, or a client and a server that disagree. Know the command that answers "which version am I really running?" for each tool:

Version checks
QuestionCommand
Which PHP runs when I type php?php -v and which php
Which PHP versions are installed?ls /usr/bin/php*
Which Composer, on which PHP?composer -V
Which psql client?psql --version
Which PostgreSQL server am I connected to?SHOW server_version; in psql
Which PostgreSQL clusters exist, on which ports?pg_lsclusters
Which Node, from where?node -v, which node and nvm ls

The client and the server are separate programs with separate versions. psql --version tells you nothing about the server, and a psql connected to an older or newer server warns "WARNING: psql major version 19, server major version 18." with the real numbers. Run the check that answers your actual question.

When versions differ

Two PHPs. The ondrej/php repository installs PHP versions side by side, as php8.3, php8.5 and so on, and php points to one of them. If php -v shows the wrong one, choose with sudo update-alternatives --config php, or type the full name, such as php8.5. Extensions belong to one version: installing php8.5-pgsql does nothing for PHP 8.3.

Two PostgreSQL clusters. If an older PostgreSQL was already installed, pg_lsclusters may show 16/main on port 5432 and your new 18/main on 5433, because Ubuntu gives each new cluster the next free port. You would then be working on PostgreSQL 16 without knowing. If the old cluster holds nothing you need, remove it with sudo pg_dropcluster 16 main --stop, set port = 5432 in /etc/postgresql/18/main/postgresql.conf, and restart with sudo systemctl restart postgresql.

A version that is too new. A tool newer than the course is usually fine within the same major version, such as PHP 8.5.14 or PostgreSQL 18.7. A new major version, such as PostgreSQL 19, can behave differently: stay with the course's versions until you finish it.

Try it: one command for every version

Run php -v | head -n 1; composer -V | head -n 1; psql --version; node -v; git --version in your terminal, then psql -h localhost -U walks_app -d mandlas_walks -c 'SHOW server_version;'. Compare them with the table at the start of this module. In the practical work you turn this into a small script.

Troubleshooting the common set-up errors

Every message below is a real one, and each names its cause if you read it slowly. Ask three questions: which program printed it (psql, PHP, Composer, the shell), what it was trying to do, and what word in it names the problem.

Common set-up errors and their fixes
MessageCauseFix
could not find driverPHP's pdo_pgsql extension is not installed or not loaded for this PHPsudo apt install php8.5-pgsql, check php -m, and restart php -S
Peer authentication failed for user "walks_app"A socket connection, and your Linux user is not walks_appAdd -h localhost to connect over TCP with the password
password authentication failed for user "walks_app"Wrong password, or a wrong line in ~/.pgpassReset it with \password walks_app as yourself, and correct ~/.pgpass
fe_sendauth: no password suppliedThe server wants a password and none was givenCheck ~/.pgpass: the line must match host, port, database and user, and the file needs chmod 600
role "lerato" does not existNo PostgreSQL role has your Linux user namesudo -u postgres createuser --superuser "$USER"
database "lerato" does not existpsql opens a database named like you by defaultcreatedb "$USER", or name one with -d
Connection refused or No such file or directory on the socketPostgreSQL is not running, or listens on another portpg_lsclusters, then sudo pg_ctlcluster 18 main start, and read the log
permission denied for schema publicThe role is not the database's ownerCreate the database with OWNER walks_app, or ALTER DATABASE mandlas_walks OWNER TO walks_app;
mv: cannot move ... Permission deniedWriting a system folder without sudoUse sudo for that one command, never for your own projects
Failed to listen on localhost:8000 (reason: Address already in use)Another server already uses port 8000, often one you forgot in another terminalStop it with Ctrl+C there, find it with ss -ltnp | grep :8000, or use port 8001

Two problems belong to WSL. If PostgreSQL in Ubuntu cannot start, or localhost:5432 reaches the wrong server, check whether you also installed PostgreSQL on Windows: both want port 5432, and WSL shares localhost with Windows. Uninstall the Windows copy, or stop its service. And if everything feels slow, run pwd: a path under /mnt/c means you are working across the bridge.

Sources