{"id":27488,"date":"2024-11-24T14:57:41","date_gmt":"2024-11-24T06:57:41","guid":{"rendered":"https:\/\/fwq.ai\/blog\/27488\/"},"modified":"2024-11-24T14:57:41","modified_gmt":"2024-11-24T06:57:41","slug":"%e5%a6%82%e4%bd%95%e6%90%ad%e5%bb%banginx-php","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/27488\/","title":{"rendered":"\u5982\u4f55\u642d\u5efanginx php"},"content":{"rendered":"<blockquote><p>\n  \u642d\u5efa nginx + php \u670d\u52a1\u5668\u5171\u9700\u8981 6 \u4e2a\u6b65\u9aa4\uff1a1. \u5b89\u88c5 nginx\uff1b2. \u5b89\u88c5 php\uff1b3. \u5b89\u88c5 php-fpm nginx \u6a21\u5757\uff1b4. \u914d\u7f6e nginx\uff0c\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\u5e76\u8bbe\u7f6e\u76d1\u542c\u7aef\u53e3\u3001\u670d\u52a1\u5668\u540d\u79f0\u3001\u6839\u76ee\u5f55\u3001\u6587\u4ef6\u67e5\u627e\u987a\u5e8f\u7b49\uff1b5. \u914d\u7f6e php\uff0c\u8c03\u6574 php-fpm \u6c60\u8bbe\u7f6e\uff0c\u5305\u62ec\u76d1\u542c\u7aef\u53e3\u3001\u7528\u6237\u3001\u7ec4\u3001\u8fdb\u7a0b\u7ba1\u7406\u7b49\uff1b6. \u542f\u7528\u5e76\u91cd\u542f\u670d\u52a1\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202411\/11\/2024111100094691142.jpg\" class=\"aligncenter\" title=\"\u5982\u4f55\u642d\u5efanginx php\u63d2\u56fe\" alt=\"\u5982\u4f55\u642d\u5efanginx php\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u642d\u5efa Nginx + PHP<\/strong><\/p>\n<p>\u642d\u5efa Nginx + PHP \u670d\u52a1\u5668\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5b89\u88c5 Nginx<\/strong><\/p>\n<pre>sudo apt-get update\nsudo apt-get install nginx<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5b89\u88c5 PHP<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>sudo apt-get install php-fpm<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u5b89\u88c5 PHP-FPM Nginx \u6a21\u5757<\/strong><\/p>\n<pre>sudo apt-get install php-fpm php-fpm nginx-module-php<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u914d\u7f6e Nginx<\/strong><\/p>\n<p>\u5728 \/etc\/\/sites-avlable\/ \u4e0b\u521b\u5efa\u65b0\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u4f8b\u5982 mysite.conf\uff1a<\/p>\n<pre>server {\n    listen 80;\n    server_name mysite.com;\n    root \/var\/www\/mysite;\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php$request_uri;\n    }\n\n    location ~ .php$ {\n        fastcgi_pass unix:\/run\/php\/php7.4-fpm.sock;\n        fastcgi_index index.php;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n    }\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u914d\u7f6e PHP<\/strong><\/p>\n<p>\u5728 \/etc\/php\/7.4\/fpm\/pool.d\/www.conf \u4e2d\u8c03\u6574 PHP-FPM \u6c60\u8bbe\u7f6e\uff1a<\/p>\n<pre>listen = \/run\/php\/php7.4-fpm.sock\nlisten.owner = www-data\nlisten.group = www-data\nuser = www-data\ngroup = www-data\npm = dynamic\npm.max_children = 5\npm.start_servers = 2\npm.min_spare_servers = 1\npm.max_spare_servers = 3<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u542f\u7528\u5e76\u91cd\u542f\u670d\u52a1<\/strong><\/p>\n<pre>sudo ln -s \/etc\/nginx\/sites-available\/mysite.conf \/etc\/nginx\/sites-enabled\/\nsudo service nginx restart\nsudo service php7.4-fpm restart<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u6b65\u9aa4\u5c06\u6210\u529f\u8bbe\u7f6e Nginx + PHP \u670d\u52a1\u5668\uff0c\u60a8\u73b0\u5728\u53ef\u4ee5\u5728 \/var\/www\/mysite \u76ee\u5f55\u4e2d\u521b\u5efa\u548c\u4e0a\u4f20 PHP \u6587\u4ef6\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u642d\u5efa php\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u642d\u5efa nginx + php \u670d\u52a1\u5668\u5171\u9700\u8981 6 \u4e2a\u6b65\u9aa4\uff1a1. \u5b89\u88c5 nginx\uff1b2. \u5b89\u88c5 php\uff1b3. \u5b89\u88c5 php-fpm nginx \u6a21\u5757\uff1b4. \u914d\u7f6e nginx\uff0c\u521b\u5efa\u914d\u7f6e\u6587\u4ef6\u5e76\u8bbe\u7f6e\u76d1\u542c\u7aef\u53e3\u3001\u670d\u52a1\u5668\u540d\u79f0\u3001\u6839\u76ee\u5f55\u3001\u6587\u4ef6\u67e5\u627e\u987a\u5e8f\u7b49\uff1b5. \u914d\u7f6e php\uff0c\u8c03\u6574 php-fpm \u6c60\u8bbe\u7f6e\uff0c\u5305\u62ec\u76d1\u542c\u7aef\u53e3\u3001\u7528\u6237\u3001\u7ec4\u3001\u8fdb\u7a0b\u7ba1\u7406\u7b49\uff1b6. \u542f\u7528\u5e76\u91cd\u542f\u670d\u52a1\u3002 \u5982\u4f55\u642d\u5efa Nginx + PHP \u642d\u5efa Nginx + PHP \u670d\u52a1\u5668\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u5b89\u88c5 Nginx sudo apt-get update sudo apt-get install nginx \u767b\u5f55\u540e\u590d\u5236 2. \u5b89\u88c5 PHP \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b sudo apt-get install php-fpm \u767b\u5f55\u540e\u590d\u5236 3. \u5b89\u88c5 PHP-FPM Nginx [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-27488","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27488","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=27488"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/27488\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=27488"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=27488"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=27488"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}