Skip to content

13. Appendices

13.1. Installing PHP

The examples and case study require [PHP] 8.4 or a later version, with the extensions [intl] (number formatting, Example 16), [pdo_mysql] (access to [MySQL], Example 28 and case study), [mbstring], and [openssl]. They have been tested with version 8.4.

Under [Windows], the simplest option is [Laragon] (laragon.org), which installs [PHP], [Composer], a [MySQL] server, and the [HeidiSQL] administration tool. If the provided version of [PHP] is older than 8.4, download a more recent version from windows.php.net/download (the *Thread Safe* version, [.zip] archive), which you should extract into the [bin\php] folder of [Laragon]; the PHP / [Laragon] version allows you to select it. The PHP / Extensions menu activates an extension with a single click ([intl], [pdo_mysql]). The [Laragon] terminal (Terminal button) supports the commands [php], [composer], and [mysql].

Without [Laragon], extract the archive from [PHP] into a folder ([C:\php]), add this folder to the environment variable [Path], then create the configuration file [php.ini] by copying [php.ini-development], and remove the semicolon that comments out the lines for the required extensions:

1
2
3
4
extension=intl
extension=mbstring
extension=openssl
extension=pdo_mysql

Under [macOS], the package manager [Homebrew] installs [PHP] and its standard extensions: [brew install php]. For [Linux] ([Ubuntu]), the version provided by the distribution is often older; the [ppa:ondrej/php] repository provides the latest versions:

sudo add-apt-repository ppa:ondrej/php
sudo apt install php8.4-cli php8.4-intl php8.4-mbstring php8.4-mysql php8.4-xml php8.4-curl php8.4-zip

Verify the installation in a new console:

php -v
php -m

The first command should display a version number equal to or greater than 8.4 (for example, [PHP 8.4.12]); the second lists the loaded extensions, including [intl] and [pdo_mysql]. The command [php --ini] indicates which file, [php.ini], is being used.

13.2. Compose

[Composer] is the library manager for [PHP] (getcomposer.org). It is provided by [Laragon]; for [Windows], without [Laragon], its installer ([Composer-Setup.exe]) is used; for [macOS], use [brew install composer]; for [Linux], follow the instructions on the getcomposer.org/download page. Verify the installation:

composer -V

Useful commands in a project folder (the one containing [composer.json]):

1
2
3
4
composer install            # install the project's libraries (vendor folder)
composer show               # the installed libraries
composer update             # move to the most recent versions allowed by composer.json
composer dump-autoload      # rebuild the class loader (after adding a folder of classes)

[Composer] downloads the libraries from the [Packagist] (packagist.org) repository: an Internet connection is required during installation. If you are behind a corporate proxy, specify the proxy using the environment variables [HTTP_PROXY] and [HTTPS_PROXY]. The [vendor] folder is not copied from one machine to another (it may contain absolute paths and is large); it is recreated using [composer install]. This is why it is not included in the course materials. The [examples] folder has its own [vendor] folder, shared by all 28 examples; the case study has its own.

13.3. Installing Visual Studio Code

[Visual Studio Code] is downloaded from code.visualstudio.com. Add two extensions (View menu / Extensions):

  • PHP Intelephense: code completion, code navigation (including the code from [Laravel], in the [vendor] folder), and error reporting;
  • Laravel (the official extension): syntax highlighting for [Blade] views, and autocompletion for route names, view names, configuration keys, and translation keys.

The PHP Debug extension allows you to step through the code using the [Xdebug] debugger (an extension of [PHP], which must be installed separately: xdebug.org).

Open the [examples] folder or the case study folder (File menu / Open Folder). The built-in terminal (Terminal menu / New Terminal) allows you to launch applications without leaving the editor.

13.4. Installing MySQL with Laragon

[Laragon] installs a ready-to-use [MySQL] server under [Windows], along with the [HeidiSQL] administration tool. After installation:

  • the "Start All" button launches the [MySQL] server on port 3306;
  • the user [root] has no password: these are the values from the [.env] files in Example 28 and the case study ([DB_USERNAME=root], [DB_PASSWORD=]) ;
  • The Database button opens [HeidiSQL], where the File menu / Run a File menu item (SQL) runs the scripts [dbpersons.sql] (Example 28) and [dbrdvmedecins2.sql] (case study).

In [Linux] or [macOS], install [MySQL] or [MariaDB] using the system’s package manager, and run the scripts using the command-line client [mysql]. The [pdo_mysql] driver works with both without any configuration. Under [Linux], the [root] account for [MariaDB] is often configured to log in only via the system account [root] ([sudo mysql]): a user is then created for the applications, and this user is specified in their [.env] file:

sudo mysql -e "CREATE USER 'course'@'localhost' IDENTIFIED BY 'course'; GRANT ALL ON *.* TO 'course'@'localhost';"

13.5. Installing curl

[curl] comes bundled with [Windows] 10 and 11, [macOS], and most [Linux] distributions. In [PowerShell], you must type [curl.exe], not [curl]: In older versions of [PowerShell], [curl] is an alias for another command ([Invoke-WebRequest]), which has different options. In the command prompt for [Windows] ([cmd]), the quotation marks for a string JSON are written as [\"] (example 11), and a URL that contains [&] must be enclosed in double quotes.