nginxÔõôÆô¶¯phpЧÀÍÆ÷
nginx ͨ¹ý fastcgi »ò php-fpm Æô¶¯ php ЧÀÍÆ÷£¬Ïêϸ°ì·¨°üÀ¨£º×°Öà fastcgi Ä£¿é²¢ÉèÖà nginx ÉèÖÃÎļþ£¬Ö¸¶¨ php-fpm Ì×½Ó×ÖÎļþµÄλÖá£×°Öò¢ÉèÖà php-fpm£¬ÉèÖüàÌýÌ×½Ó×ÖÎļþºÍÆô¶¯ php-fpm¡£ÔÚ nginx ÉèÖÃÎļþÖÐÌí¼ÓÊðÀí pass ÉèÖ㬽« php ÇëÇóת·¢¸ø php-fpm ЧÀÍÆ÷£¨Í¨³£ÊÇ 127.0.0.1:9000£©¡£Æô¶¯ nginx£¬²âÊÔ»á¼û php ÎļþÒÔÑéÖ¤ php ЧÀÍÆ÷ÊÇ·ñÒÑÆô¶¯¡£
Nginx ÔõÑùÆô¶¯ PHP ЧÀÍÆ÷
ÒªÁ죺
Nginx ͨ¹ý FastCGI »ò PHP-FPM À´Æô¶¯ PHP ЧÀÍÆ÷£¬Ïêϸ°ì·¨ÈçÏ£º
FastCGI
×°Öà FastCGI Ä£¿é£ºsudo apt-get install libnginx-mod-fastcgi
ÉèÖà FastCGI Ä£¿é£ºÔÚ Nginx ÉèÖÃÎļþÖУ¬Ìí¼ÓÈçÏ´úÂ룺
location ~ \.php$ { fastcgi_pass unix:/var/run/php/php7.4-fpm.sock; fastcgi_index index.php; include fastcgi_params; }
µÇ¼ºó¸´ÖÆ
×¢ÖØ£¬½«Â·¾¶ /var/run/php/php7.4-fpm.sock Ì滻Ϊ PHP-FPM Ì×½Ó×ÖÎļþµÄλÖá£
PHP-FPM
×°Öà PHP-FPM£ºsudo apt-get install php-fpm
ÉèÖà PHP-FPM£º±à¼ /etc/php/7.4/fpm/pool.d/www.conf Îļþ£¬²¢ÉèÖÃÒÔÏÂÑ¡Ï
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
listen = /run/php/php7.4-fpm.sock
µÇ¼ºó¸´ÖÆ
½¨ÉèÌ×½Ó×ÖÎļþ£ºsudo mkdir /run/php/ && sudo chown www-data:www-data /run/php
Æô¶¯ PHP-FPM£ºsudo systemctl start php7.4-fpm
ÉèÖà Nginx£ºÔÚ Nginx ÉèÖÃÎļþÖУ¬Ìí¼ÓÈçÏ´úÂ룺
location ~ \.php$ { proxy_pass http://127.0.0.1:9000; }
µÇ¼ºó¸´ÖÆ
Æô¶¯ Nginx
ÔÚÉèÖÃÍê FastCGI »ò PHP-FPM ºó£¬Æô¶¯ Nginx£ºsudo systemctl start nginx¡£
²âÊÔ
»á¼ûÒ»¸ö PHP Îļþ£¨ÀýÈç /var/www/html/index.php£©£¬ÒÔ²âÊÔ PHP ЧÀÍÆ÷ÊÇ·ñÒÑÆô¶¯¡£ÈôÊÇ PHP ¾ç±¾±»×¼È·Ö´ÐУ¬Ôò»áÏÔʾÆäÊä³ö¡£
ÒÔÉϾÍÊÇnginxÔõôÆô¶¯phpЧÀÍÆ÷µÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡