Skip to content

2. Setting Up a Development Environment

The scripts were written and tested in the following environment:

  • an [Apache] / [MySQL] DBMS / [PHP] 8.5 web server environment called [Laragon];
  • the [Visual Studio Code] editor and its extension [PHP Intelephense];
  • the dependency manager [Composer], provided with [Laragon], which installs the PHP libraries used by the course.

Other tools (the mail server [Mailpit], the [PostgreSQL] DBMS and the server [Redis]) are only relevant to certain chapters: their installation is described in the relevant chapters.

2.1. Installing Laragon

[Laragon] is a package for [Windows] that combines several software components:

  • a web server ([Apache]). We will use it to write web scripts in PHP;
  • the [MySQL] DBMS ([PostgreSQL] can be added to this, see the chapter on version 6);
  • the PHP scripting language, in several versions, including version 8.5;
  • a [Redis] server that implements a cache for web applications;
  • the [Composer] tool;
  • a command-line terminal in which all these tools can be used directly.

[Laragon] can be downloaded from https://laragon.org/download/. It is free to use with all its features; a prompt occasionally appears asking you to purchase a license to support its development, which is optional. Installation is straightforward: simply accept the default settings. [Laragon] is then installed in the [C:\laragon] folder, which we will refer to as <laragon> from here on:

1
2
3
4
5
6
C:\laragon
├── bin\        the software: apache, mysql, php, redis, composer…
├── data\       the DBMS data
├── etc\        configuration files
├── tmp\
└── www\        the root of the Apache web server: http://localhost

Launching [Laragon] displays its main window:

  • The [Démarrer tout] (Start All) button starts the [Apache] web server, as well as the [MySQL] DBMS. The window then indicates, for each of them, that it is active and on which port it is listening: 80 for [Apache], 3306 for [MySQL];
  • the [Web] button displays the [http://localhost] page, which corresponds to the [<laragon>/www] folder;
  • the [Base de données] (Database) button launches a database administration tool ([HeidiSQL], included with [Laragon]);
  • The [Terminal] button opens a command terminal in which [php], [composer], [mysql]… can be used directly;
  • The [Racine] (Root) button opens the [Windows] file explorer to the [<laragon>/www] folder. This is where you should place all web applications managed by the [Apache] server from [Laragon];
  • Right-clicking in the window (or on the [Laragon] icon in the taskbar) opens the [Laragon] menu, which provides access to the configuration settings for each application.

2.1.1. Select PHP 8.5

[Laragon] may contain multiple versions of PHP. The version to use is selected from its menu under the [PHP > Version] section. Select version 8.5 (the most recent in the 8.5 series). It will then be used by both the [Apache] server and the [php] terminal command.

In order for the [php] command to also be usable in [VS Code] terminals, the PHP folder must be located within the PATH folder of [Windows]. [Laragon] handles this: [Tools > Path > Add Laragon to Path] menu. Then open a new terminal (terminals that are already open will not see the change) and type:

> php -v

The command should display the version of PHP, 8.5.x.

2.1.2. Configure PHP for training

PHP is configured via a text file named [php.ini], accessible through the [Laragon] menu under the [PHP > php.ini] section. During training, PHP must report all errors, warnings, and deprecations. Verify that the file contains the following lines (or modify them):

1
2
3
4
5
6
error_reporting = E_ALL
display_errors = On
display_startup_errors = On
log_errors = On
error_log = C:/laragon/tmp/php_errors.log
date.timezone = Europe/Paris
  • [error_reporting = E_ALL]: PHP reports everything, including the [Deprecated] messages that announce deprecated features. A production configuration often uses [E_ALL & ~E_DEPRECATED], which hides them: that’s not what we want here;
  • [display_errors = On]: Messages are displayed in the script’s output (the terminal or the web page);
  • [log_errors = On]: Messages are also written to the error log;
  • [error_log]: the log file. Without this line, a console script writes its log to the terminal itself, and each message would appear there twice (once preceded by [PHP], once without it);
  • [date.timezone]: the time zone used by date functions.

The course also uses several extensions of PHP. They are enabled in the [Laragon] menu, under the [PHP > Extensions] section, or in the [php.ini] file using lines of the form [extension=name]. The extensions used are: [curl], [mbstring], [openssl], [pdo_mysql], [pdo_pgsql], [fileinfo], and [zip] (the latter is used by [Composer] to decompress the libraries it downloads). After modifying the [php.ini] file, you must restart [Apache] (the [Reload] button in [Laragon]); the console scripts, on the other hand, re-read the [php.ini] file each time they run.

You can verify the configuration in a terminal using the command [php --ini] (the [php.ini] file used) and [php -m] (the list of loaded extensions). The first script in the next chapter, [phpinfo.php], displays the entire configuration.

2.2. Installing VS Code

[Visual Studio Code] is a free editor from Microsoft, available for download at https://code.visualstudio.com/. Here, it replaces the [NetBeans] IDE used in the PHP 7 course.

Once [VS Code] is installed, add support for the PHP language: in the [Extensions] panel (Ctrl+Shift+X), search for and install the [PHP Intelephense] extension. It provides:

  • code completion: PHP functions, classes, their methods, and their attributes are suggested as you type;
  • display of documentation for a function or method when you hover over its name;
  • error detection as you type (undefined variables, incorrect types, nonexistent methods, etc.), which are underlined in the code and listed in the [Problems] panel;
  • code navigation: pressing Ctrl+click on a class or function name opens its definition, including those in the libraries within the [vendor] folder.

[Intelephense] must know the version of PHP being used to identify its new features: in the [VS Code] settings (Ctrl+comma), search for “intelephense php version” and enter 8.5.

Next, open the course code folder in [VS Code] ([File > Open Folder] menu). A terminal opens via the [Terminal > New Terminal] menu: it is set to the open folder, and you type the commands [php], [composer], [curl]… To run a console script, navigate to its folder (command [cd]) and type [php script-name.php].

2.3. Installing the Course Code

The course code files are contained in a folder named [php8-oct-2026], which can be downloaded at the beginning of this document. Place it in the [<laragon>/www] folder:

1
2
3
4
5
6
C:\laragon\www
└── php8-oct-2026
    ├── composer.json
    ├── phpunit.xml
    ├── scripts-console
    └── scripts-web

Its web scripts are then accessible at URLs [http://localhost/php8-oct-2026/...]. For example, once [Apache] is launched, the URL [http://localhost/php8-oct-2026/composer.json] should display the file [composer.json].

2.4. Installing Libraries with Composer

Like most programming languages, PHP has a dependency manager, [Composer], which downloads the libraries a project needs from the [packagist.org] repository. The libraries used by the course are declared in the [composer.json] file in the [php8-oct-2026] folder:

{
    "name": "stahe/php8-oct-2026",
    "description": "Code of the course \"Introduction to the PHP 8 language by example\" (October 2026)",
    "type": "project",
    "license": "MIT",
    "require": {
        "php": ">=8.5",
        "symfony/http-foundation": "^8.0",
        "symfony/http-client": "^8.0",
        "symfony/mailer": "^8.0",
        "symfony/mime": "^8.0",
        "predis/predis": "^3.0",
        "zbateson/mail-mime-parser": "^3.0"
    },
    "require-dev": {
        "phpunit/phpunit": "^12.0"
    },
    "config": {
        "sort-packages": true
    }
}
  • Line 6: the libraries required to run the scripts. Each is identified by a name in the form [vendor/library] and a version constraint: [^8.0] means “any version of 8.x starting with 8.0.” Their roles are described in the chapters that use them;
  • line 7: the project requires PHP 8.5 or later;
  • line 15: libraries used solely for development, in this case the [PHPUnit] testing framework.

To install these libraries, open a terminal in the [php8-oct-2026] folder (the [Laragon] terminal, or the [VS Code] terminal) and type:

> composer install

[Composer] then creates a folder named [vendor] containing the libraries and their dependencies, as well as a file named [vendor/autoload.php]. A script that wants to use these libraries simply needs to include this file, which automatically loads their classes the first time they are used. The scripts in this course do this using a path relative to their own folder, for example:

require_once __DIR__ . '/../../vendor/autoload.php';

The constant [__DIR__] refers to the folder of the script that uses it: therefore, the path does not depend on the folder in which the script is run, nor on where the [php8-oct-2026] folder is located.

Verify the installation by displaying the version of [PHPUnit]:

> php vendor/bin/phpunit --version
PHPUnit 12.5.37 by Sebastian Bergmann and contributors.

Now that the working environment has been installed, we can cover the basics of PHP.