{"id":15892,"date":"2024-11-18T14:39:22","date_gmt":"2024-11-18T06:39:22","guid":{"rendered":"https:\/\/fwq.ai\/blog\/15892\/"},"modified":"2024-11-18T14:39:22","modified_gmt":"2024-11-18T06:39:22","slug":"%e5%a6%82%e4%bd%95%e5%9c%a8linux%e4%b8%8a%e9%83%a8%e7%bd%b2web%e5%ba%94%e7%94%a8%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/15892\/","title":{"rendered":"\u5982\u4f55\u5728Linux\u4e0a\u90e8\u7f72Web\u5e94\u7528\u7a0b\u5e8f"},"content":{"rendered":"<p>\u5982\u4f55\u5728\u4e0a\u90e8\u7f72web\u5e94\u7528\u7a0b\u5e8f<\/p>\n<p>\u968f\u7740\u4e92\u8054\u7f51\u7684\u53d1\u5c55\uff0cWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u548c\u90e8\u7f72\u53d8\u5f97\u8d8a\u6765\u8d8a\u6d41\u884c\u3002\u800cLinux\u662fWeb\u670d\u52a1\u5668\u7684\u9996\u9009\u64cd\u4f5c\u7cfb\u7edf\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728linux\u4e0a\u90e8\u7f72web\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u9644\u4e0a\u4e00\u4e9b\u5e38\u89c1\u7684\u4ee3\u7801\u793a\u4f8b\u3002<\/p>\n<ol>\n<li>\u5b89\u88c5\u5fc5\u8981\u7684\u8f6f\u4ef6<br \/>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5\u4e00\u4e9b\u5fc5\u8981\u7684\u8f6f\u4ef6\uff0c\u5305\u62ecWeb\u670d\u52a1\u5668\uff08\u5982Apache\u3001Nginx\u7b49\uff09\u3001PHP\u89e3\u91ca\u5668\uff08\u5982\u679c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u4e86PHP\uff09\u4ee5\u53ca\u6570\u636e\u5e93\u670d\u52a1\u5668\uff08\u5982MySQL\u3001PostgreSQL\u7b49\uff09\u3002\u4ee5Ubuntu\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a<\/li>\n<\/ol>\n<pre>sudo apt-get update\nsudo apt-get install apache2 php mysql-server<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u8bbe\u7f6eWeb\u670d\u52a1\u5668<br \/>\u5b89\u88c5\u5b8cWeb\u670d\u52a1\u5668\u540e\uff0c\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u57fa\u672c\u7684\u914d\u7f6e\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u4ee5\u5c06\u7f51\u7ad9\u6587\u4ef6\u653e\u5728\/var\/www\/html\u76ee\u5f55\u4e0b\uff0c\u5e76\u914d\u7f6e\u865a\u62df\u4e3b\u673a\uff08\u5982\u679c\u9700\u8981\uff09\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u90e8\u7f72\u9759\u6001\u7f51\u7ad9\u7684\u793a\u4f8bApache\u914d\u7f6e\uff1a<\/li>\n<\/ol>\n<pre>&lt;virtualhost&gt;\n  ServerName example.com\n  ServerAlias www.example.com\n  DocumentRoot \/var\/www\/html\n\n  &lt;directory&gt;\n    Options Indexes FollowSymLinks\n    AllowOverride All\n    Require all granted\n  &lt;\/directory&gt;\n\n  ErrorLog ${APACHE_LOG_DIR}\/error.log\n  CustomLog ${APACHE_LOG_DIR}\/access.log combined\n&lt;\/virtualhost&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u914d\u7f6e\u6570\u636e\u5e93<br \/>\u5982\u679c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u4f7f\u7528\u6570\u636e\u5e93\uff0c\u9700\u8981\u8fdb\u884c\u76f8\u5e94\u7684\u914d\u7f6e\u3002\u4ee5MySQL\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u5f55\u5230MySQL\u670d\u52a1\u5668\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93\u548c\u7528\u6237\uff1a<\/li>\n<\/ol>\n<pre>sudo mysql -u root -p\nCREATE DATABASE myapp;\nCREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';\nGRANT ALL PRIVILEGES ON myapp.* TO 'myuser'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u90e8\u7f72\u5e94\u7528\u7a0b\u5e8f<br \/>\u73b0\u5728\uff0c\u4f60\u53ef\u4ee5\u5c06\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4e0a\u4f20\u5230\u670d\u52a1\u5668\uff0c\u5e76\u6839\u636e\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u914d\u7f6e\u3002\u4f8b\u5982\uff0c\u5982\u679c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u4e86WordPress\uff0c\u53ef\u4ee5\u4e0b\u8f7d\u6700\u65b0\u7684WordPress\u538b\u7f29\u5305\uff0c\u5e76\u5c06\u5176\u89e3\u538b\u5230\/var\/www\/html\u76ee\u5f55\u4e0b\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95eehttp:\/\/example.com\u6765\u8bbf\u95ee\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n<li>\u8bbe\u7f6e\u57df\u540d\u548cSSL\u8bc1\u4e66<br \/>\u5982\u679c\u4f60\u60f3\u4f7f\u7528\u81ea\u5b9a\u4e49\u57df\u540d\u548cSSL\u8bc1\u4e66\u6765\u8bbf\u95ee\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u989d\u5916\u7684\u914d\u7f6e\u3002\u9996\u5148\uff0c\u4f60\u9700\u8981\u5728DNS\u670d\u52a1\u5668\u4e0a\u8bbe\u7f6e\u4e00\u4e2aA\u8bb0\u5f55\uff0c\u5c06\u4f60\u7684\u57df\u540d\u6307\u5411\u670d\u52a1\u5668\u7684IP\u5730\u5740\u3002\u7136\u540e\uff0c\u53ef\u4ee5\u4f7f\u7528Let&#8217;s Encrypt\u7b49\u5de5\u5177\u6765\u83b7\u53d6\u5e76\u914d\u7f6eSSL\u8bc1\u4e66\u3002<\/li>\n<li>\u76d1\u63a7\u548c\u65e5\u5fd7<br \/>\u5bf9\u4e8e\u90e8\u7f72\u7684Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u76d1\u63a7\u548c\u65e5\u5fd7\u8bb0\u5f55\u662f\u975e\u5e38\u91cd\u8981\u7684\u3002\u4f60\u53ef\u4ee5\u4f7f\u7528\u5de5\u5177\u5982Monit\u3001New Relic\u7b49\u6765\u76d1\u63a7\u670d\u52a1\u5668\u7684\u6027\u80fd\u548c\u5e94\u7528\u7a0b\u5e8f\u7684\u8fd0\u884c\u72b6\u6001\u3002\u6b64\u5916\uff0c\u4f60\u8fd8\u53ef\u4ee5\u914d\u7f6e\u65e5\u5fd7\u7cfb\u7edf\uff0c\u4ee5\u4fbf\u8ddf\u8e2a\u548c\u5206\u6790\u5e94\u7528\u7a0b\u5e8f\u7684\u65e5\u5fd7\u3002<\/li>\n<li>\u81ea\u52a8\u5316\u90e8\u7f72<br \/>\u6700\u540e\uff0c\u5bf9\u4e8e\u4e00\u4e2a\u590d\u6742\u7684Web\u5e94\u7528\u7a0b\u5e8f\uff0c\u624b\u52a8\u90e8\u7f72\u53ef\u80fd\u4f1a\u53d8\u5f97\u7e41\u7410\u548c\u5bb9\u6613\u51fa\u9519\u3002\u56e0\u6b64\uff0c\u5efa\u8bae\u4f7f\u7528\u81ea\u52a8\u5316\u90e8\u7f72\u5de5\u5177\uff08\u5982Ansible\u3001Docker\u3001Kubernetes\u7b49\uff09\u6765\u7b80\u5316\u90e8\u7f72\u8fc7\u7a0b\uff0c\u5e76\u786e\u4fdd\u4e00\u81f4\u7684\u73af\u5883\u914d\u7f6e\u548c\u90e8\u7f72\u3002<\/li>\n<\/ol>\n<p>\u603b\u7ed3\u8d77\u6765\uff0c\u90e8\u7f72Web\u5e94\u7528\u7a0b\u5e8f\u5728Linux\u4e0a\u662f\u4e00\u9879\u76f8\u5bf9\u7b80\u5355\u7684\u4efb\u52a1\uff0c\u4f46\u9700\u8981\u4e00\u4e9b\u57fa\u672c\u7684\u914d\u7f6e\u548c\u5b89\u88c5\u3002\u901a\u8fc7\u6309\u7167\u4e0a\u8ff0\u6b65\u9aa4\u8fdb\u884c\u64cd\u4f5c\uff0c\u4f60\u5c06\u80fd\u591f\u8f7b\u677e\u5730\u5728Linux\u4e0a\u90e8\u7f72\u4f60\u7684Web\u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5728Linux\u4e0a\u90e8\u7f72Web\u5e94\u7528\u7a0b\u5e8f\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>\u5982\u4f55\u5728\u4e0a\u90e8\u7f72web\u5e94\u7528\u7a0b\u5e8f \u968f\u7740\u4e92\u8054\u7f51\u7684\u53d1\u5c55\uff0cWeb\u5e94\u7528\u7a0b\u5e8f\u7684\u5f00\u53d1\u548c\u90e8\u7f72\u53d8\u5f97\u8d8a\u6765\u8d8a\u6d41\u884c\u3002\u800cLinux\u662fWeb\u670d\u52a1\u5668\u7684\u9996\u9009\u64cd\u4f5c\u7cfb\u7edf\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u5982\u4f55\u5728linux\u4e0a\u90e8\u7f72web\u5e94\u7528\u7a0b\u5e8f\uff0c\u5e76\u9644\u4e0a\u4e00\u4e9b\u5e38\u89c1\u7684\u4ee3\u7801\u793a\u4f8b\u3002 \u5b89\u88c5\u5fc5\u8981\u7684\u8f6f\u4ef6\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u6211\u4eec\u9700\u8981\u5b89\u88c5\u4e00\u4e9b\u5fc5\u8981\u7684\u8f6f\u4ef6\uff0c\u5305\u62ecWeb\u670d\u52a1\u5668\uff08\u5982Apache\u3001Nginx\u7b49\uff09\u3001PHP\u89e3\u91ca\u5668\uff08\u5982\u679c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u4f7f\u7528\u4e86PHP\uff09\u4ee5\u53ca\u6570\u636e\u5e93\u670d\u52a1\u5668\uff08\u5982MySQL\u3001PostgreSQL\u7b49\uff09\u3002\u4ee5Ubuntu\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u8fdb\u884c\u5b89\u88c5\uff1a sudo apt-get update sudo apt-get install apache2 php mysql-server \u767b\u5f55\u540e\u590d\u5236 \u8bbe\u7f6eWeb\u670d\u52a1\u5668\u5b89\u88c5\u5b8cWeb\u670d\u52a1\u5668\u540e\uff0c\u9700\u8981\u8fdb\u884c\u4e00\u4e9b\u57fa\u672c\u7684\u914d\u7f6e\u3002\u6bd4\u5982\uff0c\u4f60\u53ef\u4ee5\u5c06\u7f51\u7ad9\u6587\u4ef6\u653e\u5728\/var\/www\/html\u76ee\u5f55\u4e0b\uff0c\u5e76\u914d\u7f6e\u865a\u62df\u4e3b\u673a\uff08\u5982\u679c\u9700\u8981\uff09\u3002\u4ee5\u4e0b\u662f\u4e00\u4e2a\u90e8\u7f72\u9759\u6001\u7f51\u7ad9\u7684\u793a\u4f8bApache\u914d\u7f6e\uff1a &lt;virtualhost&gt; ServerName example.com ServerAlias www.example.com DocumentRoot \/var\/www\/html &lt;directory&gt; Options Indexes FollowSymLinks AllowOverride All Require all granted &lt;\/directory&gt; ErrorLog ${APACHE_LOG_DIR}\/error.log CustomLog ${APACHE_LOG_DIR}\/access.log combined &lt;\/virtualhost&gt; \u767b\u5f55\u540e\u590d\u5236 \u914d\u7f6e\u6570\u636e\u5e93\u5982\u679c\u4f60\u7684\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u4f7f\u7528\u6570\u636e\u5e93\uff0c\u9700\u8981\u8fdb\u884c\u76f8\u5e94\u7684\u914d\u7f6e\u3002\u4ee5MySQL\u4e3a\u4f8b\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u767b\u5f55\u5230MySQL\u670d\u52a1\u5668\u5e76\u521b\u5efa\u4e00\u4e2a\u65b0\u7684\u6570\u636e\u5e93\u548c\u7528\u6237\uff1a sudo mysql -u root -p CREATE DATABASE myapp; CREATE USER &#8216;myuser&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;mypassword&#8217;; GRANT ALL [&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-15892","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15892","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=15892"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/15892\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=15892"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=15892"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=15892"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}