{"id":51373,"date":"2024-10-08T18:04:17","date_gmt":"2024-10-08T10:04:17","guid":{"rendered":"https:\/\/server.hk\/cnblog\/51373\/"},"modified":"2024-11-14T10:43:31","modified_gmt":"2024-11-14T02:43:31","slug":"ubuntu-16-04-%e4%b8%8a%e5%ae%89%e8%a3%9d-lemp-%e5%85%b7%e9%ab%94%e6%ad%a5%e9%a9%9f","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/51373\/","title":{"rendered":"Ubuntu 16.04 \u4e0a\u5b89\u88dd LEMP \u5177\u9ad4\u6b65\u9a5f"},"content":{"rendered":"<h1 id=\"ubuntu-16-04-%e4%b8%8a%e5%ae%89%e8%a3%9d-lemp-%e5%85%b7%e9%ab%94%e6%ad%a5%e9%a9%9f-WJAxgfddnS\">Ubuntu 16.04 \u4e0a\u5b89\u88dd LEMP \u5177\u9ad4\u6b65\u9a5f<\/h1>\n<p>LEMP \u662f\u4e00\u500b\u6d41\u884c\u7684\u7db2\u9801\u4f3a\u670d\u5668\u67b6\u69cb\uff0c\u5305\u542b Linux\u3001Nginx\u3001MySQL \u548c PHP\u3002\u9019\u500b\u67b6\u69cb\u56e0\u5176\u9ad8\u6548\u80fd\u548c\u9748\u6d3b\u6027\u800c\u53d7\u5230\u5ee3\u6cdb\u4f7f\u7528\u3002\u672c\u6587\u5c07\u8a73\u7d30\u4ecb\u7d39\u5728 Ubuntu 16.04 \u4e0a\u5b89\u88dd LEMP \u7684\u5177\u9ad4\u6b65\u9a5f\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-WJAxgfddnS\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u5df2\u7d93\u64c1\u6709\u4e00\u500b\u904b\u884c Ubuntu 16.04 \u7684\u4f3a\u670d\u5668\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528 SSH \u767b\u5165\u4f3a\u670d\u5668\uff0c\u4e26\u78ba\u4fdd\u7cfb\u7d71\u662f\u6700\u65b0\u7684\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u66f4\u65b0\u7cfb\u7d71\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt upgrade<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-nginx-WJAxgfddnS\">\u5b89\u88dd Nginx<\/h2>\n<p>Nginx \u662f\u4e00\u500b\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u9996\u5148\u9700\u8981\u5b89\u88dd\u5b83\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt install nginx<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Nginx \u4e26\u8a2d\u7f6e\u5176\u5728\u958b\u6a5f\u6642\u81ea\u52d5\u555f\u52d5\uff1a<\/p>\n<pre><code>sudo systemctl start nginx\nsudo systemctl enable nginx<\/code><\/pre>\n<p>\u63a5\u8457\uff0c\u60a8\u53ef\u4ee5\u5728\u700f\u89bd\u5668\u4e2d\u8f38\u5165\u4f3a\u670d\u5668\u7684 IP \u5730\u5740\uff0c\u61c9\u8a72\u80fd\u770b\u5230 Nginx \u7684\u6b61\u8fce\u9801\u9762\uff0c\u8868\u793a\u5b89\u88dd\u6210\u529f\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-mysql-WJAxgfddnS\">\u5b89\u88dd MySQL<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd MySQL \u6578\u64da\u5eab\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt install mysql-server<\/code><\/pre>\n<p>\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0c\u7cfb\u7d71\u6703\u63d0\u793a\u60a8\u8a2d\u7f6e MySQL \u7684 root \u5bc6\u78bc\u3002\u8a2d\u7f6e\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u904b\u884c\u5b89\u5168\u6027\u8173\u672c\u4f86\u52a0\u5f37 MySQL \u7684\u5b89\u5168\u6027\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>\u6839\u64da\u63d0\u793a\u9078\u64c7\u9069\u5408\u7684\u9078\u9805\uff0c\u9019\u5c07\u6709\u52a9\u65bc\u4fdd\u8b77\u60a8\u7684\u6578\u64da\u5eab\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-php-WJAxgfddnS\">\u5b89\u88dd PHP<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd PHP \u53ca\u5176\u76f8\u95dc\u7684\u64f4\u5c55\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd PHP \u548c\u5e38\u7528\u64f4\u5c55\uff1a<\/p>\n<pre><code>sudo apt install php-fpm php-mysql<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u9700\u8981\u914d\u7f6e PHP \u4ee5\u4fbf\u8207 Nginx \u4e00\u8d77\u4f7f\u7528\u3002\u7de8\u8f2f PHP \u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo nano \/etc\/php\/7.0\/fpm\/php.ini<\/code><\/pre>\n<p>\u627e\u5230\u4ee5\u4e0b\u884c\u4e26\u78ba\u4fdd\u5b83\u5011\u7684\u503c\u5982\u4e0b\uff1a<\/p>\n<pre><code>cgi.fix_pathinfo=0<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\uff0c\u7136\u5f8c\u91cd\u555f PHP-FPM \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl restart php7.0-fpm<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-nginx-%e4%bd%bf%e7%94%a8-php-WJAxgfddnS\">\u914d\u7f6e Nginx \u4f7f\u7528 PHP<\/h2>\n<p>\u73fe\u5728\uff0c\u6211\u5011\u9700\u8981\u914d\u7f6e Nginx \u4ee5\u652f\u6301 PHP\u3002\u7de8\u8f2f Nginx \u7684\u9ed8\u8a8d\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo nano \/etc\/nginx\/sites-available\/default<\/code><\/pre>\n<p>\u627e\u5230\u4ee5\u4e0b\u884c\uff1a<\/p>\n<pre><code>index index.html index.htm;<\/code><\/pre>\n<p>\u5c07\u5176\u66f4\u6539\u70ba\uff1a<\/p>\n<pre><code>index index.php index.html index.htm;<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u627e\u5230\u4ee5\u4e0b\u4f4d\u7f6e\u584a\uff1a<\/p>\n<pre><code>location \/ {<\/code><\/pre>\n<p>\u5728\u5176\u5167\u90e8\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>try_files $uri $uri\/ =404;<\/code><\/pre>\n<p>\u63a5\u8457\uff0c\u6dfb\u52a0\u4e00\u500b\u65b0\u7684\u4f4d\u7f6e\u584a\u4f86\u8655\u7406 PHP \u6587\u4ef6\uff1a<\/p>\n<pre><code>location ~ .php$ {\n    include snippets\/fastcgi-php.conf;\n    fastcgi_pass unix:\/var\/run\/php\/php7.0-fpm.sock;\n}<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\uff0c\u7136\u5f8c\u6aa2\u67e5 Nginx \u914d\u7f6e\u662f\u5426\u6b63\u78ba\uff1a<\/p>\n<pre><code>sudo nginx -t<\/code><\/pre>\n<p>\u5982\u679c\u6c92\u6709\u932f\u8aa4\uff0c\u91cd\u555f Nginx \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6-lemp-%e5%a0%86%e7%96%8a-WJAxgfddnS\">\u6e2c\u8a66 LEMP \u5806\u758a<\/h2>\n<p>\u6700\u5f8c\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u4e00\u500b PHP \u6e2c\u8a66\u6587\u4ef6\u4f86\u78ba\u8a8d LEMP \u5806\u758a\u662f\u5426\u6b63\u5e38\u904b\u884c\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5275\u5efa\u4e00\u500b\u65b0\u7684 PHP \u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo nano \/var\/www\/html\/info.php<\/code><\/pre>\n<p>\u5728\u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u5167\u5bb9\uff1a<\/p>\n<pre><code>&lt;?php\nphpinfo();\n?&gt;<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\u3002\u7136\u5f8c\u5728\u700f\u89bd\u5668\u4e2d\u8a2a\u554f <code>http:\/\/your_server_ip\/info.php<\/code>\uff0c\u60a8\u61c9\u8a72\u80fd\u770b\u5230 PHP \u7684\u4fe1\u606f\u9801\u9762\uff0c\u9019\u8868\u793a LEMP \u5806\u758a\u5df2\u6210\u529f\u5b89\u88dd\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-WJAxgfddnS\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5728 Ubuntu 16.04 \u4e0a\u5b89\u88dd LEMP \u7684\u5177\u9ad4\u6b65\u9a5f\uff0c\u5305\u62ec Nginx\u3001MySQL \u548c PHP \u7684\u5b89\u88dd\u8207\u914d\u7f6e\u3002\u9019\u4e9b\u6b65\u9a5f\u5c07\u5e6b\u52a9\u60a8\u5efa\u7acb\u4e00\u500b\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\u3002\u5982\u679c\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u89e3\u6c7a\u65b9\u6848\uff0c\u8acb\u8a2a\u554f\u6211\u5011\u7684\u7db2\u7ad9\u4ee5\u7372\u53d6\u66f4\u591a\u4fe1\u606f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u5728 Ubuntu 16.04 \u4e0a\u5b89\u88dd LEMP\uff0c\u5305\u542b\u8a73\u7d30\u6b65\u9a5f\u8207\u914d\u7f6e\u6307\u5357\uff0c\u52a9\u4f60\u5feb\u901f\u642d\u5efa\u9ad8\u6548\u7684\u7db2\u9801\u4f3a\u670d\u5668\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-51373","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51373","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=51373"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51373\/revisions"}],"predecessor-version":[{"id":51374,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/51373\/revisions\/51374"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=51373"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=51373"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=51373"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}