devsetup1-7 Exercise 1: PHP Without a Web Server ================================================== STEP 1: CHECK FIRST ------------------- command -v php # nothing on a fresh install dpkg -l 'php*' | grep ^ii apt policy php-cli STEP 2: INSTALL THE RIGHT PACKAGES ---------------------------------- sudo apt install php-cli php-mbstring php-xml php-curl php-zip php-intl php-mysql php-sqlite3 Read apt's list of packages to be installed BEFORE confirming. It should contain php8.4-cli, php8.4-common and the extension packages. It should NOT contain apache2, libapache2-mod-php8.4, php8.4-fpm or php8.4-cgi. STEP 3: VERIFY -------------- php -v php -m | grep -Ei 'mbstring|curl|mysqli|pdo_mysql|pdo_sqlite|zip|intl' type -a php Expected: PHP 8.4.x; each of the modules listed (mbstring, curl, mysqli, pdo_mysql, pdo_sqlite, zip, intl); and a single /usr/bin/php. Confirm no web server came along: dpkg -s apache2 # "package 'apache2' is not installed" systemctl status apache2 # "Unit apache2.service could not be found" ss -tlnp # nothing listening on port 80 STEP 4: SERVE A PAGE -------------------- mkdir -p ~/projects/php-demo && cd ~/projects/php-demo echo ' index.php php -S localhost:8000 Open http://localhost:8000. The page shows the PHP version and "devserver". The terminal prints a line for each request. Stop with Ctrl+C. WHY apt install php IS WRONG HERE --------------------------------- The php package is a metapackage that depends on php8.4, and php8.4 depends on ONE of: libapache2-mod-php8.4, php8.4-fpm or php8.4-cgi (plus php8.4-common). It exists to make sure a server-side PHP interpreter is present. On a typical system apt satisfies that requirement by installing Apache and its PHP module, which starts a web server on a development machine that only needed the command-line PHP. php-cli gives you the php command, and the individual extensions give you what projects actually need, with no web server. WHY THIS WORKS AS AN ANSWER --------------------------- The exercise checks the result three ways (packages, modules, and the absence of a web server) rather than assuming that a successful install means the right install. Reading apt's plan before confirming is the habit that catches this kind of mistake.