{"id":63583,"date":"2025-04-29T09:44:25","date_gmt":"2025-04-29T01:44:25","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63583\/"},"modified":"2025-04-29T09:44:25","modified_gmt":"2025-04-29T01:44:25","slug":"nginx%e6%80%8e%e4%b9%88%e9%85%8d%e7%bd%aephp-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63583\/","title":{"rendered":"nginx\u600e\u4e48\u914d\u7f6ephp"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u5728 nginx \u4e2d\u914d\u7f6e php\uff1f\u5b89\u88c5 php\u914d\u7f6e nginx\uff0c\u5305\u62ec\u8bbe\u7f6e php \u811a\u672c\u8def\u5f84\u548c php-fpm \u5957\u63a5\u5b57\u4f4d\u7f6e\u542f\u7528\u5e76\u6d4b\u8bd5\u914d\u7f6e\uff0c\u786e\u4fdd php \u8f93\u51fa\u6b63\u5e38\u663e\u793a\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/27\/2024052721541833652.jpg\" class=\"aligncenter\" title=\"nginx\u600e\u4e48\u914d\u7f6ephp\u63d2\u56fe\" alt=\"nginx\u600e\u4e48\u914d\u7f6ephp\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Nginx \u4e2d\u914d\u7f6e PHP<\/strong><\/p>\n<p><strong>\u7b80\u4ecb\uff1a<\/strong><\/p>\n<p>Nginx \u662f\u4e00\u4e2a\u6d41\u884c\u7684 Web \u670d\u52a1\u5668\uff0c\u800c PHP \u662f\u4e00\u79cd\u670d\u52a1\u5668\u7aef\u7684\u811a\u672c\u8bed\u8a00\u3002\u4e3a\u4e86\u4f7f\u7528 PHP \u7f16\u5199\u52a8\u6001 Web \u5e94\u7528\u7a0b\u5e8f\uff0c\u9700\u8981\u5728 Nginx \u4e2d\u914d\u7f6e\u5b83\u3002<\/p>\n<p><strong>\u6b65\u9aa4\uff1a<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p><strong>1. \u5b89\u88c5 PHP<\/strong><\/p>\n<ul>\n<li>\u5728\u670d\u52a1\u5668\u4e0a\u5b89\u88c5 PHP\u3002<\/li>\n<li>\u5728 Ubuntu\/Debian \u4e0a\uff1asudo apt-get install php<\/li>\n<li>\u5728 CentOS\/Red Hat \u4e0a\uff1asudo yum install php<\/li>\n<\/ul>\n<p><strong>2. \u914d\u7f6e Nginx<\/strong><\/p>\n<ul>\n<li>\u6253\u5f00 Nginx \u914d\u7f6e\u6587\u4ef6 \/etc\/\/sites-available\/default\u3002<\/li>\n<li>\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u6bb5\uff1a<\/li>\n<\/ul>\n<pre>location ~ .php$ {\n    root \/var\/www\/html;\n    fastcgi_pass unix:\/var\/run\/php\/php-fpm.sock;\n    fastcgi_index index.php;\n    include fastcgi_params;\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u5c06 \/var\/www\/html \u66ff\u6362\u4e3a PHP \u811a\u672c\u6240\u5728\u7684\u76ee\u5f55\u3002<\/li>\n<li>\u5c06 \/var\/run\/php\/php-fpm.sock \u66ff\u6362\u4e3a PHP-FPM \u5957\u63a5\u5b57\u7684\u4f4d\u7f6e\u3002<\/li>\n<\/ul>\n<p><strong>3. \u542f\u7528\u5e76\u6d4b\u8bd5\u914d\u7f6e<\/strong><\/p>\n<ul>\n<li>\u91cd\u65b0\u52a0\u8f7d Nginx\uff1asudo nginx -s reload\u3002<\/li>\n<li>\u521b\u5efa\u4e00\u4e2a\u7b80\u5355\u7684 PHP \u6587\u4ef6\uff08\u4f8b\u5982 index.php\uff09\u5e76\u5c06\u5176\u653e\u5728 \/var\/www\/html \u76ee\u5f55\u4e2d\u3002<\/li>\n<li>\u8bbf\u95ee\u5305\u542b PHP \u4ee3\u7801\u7684 Web \u9875\u9762\u3002\u5982\u679c\u770b\u5230 PHP \u8f93\u51fa\uff0c\u5219\u914d\u7f6e\u6210\u529f\u3002<\/li>\n<\/ul>\n<p><strong>\u5176\u4ed6\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li>\u786e\u4fdd PHP-FPM \u670d\u52a1\u6b63\u5728\u8fd0\u884c\uff1asudo systemctl status php-fpm\u3002<\/li>\n<li>\u5982\u679c\u9047\u5230\u9519\u8bef\uff0c\u8bf7\u68c0\u67e5 Nginx \u548c PHP-FPM \u65e5\u5fd7\u3002<\/li>\n<li>\u8c03\u6574 fastcgi_pass \u503c\u4ee5\u5339\u914d PHP-FPM \u5957\u63a5\u5b57\u7684\u4f4d\u7f6e\u3002<\/li>\n<li>\u8003\u8651\u4f7f\u7528 Nginx \u6a21\u5757\u6765\u589e\u5f3a PHP \u652f\u6301\uff0c\u4f8b\u5982 ngx_fastcgi_module\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u914d\u7f6ephp\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5728 nginx \u4e2d\u914d\u7f6e php\uff1f\u5b89\u88c5 php\u914d\u7f6e nginx\uff0c\u5305\u62ec\u8bbe\u7f6e php \u811a\u672c\u8def\u5f84\u548c php-fpm \u5957\u63a5\u5b57\u4f4d\u7f6e\u542f\u7528\u5e76\u6d4b\u8bd5\u914d\u7f6e\uff0c\u786e\u4fdd php \u8f93\u51fa\u6b63\u5e38\u663e\u793a \u5982\u4f55\u5728 Nginx \u4e2d\u914d\u7f6e PHP \u7b80\u4ecb\uff1a Nginx \u662f\u4e00\u4e2a\u6d41\u884c\u7684 Web \u670d\u52a1\u5668\uff0c\u800c PHP \u662f\u4e00\u79cd\u670d\u52a1\u5668\u7aef\u7684\u811a\u672c\u8bed\u8a00\u3002\u4e3a\u4e86\u4f7f\u7528 PHP \u7f16\u5199\u52a8\u6001 Web \u5e94\u7528\u7a0b\u5e8f\uff0c\u9700\u8981\u5728 Nginx \u4e2d\u914d\u7f6e\u5b83\u3002 \u6b65\u9aa4\uff1a \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b 1. \u5b89\u88c5 PHP \u5728\u670d\u52a1\u5668\u4e0a\u5b89\u88c5 PHP\u3002 \u5728 Ubuntu\/Debian \u4e0a\uff1asudo apt-get install php \u5728 CentOS\/Red Hat \u4e0a\uff1asudo yum install php 2. \u914d\u7f6e Nginx \u6253\u5f00 Nginx \u914d\u7f6e\u6587\u4ef6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63583","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63583","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=63583"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63583\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63583"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63583"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63583"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}