Le Système LEMP: Linux/Engine-X/MySQL/PHP est très performant.
Le serveur web Engine-X (les anglais savent prononcer nginx) sort du paradigme synchrone en ne servant pas un client après l'autre, mais plusieurs en parallèle.
Apache fonctionne en mode synchrone: un client se connecte, demande et reçoit sa page. Pendant ce temps les autres clients derrière font la queue en attendant leur tour.
Nginx au contraire sert un petit peu le premier client, puis le second et ainsi de suite avant de repasser au premier. Cela se passe si vite que ça semble instantané, comme dans un système d'exploitation multitâche coopératif, qui exécute quelques instructions de chaque application chargée. PHP fait la même chose (php-fpm).
nginx est plus rapide qu'Apache et beaucoup plus simple à configurer.
- Installation
- Configuration
- Dossier perso ~/www
- PHP-FPM
- PHP GD
- PHP Opcache (à finir)
- MySQL/PHPMyAdmin
INSTALLER NGINX SUR LINUX
Répertoire de publicationPar défaut /var/www mais on peut le changer:
$ sudo mkdir /media/149Go/www $ sudo chown -R $USER:$USER /media/149Go/www $ gedit /media/149Go/www/index.html
<html> <head> <title>your_domain website</title> </head> <body> <h1>Hello World!</h1> <p>This is the landing page of <strong>your_domain</strong>.</p> </body> </html>
$ sudo apt update $ sudo apt install nginx
$ service nginx start ou $ sudo systemctl restart nginx (cette commande retient le mot de passe saisi)Si Apache tourne, nginx plante. Voir les applications qui occupent le port 80:
$ sudo lsof -i:80 $ sudo systemctl stop apache2tester
http://localhost
http://127.0.0.1
CONFIGURER NGINX
Voir la config. Normalement on ne touche à rien (https://www.nginx.com/resources/wiki/start/topics/examples/full/)$ gedit /etc/nginx/nginx.conf
$ sudo gedit /etc/nginx/sites-enabled/defaultChanger le DocumentRoot
#root /var/www/html; root /media/149Go/www;en bas il montre un exemple de Virtual Host, à tester
Vérifie la config
$ sudo nginx -tRecharge la config
$ sudo systemctl reload nginxredémarre le serveur
$ sudo systemctl restart nginxvoir les sites activés
$ grep -R "root" /etc/nginx/sites-enabled
DOSSIER PERSO ~/www
L'exemple précédent utilisait un dossier www sur un disque SATA disctinct du système d'exploitation.Si vous préférez -par facilité des droits d'écriture des fichiers- avoir un dossier /home/joe/www ou /home/joe/public_html
$ mkdir ~/www ou $ mkdir /home/joe/www $ echo "<h1>ok</h1>" >> /home/joe/www/index.html $ sudo gedit /etc/nginx/sites-enabled/defaultLa config Nginx avec PHP:
server { listen 80 default_server; listen [::]:80 default_server; root /home/joe/www; index index.html index.php; server_name _; location / { try_files $uri $uri/ =404; #try_files $uri $uri/ /index.html; } #error_page 404 /404.html; #error_page 500 502 503 504 /50x.html; location ~ \.php$ { include snippets/fastcgi-php.conf; fastcgi_pass unix:/run/php/php8.1-fpm.sock; } # deny access to Apache .htaccess on Nginx with PHP, # if Apache and Nginx document roots concur location ~ /\.ht { deny all; } }
PAGES D'ERREUR PERSO
En cas de 404 le serveur répond<html> <head><title>404 Not Found</title></head> <body> <center><h1>404 Not Found</h1></center> <hr><center>nginx/1.18.0 (Ubuntu)</center> </body> </html>
$ sudo gedit /etc/nginx/nginx.conf $ sudo gedit /etc/nginx/sites-enabled/default
server { ... error_page 404 /err/error404.html; ... }
PHP
PHP peut tourner comme librairie partagée chargée par Apache, ou sous forme de service (php-fpm) ce qui améliore les performances.$ sudo apt install php-fpm php-mysqlS'assurer que le service PHP tourne
$ sudo systemctl status php7.1-fpm.service
$ sudo gedit /etc/nginx/sites-enabled/defaultajouter
location ~ \.php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; include snippets/fastcgi-php.conf; }
$ sudo systemctl restart nginx ou $ service nginx reload
$ gedit /etc/php/7.4/fpm/php.iniligne 798 décommenter cgi.fix_pathinfo=0
Ligne 503 afficher les erreurs sur la machine de dev en mettant
display_errors = On
Recharger le service
$ service php7.4-fpm reloadinfo.php
<?php phpinfo(); ?>http://127.0.0.1/info.php
Après peut-être il faut mettre server localhost dans la config pour pouvoir faire
http://localhost/info.php
PHP GD
Il y a quelques changements avec PHP8 (il dit une erreur: Constant not defined IMG_JPEG).Lancer un phpinfo() pour savoir le chemin du fichier ini puis
$ sudo gedit /etc/php/8.1/fpm/php.iniCTRL-F saisir GD et décommenter la ligne 922
extension=gd
Enregistrer fermer
$ sudo apt-get install php-gd $ service nginx reload
PHP OPCACHE
$ gedit /etc/php/7.4/fpm/php.iniCTRL-F opcache. ligne 1766
tout décommenter
MySQL
$ sudo apt-get install mysql-server mysql-client $ sudo mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.26-0ubuntu0.20.04.2 (Ubuntu) Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> mysql> use mysql; mysql> SELECT user,plugin,host FROM user; mysql> CREATE DATABASE mabase; mysql> CREATE USER 'bert'@'localhost' IDENTIFIED BY 'mot_de_passe_solide'; mysql> GRANT ALL ON mabase.* TO 'bert'@'localhost'; mysql> exit; $ mysql -u bert -p (saisir le passe) mysql> USE mabase; mysql> SHOW TABLES; mysql> SELECT * FROM matable; mysql> exit Bye
PHPMyAdmin
Télécharger et extraire phpMyAdmin 5.1.1et tester http://127.0.0.1/phpMyAdmin Dans config.inc.php mettre
$cfg['blowfish_secret'] = 'qtdRoGmbc9{8IZr323xYcSN]0s)r$9b_JUnb{~Xz';Il se plaint
Composer detected issues in your platform: Your Composer dependencies require the following PHP extensions to be installed: xml
$ sudo apt install php-xmlIl se plaint
Wrong permissions on configuration file, should not be world writable!Donc
$ cd /repertoire/publication/PHPMyAdmin $ gedit config.inc.php ajouter $cfg['CheckConfigurationPermissions'] = false;