{"id":45116,"date":"2024-10-06T20:35:14","date_gmt":"2024-10-06T12:35:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/45116\/"},"modified":"2024-10-06T20:35:14","modified_gmt":"2024-10-06T12:35:14","slug":"%e9%98%bf%e9%87%8c%e9%9b%b2-centos-%e4%b8%8b-lnmp-%e7%92%b0%e5%a2%83%e6%90%ad%e5%bb%ba","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/45116\/","title":{"rendered":"\u963f\u91cc\u96f2 CentOS \u4e0b LNMP \u74b0\u5883\u642d\u5efa"},"content":{"rendered":"<h1 id=\"%e9%98%bf%e9%87%8c%e9%9b%b2-centos-%e4%b8%8b-lnmp-%e7%92%b0%e5%a2%83%e6%90%ad%e5%bb%ba-jCkXXqCkes\">\u963f\u91cc\u96f2 CentOS \u4e0b LNMP \u74b0\u5883\u642d\u5efa<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0cLNMP\uff08Linux, Nginx, MySQL, PHP\uff09\u67b6\u69cb\u56e0\u5176\u9ad8\u6548\u80fd\u548c\u9748\u6d3b\u6027\u800c\u53d7\u5230\u5ee3\u6cdb\u4f7f\u7528\u3002\u672c\u6587\u5c07\u4ecb\u7d39\u5982\u4f55\u5728\u963f\u91cc\u96f2\u7684 CentOS \u7cfb\u7d71\u4e0a\u642d\u5efa LNMP \u74b0\u5883\uff0c\u5e6b\u52a9\u958b\u767c\u8005\u548c\u7cfb\u7d71\u7ba1\u7406\u54e1\u5feb\u901f\u90e8\u7f72\u7db2\u7ad9\u6216\u61c9\u7528\u7a0b\u5e8f\u3002<\/p>\n<h2 id=\"%e5%89%8d%e6%9c%9f%e6%ba%96%e5%82%99-jCkXXqCkes\">\u524d\u671f\u6e96\u5099<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u60a8\u9700\u8981\u78ba\u4fdd\u5df2\u7d93\u64c1\u6709\u4e00\u500b\u904b\u884c\u4e2d\u7684\u963f\u91cc\u96f2 CentOS \u5be6\u4f8b\u3002\u60a8\u53ef\u4ee5\u9078\u64c7 CentOS 7 \u6216 CentOS 8\uff0c\u9019\u88e1\u4ee5 CentOS 7 \u70ba\u4f8b\u9032\u884c\u8aaa\u660e\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-nginx-jCkXXqCkes\">\u5b89\u88dd Nginx<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd Nginx\u3002\u6253\u958b\u7d42\u7aef\uff0c\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd Nginx\uff1a<\/p>\n<pre><code>sudo yum install epel-release\nsudo yum install nginx<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5 Nginx \u4e26\u8a2d\u7f6e\u5176\u958b\u6a5f\u81ea\u555f\uff1a<\/p>\n<pre><code>sudo systemctl start nginx\nsudo systemctl enable nginx<\/code><\/pre>\n<p>\u60a8\u53ef\u4ee5\u5728\u700f\u89bd\u5668\u4e2d\u8f38\u5165\u5be6\u4f8b\u7684 IP \u5730\u5740\uff0c\u82e5\u770b\u5230 Nginx \u7684\u6b61\u8fce\u9801\u9762\uff0c\u5247\u8868\u793a\u5b89\u88dd\u6210\u529f\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-mysql-jCkXXqCkes\">\u5b89\u88dd MySQL<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd MySQL\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd MySQL\uff1a<\/p>\n<pre><code>sudo yum install mysql-server<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5 MySQL \u4e26\u8a2d\u7f6e\u5176\u958b\u6a5f\u81ea\u555f\uff1a<\/p>\n<pre><code>sudo systemctl start mysqld\nsudo systemctl enable mysqld<\/code><\/pre>\n<p>\u5b89\u88dd\u904e\u7a0b\u4e2d\uff0cMySQL \u6703\u81ea\u52d5\u751f\u6210\u4e00\u500b\u81e8\u6642\u5bc6\u78bc\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u67e5\u770b\u8a72\u5bc6\u78bc\uff1a<\/p>\n<pre><code>sudo grep 'temporary password' \/var\/log\/mysqld.log<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u4f7f\u7528\u8a72\u5bc6\u78bc\u767b\u9304 MySQL \u4e26\u9032\u884c\u5b89\u5168\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>mysql -u root -p<\/code><\/pre>\n<p>\u5728\u767b\u9304\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u5168\u8a2d\u7f6e\uff1a<\/p>\n<pre><code>mysql_secure_installation<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-php-jCkXXqCkes\">\u5b89\u88dd PHP<\/h2>\n<p>\u73fe\u5728\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd PHP \u53ca\u5176\u76f8\u95dc\u64f4\u5c55\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88dd PHP\uff1a<\/p>\n<pre><code>sudo yum install php php-fpm php-mysql<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u52d5 PHP-FPM \u4e26\u8a2d\u7f6e\u5176\u958b\u6a5f\u81ea\u555f\uff1a<\/p>\n<pre><code>sudo systemctl start php-fpm\nsudo systemctl enable php-fpm<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-nginx-%e6%94%af%e6%8c%81-php-jCkXXqCkes\">\u914d\u7f6e Nginx \u652f\u6301 PHP<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u914d\u7f6e Nginx \u4ee5\u652f\u6301 PHP\u3002\u7de8\u8f2f Nginx \u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>sudo vi \/etc\/nginx\/conf.d\/default.conf<\/code><\/pre>\n<p>\u5728 server \u5340\u584a\u4e2d\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u914d\u7f6e\uff1a<\/p>\n<pre><code>location ~ .php$ {\n    include fastcgi_params;\n    fastcgi_pass 127.0.0.1:9000;\n    fastcgi_index index.php;\n    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n}<\/code><\/pre>\n<p>\u4fdd\u5b58\u4e26\u9000\u51fa\u7de8\u8f2f\u5668\u5f8c\uff0c\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\u65b0\u52a0\u8f09 Nginx \u914d\u7f6e\uff1a<\/p>\n<pre><code>sudo systemctl reload nginx<\/code><\/pre>\n<h2 id=\"%e6%b8%ac%e8%a9%a6-lnmp-%e7%92%b0%e5%a2%83-jCkXXqCkes\">\u6e2c\u8a66 LNMP \u74b0\u5883<\/h2>\n<p>\u6700\u5f8c\uff0c\u6211\u5011\u53ef\u4ee5\u5275\u5efa\u4e00\u500b PHP \u6e2c\u8a66\u6587\u4ef6\u4f86\u78ba\u8a8d LNMP \u74b0\u5883\u662f\u5426\u642d\u5efa\u6210\u529f\u3002\u5728 Nginx \u7684\u6839\u76ee\u9304\u4e0b\u5275\u5efa\u4e00\u500b info.php \u6587\u4ef6\uff1a<\/p>\n<pre><code>echo &lt;?php phpinfo(); ?&gt; | sudo tee \/usr\/share\/nginx\/html\/info.php<\/code><\/pre>\n<p>\u7136\u5f8c\u5728\u700f\u89bd\u5668\u4e2d\u8a2a\u554f <code>http:\/\/your_server_ip\/info.php<\/code>\uff0c\u5982\u679c\u80fd\u770b\u5230 PHP \u4fe1\u606f\u9801\u9762\uff0c\u5247\u8868\u793a LNMP \u74b0\u5883\u642d\u5efa\u6210\u529f\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-jCkXXqCkes\">\u7e3d\u7d50<\/h2>\n<p>\u672c\u6587\u4ecb\u7d39\u4e86\u5982\u4f55\u5728\u963f\u91cc\u96f2\u7684 CentOS \u7cfb\u7d71\u4e0a\u642d\u5efa LNMP \u74b0\u5883\uff0c\u5305\u62ec Nginx\u3001MySQL \u548c PHP \u7684\u5b89\u88dd\u8207\u914d\u7f6e\u3002\u9019\u4e00\u904e\u7a0b\u4e0d\u50c5\u80fd\u5e6b\u52a9\u958b\u767c\u8005\u5feb\u901f\u90e8\u7f72\u61c9\u7528\uff0c\u9084\u80fd\u63d0\u9ad8\u7db2\u7ad9\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002\u5982\u679c\u60a8\u9700\u8981\u9032\u4e00\u6b65\u7684\u652f\u6301\u6216\u5c0b\u627e\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">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\u963f\u91cc\u96f2\u7684 CentOS \u7cfb\u7d71\u4e0a\u642d\u5efa LNMP \u74b0\u5883\uff0c\u5be6\u73fe\u9ad8\u6548\u7684\u7db2\u7ad9\u904b\u884c\u8207\u7ba1\u7406\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-45116","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45116","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=45116"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45116\/revisions"}],"predecessor-version":[{"id":45117,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/45116\/revisions\/45117"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=45116"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=45116"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=45116"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}