PHP

PHP (distribué par php.net) est un langage de script côté serveur.

Installation

Après avoir vérifié que le système est à jour, ajoutez les sources du référentiel php :

sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/php
sudo LC_ALL=C.UTF-8 add-apt-repository ppa:ondrej/apache2

Installer php et son module Apache :

sudo apt install -y php8.4-cli libapache2-mod-php8.4

Installer les modules supplémentaires requis par Grav:

sudo apt install -y php8.4-{apcu,bz2,ctype,curl,dom,gd,json,mbstring,opcache,openssl,session,simplexml,xml,yaml,zip}
Au moment de la rédaction de ce tutoriel (août 2025), la dernière version de php est la 8.4 ; vérifiez si vous devez migrer vers une nouvelle version.
La version installée actuellement est donnée par php -v:
PHP 8.4.11 (cli) (built: Aug  3 2025 08:42:27) (NTS)
Copyright (c) The PHP Group
Built by Debian
Zend Engine v4.4.11, Copyright (c) Zend Technologies
    with Zend OPcache v8.4.11, Copyright (c), by Zend Technologies
    

PHP-FPM

sudo apt install -y php-fpm

Créer un utilisateur dédié :

sudo useradd -m -s /bin/bash www-user
sudo passwd www-user

Configurer un pool :

sudo cp /etc/php/8.4/fpm/pool.d/www.conf /etc/php/8.4/fpm/pool.d/grav.conf
sudo nano /etc/php/8.4/fpm/pool.d/grav.conf

Modifier les lignes non commentées :

; Start a new pool named 'www'.
; the variable $pool can be used in any directive and will be replaced by the
; pool name ('www' here)
[grav]
; Unix user/group of the child processes. This can be used only if the master
; process running user is root. It is set after the child process is created.
; The user and group can be specified either by their name or by their numeric
; IDs.
; Note: If the user is root, the executable needs to be started with
;       --allow-to-run-as-root option to work.
; Default Values: The user is set to master process running user by default.
;                 If the group is not set, the user's group is used.
user = www-user
group = www-user
; The address on which to accept FastCGI requests.
; Valid syntaxes are:
;   'ip.add.re.ss:port'    - to listen on a TCP socket to a specific IPv4 address on
;                            a specific port;
;   '[ip:6:addr:ess]:port' - to listen on a TCP socket to a specific IPv6 address on
;                            a specific port;
;   'port'                 - to listen on a TCP socket to all addresses
;                            (IPv6 and IPv4-mapped) on a specific port;
;   '/path/to/unix/socket' - to listen on a unix socket.
; Note: This value is mandatory.
listen = /run/php/php8.4-fpm-grav.sock
; Set permissions for unix socket, if one is used. In Linux, read/write
; permissions must be set in order to allow connections from a web server. Many
; BSD-derived systems allow connections regardless of permissions. The owner
; and group can be specified either by name or by their numeric IDs.
; Default Values: Owner is set to the master process running user. If the group
;                 is not set, the owner's group is used. Mode is set to 0660.
listen.owner = www-user
listen.group = www-data
listen.mode = 0660
; Choose how the process manager will control the number of child processes.
; Possible Values:
;   static  - a fixed number (pm.max_children) of child processes;
                                   [...]
;             pm.process_idle_timeout   - The number of seconds after which
;                                         an idle process will be killed.
; Note: This value is mandatory.
pm = dynamic
; The number of child processes to be created when pm is set to 'static' and the
; maximum number of child processes when pm is set to 'dynamic' or 'ondemand'.
; This value sets the limit on the number of simultaneous requests that will be
; served. Equivalent to the ApacheMaxClients directive with mpm_prefork.
; Equivalent to the PHP_FCGI_CHILDREN environment variable in the original PHP
; CGI. The below defaults are based on a server without much resources. Don't
; forget to tweak pm.* to fit your needs.
; Note: Used when pm is set to 'static', 'dynamic' or 'ondemand'
; Note: This value is mandatory.
pm.max_children = 5

; The number of child processes created on startup.
; Note: Used only when pm is set to 'dynamic'
; Default Value: (min_spare_servers + max_spare_servers) / 2
pm.start_servers = 2

; The desired minimum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.min_spare_servers = 1

; The desired maximum number of idle server processes.
; Note: Used only when pm is set to 'dynamic'
; Note: Mandatory when pm is set to 'dynamic'
pm.max_spare_servers = 3

Enregistrer et quitter nano.
Éditer le fichier php.ini:

sudo nano /etc/php/8.4/apache2/php.ini

Chercher et modifier les valeurs de ces paramètres :

; Maximum execution time of each script, in seconds
; https://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 300
; Maximum amount of time each script may spend parsing request data. It's a good
; idea to limit this time on productions servers in order to eliminate unexpectedly
; long running scripts.
; Note: This directive is hardcoded to -1 for the CLI SAPI
; Default Value: -1 (Unlimited)
; Development Value: 60 (60 seconds)
; Production Value: 60 (60 seconds)
; https://php.net/max-input-time
max_input_time = 300
; Maximum amount of memory a script may consume
; https://php.net/memory-limit
memory_limit = 512M
; Maximum size of POST data that PHP will accept.
; Its value may be 0 to disable the limit. It is ignored if POST data reading
; is disabled through enable_post_data_reading.
; https://php.net/post-max-size
post_max_size = 1G
; Maximum allowed size for uploaded files.
; https://php.net/upload-max-filesize
upload_max_filesize = 1G

Enregitrer et quitter nano.
Modifier ces même lignes dans le fichier ini de PHP-FPM :

sudo nano /etc/php/8.4/fpm/php.ini

Redémarrer le service php-fpm :

sudo systemctl restart php8.4-fpm.service

Mettre à jour l'hôte virtuel

Éditer le fichier de configuration du vHost HTTP :

sudo nano /etc/apache2/sites-available/grav.howto.ovh.conf

Ajouter ce contenu entre la ligne DocumentRoot /www/grav.howto.ovh et la ligne <Directory /www/grav.howto.ovh>:

    <FilesMatch "\.php$">
        SetHandler "proxy:unix:/run/php/php8.4-fpm-grav.sock|fcgi://localhost/"
    </FilesMatch>

Enregitrer et quitter nano.
Réaliser la même modification pour le fichier de configuration du vHost HTTPS :

sudo nano /etc/apache2/sites-available/grav.howto.ovh-le-ssl.conf

Redémarrer le service :

sudo systemctl restart apache2