relecture rapide et ajout rlimit_files
This commit is contained in:
parent
71bcdbb948
commit
76dec40145
86
HowtoPHP.md
86
HowtoPHP.md
|
@ -8,8 +8,8 @@ title: Howto PHP
|
|||
|
||||
[PHP](http://php.net/) est un langage de programmation populaire
|
||||
pour le développement web. PHP peut s'utiliser en CLI (ligne de
|
||||
commande), via mod_php (module intégré à [Apache](HowtoApache)) ou
|
||||
via FPM (FastCGI Process Manager).
|
||||
commande), via `mod_php` (module intégré à [Apache](HowtoApache))
|
||||
ou via FPM (FastCGI Process Manager).
|
||||
|
||||
|
||||
Il existe [plusieurs versions de PHP](http://php.net/supported-versions.php).
|
||||
|
@ -130,16 +130,19 @@ PHP avec [Apache](HowtoApache) ou [Nginx](HowtoNginx).
|
|||
~~~
|
||||
# apt install php-fpm
|
||||
|
||||
# systemctl status php7.0-fpm
|
||||
● php7.0-fpm.service - The PHP 7.0 FastCGI Process Manager
|
||||
Loaded: loaded (/lib/systemd/system/php7.0-fpm.service; enabled; vendor preset: enabled)
|
||||
Docs: man:php-fpm7.0(8)
|
||||
Main PID: 1516 (php-fpm7.0)
|
||||
Status: "Processes active: 0, idle: 2, Requests: 0, slow: 0, Traffic: 0req/sec"
|
||||
CGroup: /system.slice/php7.0-fpm.service
|
||||
├─1516 php-fpm: master process (/etc/php/7.0/fpm/php-fpm.conf)
|
||||
├─1517 php-fpm: pool www
|
||||
└─1518 php-fpm: pool www
|
||||
# systemctl status php7.3-fpm
|
||||
● php7.3-fpm.service - The PHP 7.3 FastCGI Process Manager
|
||||
Loaded: loaded (/lib/systemd/system/php7.3-fpm.service; enabled; vendor preset: enabled)
|
||||
Active: active (running) since Tue 2023-06-27 19:42:26 CEST; 1h 41min ago
|
||||
Docs: man:php-fpm7.3(8)
|
||||
Main PID: 7213 (php-fpm7.3)
|
||||
Status: "Processes active: 3, idle: 199, Requests: 197051, slow: 0, Traffic: 30.7req/sec"
|
||||
Tasks: 203 (limit: 4915)
|
||||
Memory: 1.9G
|
||||
CGroup: /system.slice/php7.3-fpm.service
|
||||
├─ 712 php-fpm: pool front
|
||||
├─ 725 php-fpm: pool front
|
||||
...
|
||||
~~~
|
||||
|
||||
> *Note* : Pour Debian 8, il faut installer ainsi :
|
||||
|
@ -169,21 +172,21 @@ PHP avec [Apache](HowtoApache) ou [Nginx](HowtoNginx).
|
|||
Fichiers de configuration :
|
||||
|
||||
~~~
|
||||
/etc/php/7.0/
|
||||
/etc/php/7.3/
|
||||
├── apache2
|
||||
│ ├── conf.d
|
||||
│ │ ├── [...]
|
||||
│ │ └── 20-xsl.ini -> /etc/php/7.0/mods-available/xsl.ini
|
||||
│ │ └── 20-xsl.ini -> /etc/php/7.3/mods-available/xsl.ini
|
||||
│ └── php.ini
|
||||
├── cli
|
||||
│ ├── conf.d
|
||||
│ │ ├── [...]
|
||||
│ │ └── 20-xsl.ini -> /etc/php/7.0/mods-available/xsl.ini
|
||||
│ │ └── 20-xsl.ini -> /etc/php/7.3/mods-available/xsl.ini
|
||||
│ └── php.ini
|
||||
├── fpm
|
||||
│ ├── conf.d
|
||||
│ │ ├── [...]
|
||||
│ │ └── 20-xsl.ini -> /etc/php/7.0/mods-available/xsl.ini
|
||||
│ │ └── 20-xsl.ini -> /etc/php/7.3/mods-available/xsl.ini
|
||||
│ ├── php-fpm.conf
|
||||
│ ├── php.ini
|
||||
│ └── pool.d
|
||||
|
@ -193,19 +196,20 @@ Fichiers de configuration :
|
|||
└── xsl.ini
|
||||
~~~
|
||||
|
||||
On peut valider une configuration avec le binaire php-fpmx.y
|
||||
On peut valider une configuration ainsi :
|
||||
|
||||
~~~
|
||||
# php-fpm7.3 -t
|
||||
[27-Jun-2023 21:24:58] NOTICE: configuration file /etc/php/7.3/fpm/php-fpm.conf test is successful
|
||||
~~~
|
||||
|
||||
### Configuration de base (php.ini)
|
||||
|
||||
Il existe un fichier `php.ini` distinct suivant l’utilisation de
|
||||
PHP : cli, mod_php et FPM.
|
||||
Par exemple `/etc/php/7.0/fpm/php.ini` pour FPM.
|
||||
Par exemple `/etc/php/7.3/fpm/php.ini` pour FPM.
|
||||
|
||||
Le fichier `/etc/php/7.0/fpm/conf.d/z-evolinux-defaults.ini` contient
|
||||
Le fichier `/etc/php/7.3/fpm/conf.d/z-evolinux-defaults.ini` contient
|
||||
nos optimisations basiques :
|
||||
|
||||
~~~
|
||||
|
@ -227,20 +231,22 @@ Voici les directives de base :
|
|||
|
||||
~~~
|
||||
[global]
|
||||
pid = /run/php/php7.0-fpm.pid
|
||||
error_log = /var/log/php5-fpm.log
|
||||
pid = /run/php/php7.3-fpm.pid
|
||||
error_log = /var/log/php7.3-fpm.log
|
||||
rlimit_files = 65536
|
||||
~~~
|
||||
|
||||
On définit ensuite un ou plusieurs *pools* FPM via
|
||||
`/etc/php/7.0/fpm/pool.d/*.conf` :
|
||||
`/etc/php/7.3/fpm/pool.d/*.conf` :
|
||||
|
||||
~~~
|
||||
[www]
|
||||
listen = /run/php/php7.0-fpm.sock
|
||||
listen = /run/php/php7.3-fpm.sock
|
||||
;listen = 127.0.0.1:9000
|
||||
user = www-data
|
||||
group = www-data
|
||||
pm = dynamic
|
||||
rlimit_files = 4096
|
||||
|
||||
php_admin_value[sendmail_path] = /usr/sbin/sendmail -t -i -f return-path@example.com
|
||||
php_flag[display_errors] = off
|
||||
|
@ -330,7 +336,7 @@ On configure FPM avec Apache, par exemple dans un VirtualHost :
|
|||
~~~{.apache}
|
||||
DocumentRoot /home/bench/www/
|
||||
#ProxyPassMatch "^/(.*\.php(/.*)?)$" "fcgi://127.0.0.1:9000//home/foo/www/$1"
|
||||
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php/php7.0-fpm.sock|fcgi://localhost/home/foo/www/"
|
||||
ProxyPassMatch "^/(.*\.php(/.*)?)$" "unix:/var/run/php/php7.3-fpm.sock|fcgi://localhost/home/foo/www/"
|
||||
~~~
|
||||
|
||||
### Configuration mod_php
|
||||
|
@ -540,7 +546,7 @@ phalcon
|
|||
Installer les dépendances suivantes :
|
||||
|
||||
~~~
|
||||
# apt install php7.0-dev libpcre3-dev gcc make php7.0-mysql
|
||||
# apt install php7.3-dev libpcre3-dev gcc make php7.3-mysql
|
||||
~~~
|
||||
|
||||
> *Note* : Pour Debian 8 :
|
||||
|
@ -972,28 +978,28 @@ Il faut faire attention parce que cette API est aussi vulnérable a
|
|||
|
||||
Exemple pour [Google Recaptcha](http://www.google.com/recaptcha/intro/v3.html):
|
||||
|
||||
Remplacer
|
||||
Remplacer :
|
||||
|
||||
```
|
||||
~~~
|
||||
$recaptcha = new \ReCaptcha\ReCaptcha($secret);
|
||||
```
|
||||
~~~
|
||||
|
||||
Par
|
||||
Par :
|
||||
|
||||
```
|
||||
~~~
|
||||
$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\SocketPost());
|
||||
```
|
||||
~~~
|
||||
|
||||
|
||||
### Répertoire temporaire pour ImageMagick
|
||||
|
||||
Par défaut ImageMagick met ses données temporaires dans `/tmp`. Dans le cas où le volume monté sur `/tmp` est trop petit, on peut modifier le répertoire temporaire dans le fichier `/etc/ImageMagick-6/policy.xml` :
|
||||
|
||||
```xml
|
||||
~~~{.xml}
|
||||
<policymap>
|
||||
<policy domain="resource" name="temporary-path" value="/home/imagicktmp"/>
|
||||
</policymap>
|
||||
```
|
||||
~~~
|
||||
|
||||
|
||||
### Erreur opendir /var/lib/php/sessions failed Permission denied
|
||||
|
@ -1006,4 +1012,18 @@ Certaines applications comme Symfony outrepassent cette configuration et tentent
|
|||
|
||||
Le service systemd `phpsessionclean` est parfois en erreur dans les conteneurs LXC Debian 10 et 11 à cause de AppArmor. Pour résoudre le problème, il faut ajouter `lxc.apparmor.profile = unconfined` à la configuration du conteneur et le redémarrer. On peut ensuite vérifier le bon fonctionnement du service `phpsessionclean`.
|
||||
|
||||
### Erreur Too many open files
|
||||
|
||||
Si vous obtenez des erreurs du type :
|
||||
|
||||
~~~
|
||||
failed to open stream: Too many open files
|
||||
failed to open dir: Too many open files
|
||||
PHP Fatal error: date_default_timezone_get(): Timezone database is corrupt - this should *never* happen!
|
||||
~~~
|
||||
|
||||
Vous devez augmenter le nombre maximum de fichiers ouverts par process.
|
||||
Avec Apache/mod_php, voir [/HowtoApache#too-many-open-files]()
|
||||
Avec PHP-FPM, il faut modifier la directive `rlimit_files` dans la section `[global]` et le(s) pool(s) concerné(s).
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue