13. Appendices
13.1. Installing PHP
The examples and case study require [PHP] 8.4 or a later version ([Symfony] 8 requires it), with the extensions [intl] (number and date formatting, Example 16, and messages ICU, Example 22), [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 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 (Thread Safe version, archive [.zip]), and extract it into the [bin\php] folder within [Laragon]; the PHP / Version menu in [Laragon] then 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:
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:
Verify the installation in a new console:
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. Composer
[Composer] is the library manager for [PHP] (getcomposer.org). It is provided by [Laragon]; for [Windows], but not for [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:
Useful commands in a project folder (the one containing [composer.json]):
[Composer] downloads the libraries from the repository [Packagist] (packagist.org): 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.
The case study uses the [Runtime] component of [Symfony], which is also a plugin for [Composer]: it is this component that generates the [vendor/autoload_runtime.php] file read by [public/index.php]. [Composer] requests permission to run a plugin; the [composer.json] file from the application grants it (section [allow-plugins]). Under [Linux], [Composer] refuses to run plugins when launched by the [root] account, unless the environment variable [COMPOSER_ALLOW_SUPERUSER] is set to [1]: without it, the file [autoload_runtime.php] would be missing (see “Common Issues” in the case study). It is best not to work under the [root] account.
13.3. Installing Visual Studio Code
[Visual Studio Code] is downloaded to code.visualstudio.com. Add three extensions (View menu / Extensions):
- PHP Intelephense: code completion, code navigation (including the code for [Symfony], located in the [vendor] folder), and error reporting;
- Twig Language 2: syntax highlighting and completion for [Twig] views ([.html.twig] files);
- YAML (from [Red Hat]): syntax highlighting and validation of configuration files ([config/packages/*.yaml]) and dictionaries ([translations/*.yaml]).
The PHP Debug extension allows you to execute the code step by step using the [Xdebug] debugger (an extension of [PHP], to 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 and run [php bin/console ...] commands 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 of the variable [DATABASE_URL] from the [.env] files in Example 28 and the case study ([mysql://root:@127.0.0.1:3306/...]);
- the Database button opens [HeidiSQL], where the File menu / Run File 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 is specified in the [DATABASE_URL] variable in their [.env] ([mysql://course:course@127.0.0.1:3306/...]) file:
With [MariaDB], you also specify its version in the [DATABASE_URL] variable ([serverVersion=10.11.2-MariaDB] instead of [serverVersion=8.0.32], for example): [Doctrine] adapts the SQL it writes to the database being used.
13.5. Installing curl
[curl] is included with [Windows] 10 and 11, [macOS], and most [Linux] distributions. On [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.
13.6. The symfony tool
[Symfony] provides a command-line tool, the [symfony] program (Symfony CLI), which is not required to follow this document but is referenced throughout the documentation. It is installed by following the instructions on the symfony.com/download page: under [Windows], using the [Scoop] ([scoop install symfony-cli]) package manager; under [macOS], with [Homebrew] ([brew install symfony-cli/tap/symfony-cli]); under [Linux], with the system’s package manager. The most useful commands:
Its development server does the same thing as [php -S localhost:8000 -t public], with a few advantages: it locates the [public] folder on its own, it can serve the site in HTTPS (after [symfony server:ca:install]), it can run in the background ([symfony server:start -d], then [symfony server:stop]), and it selects the [PHP] version of the project when multiple versions are installed. The server built into [PHP], used in this document, has the advantage of requiring no installation.