====== Installation nginx + php + cgi (Debian) ======
[[./|Retour]]
----
[[https://www.cyberciti.biz/faq/how-to-install-fcgiwrap-for-nginx-on-ubuntu-20-04/|référence cyberciti.biz ]]
sudo apt-get install nginx php8.4-fpm php8.4-gd php8.4-mysql php8.4-curl php8.4-mbstring php8.4-xml php8.4-sqlite3
sudo nginx -v
sudo systemctl status nginx
sudo apt install fcgiwrap
sudo nano /etc/nginx/fcgiwrap.conf
*
location /cgi-bin/ {
# Disable gzip (it makes scripts feel slower since they have to complete
# before getting gzipped)
gzip off;
# Set the root to /usr/lib (inside this location this means that we are
# giving access to the files under /usr/lib/cgi-bin)
root /usr/lib;
# Fastcgi socket
fastcgi_pass unix:/var/run/fcgiwrap.socket;
# Fastcgi parameters, include the standard ones
include /etc/nginx/fastcgi_params;
# Adjust non standard parameters (SCRIPT_FILENAME)
fastcgi_param SCRIPT_FILENAME /usr/lib$fastcgi_script_name;
}
sudo systemctl enable fcgiwrap
sudo systemctl start fcgiwrap
sudo systemctl status fcgiwrap
sudo nano /etc/nginx/sites-enabled/default
# ajouter dans le fichier du site où un appel à un cgi est souhaité
# exemple :
*
## Trun on /cgi-bin/ support to run CGI apps ##
include /etc/nginx/fcgiwrap.conf;
sudo nginx -t
sudo nginx -s reload
sudo mkdir -vp /usr/lib/cgi-bin
sudo nano /usr/lib/cgi-bin/hello.cgi
*
#!/usr/bin/env bash
# ___________________________________________________________________
#
# fichier exemple : /usr/lib/cgi-bin/hello.cgi
# ___________________________________________________________________
echo "\
Content-type: text/html
Premier script CGI
Premier script CGI !
nom du serveur : $(hostname -f)
nous somme le : $(date +"%A %d %B %Y %R:%S")
"
sudo chmod +x -v /usr/lib/cgi-bin/hello.cgi
# Test dans firefox
# http://localhost/cgi-bin/hello.cgi