nginxÔõÑùÉèÖÃphp
ÉèÖà nginx ÔËÐÐ php µÄ°ì·¨°üÀ¨£º×°Öà php¡¢×°Öà nginx¡¢±à¼ nginx Ö÷ÉèÖÃÎļþÌí¼Ó php ÉèÖᢽ¨Éè php Îļþ¡¢ÖØÆô nginx¡¢²âÊÔ php£¬Àֳɺó»áÏÔʾ “php is working!” ÐÂÎÅ¡£
ÔõÑùÉèÖÃ Nginx ÒÔÔËÐÐ PHP
°ì·¨ 1£º×°Öà PHP
ÔÚÄãµÄЧÀÍÆ÷ÉÏ×°Öà PHP£¬ÏÂÁîÈçÏ£º
sudo apt-get install php7.4-fpm
µÇ¼ºó¸´ÖÆ
°ì·¨ 2£º×°Öà Nginx
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
ÈôÊÇÉÐδװÖà Nginx£¬ÇëʹÓÃÒÔÏÂÏÂÁ
sudo apt-get install nginx
µÇ¼ºó¸´ÖÆ
°ì·¨ 3£ºÉèÖà Nginx
±à¼ Nginx µÄÖ÷ÉèÖÃÎļþ /etc/nginx/nginx.conf£¬Ìí¼ÓÒÔÏÂÉèÖÿ飺
server { listen 80; server_name example.com; root /var/www/html; location ~ \.php$ { fastcgi_pass unix:/run/php/php7.4-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
µÇ¼ºó¸´ÖÆ
°ì·¨ 4£º½¨Éè PHP Îļþ
ÔÚ Nginx µÄ¸ùĿ¼ (/var/www/html) ÖУ¬½¨ÉèÒ»¸ö PHP Îļþ£¬ÀýÈç index.php£º
<?php echo "PHP is working!"; ?>
µÇ¼ºó¸´ÖÆ
°ì·¨ 5£ºÖØÆô Nginx
ÖØÆô Nginx ÒÔÓ¦Óøü¸Ä£º
sudo systemctl restart nginx
µÇ¼ºó¸´ÖÆ
°ì·¨ 6£º²âÊÔ PHP
»á¼ûÄãµÄÍøÕ¾£¨http://example.com£©£¬ÄãÓ¦¸Ã¿´µ½ “PHP is working!” ÐÂÎÅ£¬Åú×¢ PHP ÒÑÀÖ³ÉÓë Nginx ¼¯³É¡£
ÒÔÉϾÍÊÇnginxÔõÑùÉèÖÃphpµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡