nginxÔõôÉèÖÃphp
ÔõÑùÔÚ nginx ÖÐÉèÖà php£¿×°Öà phpÉèÖà nginx£¬°üÀ¨ÉèÖà php ¾ç±¾Â·¾¶ºÍ php-fpm Ì×½Ó×ÖλÖÃÆôÓò¢²âÊÔÉèÖã¬È·±£ php Êä³öÕý³£ÏÔʾ
ÔõÑùÔÚ Nginx ÖÐÉèÖÃ PHP
¼ò½é£º
Nginx ÊÇÒ»¸öÊ¢ÐÐµÄ Web ЧÀÍÆ÷£¬¶ø PHP ÊÇÒ»ÖÖЧÀÍÆ÷¶ËµÄ¾ç±¾ÓïÑÔ¡£ÎªÁËʹÓà PHP ±àд¶¯Ì¬ Web Ó¦ÓóÌÐò£¬ÐèÒªÔÚ Nginx ÖÐÉèÖÃËü¡£
°ì·¨£º
Á¬Ã¦Ñ§Ï°¡°PHPÃâ·ÑѧϰÌõ¼Ç£¨ÉîÈ룩¡±£»
1. ×°ÖÃ PHP
ÔÚЧÀÍÆ÷ÉÏ×°Öà PHP¡£
ÔÚ Ubuntu/Debian ÉÏ£ºsudo apt-get install php
ÔÚ CentOS/Red Hat ÉÏ£ºsudo yum install php
2. ÉèÖÃ Nginx
·¿ª Nginx ÉèÖÃÎļþ /etc/nginx/sites-available/default¡£
Ìí¼ÓÒÔÏ´úÂë¶Î£º
location ~ \.php$ { root /var/www/html; fastcgi_pass unix:/var/run/php/php-fpm.sock; fastcgi_index index.php; include fastcgi_params; }
µÇ¼ºó¸´ÖÆ
½« /var/www/html Ì滻Ϊ PHP ¾ç±¾ËùÔÚµÄĿ¼¡£
½« /var/run/php/php-fpm.sock Ì滻Ϊ PHP-FPM Ì×½Ó×ÖµÄλÖá£
3. ÆôÓò¢²âÊÔÉèÖÃ
ÖØмÓÔØ Nginx£ºsudo nginx -s reload¡£
½¨ÉèÒ»¸ö¼òÆ PHP Îļþ£¨ÀýÈç index.php£©²¢½«Æä·ÅÔÚ /var/www/html Ŀ¼ÖС£
»á¼û°üÀ¨ PHP ´úÂëµÄ Web Ò³Ãæ¡£ÈôÊÇ¿´µ½ PHP Êä³ö£¬ÔòÉèÖÃÀֳɡ£
ÆäËû×¢ÖØÊÂÏ
È·±£ PHP-FPM ЧÀÍÕýÔÚÔËÐУºsudo systemctl status php-fpm¡£
ÈôÊÇÓöµ½¹ýʧ£¬Çë¼ì²é Nginx ºÍ PHP-FPM ÈÕÖ¾¡£
µ÷½â fastcgi_pass ÖµÒÔÆ¥Åä PHP-FPM Ì×½Ó×ÖµÄλÖá£
˼Á¿Ê¹Óà Nginx Ä£¿éÀ´ÔöÇ¿ PHP Ö§³Ö£¬ÀýÈç ngx_fastcgi_module¡£
ÒÔÉϾÍÊÇnginxÔõôÉèÖÃphpµÄÏêϸÄÚÈÝ£¬¸ü¶àÇë¹Ø×¢±¾ÍøÄÚÆäËüÏà¹ØÎÄÕ£¡