{"id":63556,"date":"2025-04-29T14:11:13","date_gmt":"2025-04-29T06:11:13","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63556\/"},"modified":"2025-04-29T14:11:13","modified_gmt":"2025-04-29T06:11:13","slug":"nginx-php%e9%a1%b9%e7%9b%ae%e6%80%8e%e4%b9%88%e9%83%a8%e7%bd%b2-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63556\/","title":{"rendered":"nginx\u00a0php\u9879\u76ee\u600e\u4e48\u90e8\u7f72"},"content":{"rendered":"<blockquote><p>\n  \u90e8\u7f72 nginx php \u9879\u76ee\u6b65\u9aa4\uff1a\u5b89\u88c5 nginx\u3001php\u3001mysql\uff08\u53ef\u9009\uff09\u3002\u521b\u5efa nginx \u914d\u7f6e\u6587\u4ef6\uff0c\u6307\u5b9a\u76d1\u542c\u7aef\u53e3\u3001\u670d\u52a1\u5668\u540d\u79f0\u3001\u9879\u76ee\u6839\u76ee\u5f55\u548c php \u5904\u7406\u7a0b\u5e8f\u3002\u521b\u5efa fastcgi \u811a\u672c\uff0c\u914d\u7f6e php-fpm \u5904\u7406 php\u3002\u542f\u7528\u914d\u7f6e\u6587\u4ef6\uff0c\u521b\u5efa\u7b26\u53f7\u94fe\u63a5\u3002\u91cd\u542f nginx\u3002\u5b89\u88c5 php-fpm\uff0c\u914d\u7f6e cgi.fix_pathinfo\u3002\u91cd\u542f php-fpm\u3002\u5b89\u88c5 mysql\uff08\u53ef\u9009\uff09\uff0c\u914d\u7f6e\u5e76\u8bbe\u7f6e\u7528\u6237\u548c\u5bc6\u7801\u3002\u6d4b\u8bd5\u90e8\u7f72\uff0c\u8bbf\u95ee\u57df\u540d\u5e76\u9a8c\u8bc1 php\/mysql \u529f\u80fd\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/27\/2024052720182661504.jpg\" class=\"aligncenter\" title=\"nginx\u00a0php\u9879\u76ee\u600e\u4e48\u90e8\u7f72\u63d2\u56fe\" alt=\"nginx\u00a0php\u9879\u76ee\u600e\u4e48\u90e8\u7f72\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u90e8\u7f72 Nginx PHP \u9879\u76ee<\/strong><\/p>\n<p><strong>\u6b65\u9aa4<\/strong><\/p>\n<p><strong>1. \u5b89\u88c5\u6240\u9700\u7684\u8f6f\u4ef6<\/strong><\/p>\n<ul>\n<li>Nginx<\/li>\n<li>PHP<\/li>\n<li>MySQL\uff08\u53ef\u9009\uff09<\/li>\n<\/ul>\n<p><strong>2. \u521b\u5efa Nginx \u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<p>\u5728 \/etc\/\/sites-available\/ \u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0c\u4f8b\u5982 my_site.conf\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>server {\n    listen 80;\n    server_name my_site.com;\n\n    root \/path\/to\/my_site;\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php;\n    }\n\n    location ~ .php$ {\n        include snippets\/fastcgi-php.conf;\n        fastcgi_pass 127.0.0.1:9000;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u66ff\u6362 my_site.com \u4e3a\u4f60\u7684\u57df\u540d\u3002<\/li>\n<li>\u66ff\u6362 \/path\/to\/my_site \u4e3a\u9879\u76ee\u6839\u76ee\u5f55\u3002<\/li>\n<\/ul>\n<p><strong>3. \u521b\u5efa FastCGI \u811a\u672c<\/strong><\/p>\n<p>\u5728 \/etc\/nginx\/snippets\/ \u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0c\u4f8b\u5982 fastcgi-php.conf\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a<\/p>\n<pre>fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\nfastcgi_param SCRIPT_NAME $fastcgi_script_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u542f\u7528\u914d\u7f6e\u6587\u4ef6<\/strong><\/p>\n<p>\u901a\u8fc7\u521b\u5efa\u7b26\u53f7\u94fe\u63a5\u5c06\u914d\u7f6e\u6587\u4ef6\u94fe\u63a5\u5230 \/etc\/nginx\/sites-enabled\/ \u76ee\u5f55\uff1a<\/p>\n<pre>ln -s \/etc\/nginx\/sites-available\/my_site.conf \/etc\/nginx\/sites-enabled\/my_site.conf<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u91cd\u542f Nginx<\/strong><\/p>\n<p>\u91cd\u65b0\u52a0\u8f7d Nginx \u4ee5\u5e94\u7528\u66f4\u6539\uff1a<\/p>\n<pre>sudo systemctl restart nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u8bbe\u7f6e PHP<\/strong><\/p>\n<ul>\n<li>\u5b89\u88c5 PHP-FPM\uff08FastCGI \u8fdb\u7a0b\u7ba1\u7406\u5668\uff09\uff1a<\/li>\n<\/ul>\n<pre>sudo apt-get install php7.4-fpm<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u4fee\u6539 \/etc\/php\/7.4\/fpm\/php.ini \u6587\u4ef6\uff0c\u914d\u7f6e\u5982\u4e0b\uff1a<\/li>\n<\/ul>\n<pre>cgi.fix_pathinfo = 0<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u91cd\u542f PHP-FPM\uff1a<\/li>\n<\/ul>\n<pre>sudo systemctl restart php7.4-fpm<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>7. \u5b89\u88c5 MySQL\uff08\u53ef\u9009\uff09<\/strong><\/p>\n<ul>\n<li>\u5b89\u88c5 MySQL\uff1a<\/li>\n<\/ul>\n<pre>sudo apt-get install mysql-server<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li>\u914d\u7f6e MySQL \u5e76\u8bbe\u7f6e\u7528\u6237\u548c\u5bc6\u7801\u3002<\/li>\n<\/ul>\n<p><strong>8. \u6d4b\u8bd5\u90e8\u7f72<\/strong><\/p>\n<ul>\n<li>\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee\u4f60\u7684\u57df\u540d\uff08my_site.com\uff09\u3002<\/li>\n<li>\u786e\u4fdd PHP \u9875\u9762\u6b63\u5e38\u5de5\u4f5c\u3002<\/li>\n<li>\u9a8c\u8bc1 MySQL \u8fde\u63a5\uff08\u5982\u679c\u5df2\u5b89\u88c5\uff09\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f&nbsp;php\u9879\u76ee\u600e\u4e48\u90e8\u7f72\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>\u90e8\u7f72 nginx php \u9879\u76ee\u6b65\u9aa4\uff1a\u5b89\u88c5 nginx\u3001php\u3001mysql\uff08\u53ef\u9009\uff09\u3002\u521b\u5efa nginx \u914d\u7f6e\u6587\u4ef6\uff0c\u6307\u5b9a\u76d1\u542c\u7aef\u53e3\u3001\u670d\u52a1\u5668\u540d\u79f0\u3001\u9879\u76ee\u6839\u76ee\u5f55\u548c php \u5904\u7406\u7a0b\u5e8f\u3002\u521b\u5efa fastcgi \u811a\u672c\uff0c\u914d\u7f6e php-fpm \u5904\u7406 php\u3002\u542f\u7528\u914d\u7f6e\u6587\u4ef6\uff0c\u521b\u5efa\u7b26\u53f7\u94fe\u63a5\u3002\u91cd\u542f nginx\u3002\u5b89\u88c5 php-fpm\uff0c\u914d\u7f6e cgi.fix_pathinfo\u3002\u91cd\u542f php-fpm\u3002\u5b89\u88c5 mysql\uff08\u53ef\u9009\uff09\uff0c\u914d\u7f6e\u5e76\u8bbe\u7f6e\u7528\u6237\u548c\u5bc6\u7801\u3002\u6d4b\u8bd5\u90e8\u7f72\uff0c\u8bbf\u95ee\u57df\u540d\u5e76\u9a8c\u8bc1 php\/mysql \u529f\u80fd\u3002 \u5982\u4f55\u90e8\u7f72 Nginx PHP \u9879\u76ee \u6b65\u9aa4 1. \u5b89\u88c5\u6240\u9700\u7684\u8f6f\u4ef6 Nginx PHP MySQL\uff08\u53ef\u9009\uff09 2. \u521b\u5efa Nginx \u914d\u7f6e\u6587\u4ef6 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b \u5728 \/etc\/\/sites-available\/ \u76ee\u5f55\u4e0b\u521b\u5efa\u4e00\u4e2a\u65b0\u6587\u4ef6\uff0c\u4f8b\u5982 my_site.conf\uff0c\u5e76\u6dfb\u52a0\u4ee5\u4e0b\u5185\u5bb9\uff1a server { listen 80; server_name my_site.com; root \/path\/to\/my_site; location \/ { try_files $uri $uri\/ \/index.php; [&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-63556","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63556","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=63556"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63556\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63556"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63556"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63556"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}