{"id":608,"date":"2022-02-20T20:41:36","date_gmt":"2022-02-20T12:41:36","guid":{"rendered":"https:\/\/www.buyao007.icu\/?p=608"},"modified":"2022-02-28T15:52:43","modified_gmt":"2022-02-28T07:52:43","slug":"6-nginx%e6%90%ad%e5%bb%balnmp%e6%9e%b6%e6%9e%84","status":"publish","type":"post","link":"https:\/\/www.buyao007.icu\/?p=608","title":{"rendered":"6.Nginx\u642d\u5efaLNMP\u67b6\u6784"},"content":{"rendered":"\n<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6\u7fa4\u67b6\u6784\u4e0e\u81ea\u52a8\u5316\u8fd0\u7ef4\uff0c\u66fe\u8d1f\u8d23\u56fd\u5185\u67d0\u5927\u578b\u535a\u5ba2\u7f51\u7ad9\u8fd0\u7ef4\u5de5\u4f5c\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">1.LNMP\u67b6\u6784\u57fa\u672c\u6982\u8ff0<\/h2>\n\n\n\n<p><strong><em>1.\u4ec0\u4e48\u662fLNMP<\/em><\/strong><\/p>\n\n\n\n<p>LNMP\u662f\u4e00\u5957\u6280\u672f\u7684\u7ec4\u5408\uff0cL\u662flinux\uff0cN\u662fnginx\uff0cM\u662fmysql\uff0cP\u662fphp<\/p>\n\n\n\n<p><strong><em>2.LNMP\u67b6\u6784\u539f\u7406<\/em><\/strong><\/p>\n\n\n\n<p>1.\u7528\u6237\u53d1\u51fa\u8bf7\u6c42\u540e,\u8bf7\u6c42\u5230\u8fbenginx<br>2.\u5982\u679c\u662f\u9759\u6001\u8bf7\u6c42,nginx\u81ea\u5df1\u5904\u7406<br>3.\u5982\u679c\u662f\u52a8\u6001\u8bf7\u6c42nginx \u6839\u636e \u8bf7\u6c42\u7c7b\u578b(php) \u901a\u8fc7fastcgi_pass \u52a8\u6001\u8bf7\u6c42\u4ea4\u7ed9 php-fpm(fastcgi)<br>4.php-fpm\u6536\u5230\u8bf7\u6c42\u540e,\u4f20\u9012\u7ed9php\u89e3\u91ca\u5668(\u4e0e\u6570\u636e\u5e93\u4ea4\u4e92)<br>5.\u89e3\u91ca\u540e\u628a\u7ed3\u679c\u4f20\u9012\u7ed9\u7528\u6237(\u89e3\u91ca\u5668--&gt;php-fpm---&gt;nginx---&gt;\u7528\u6237)<br>6.\u5b8c\u6210\u52a8\u6001\u8bf7\u6c42\u8fc7\u7a0b<br>php-fpm.conf \u914d\u7f6e\u63a7\u5236php-fpm\u8fdb\u7a0b<br>php.ini \u63a7\u5236\u89e3\u91ca\u5668<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_1\">2.LNMP\u73af\u5883\u914d\u7f6e<\/h2>\n\n\n\n<p><em><strong>1.\u5b89\u88c5Linux\u670d\u52a1\u5668<\/strong><\/em><\/p>\n\n\n\n<p>\u5b89\u88c5Redhat CentOS Ubuntu \u670d\u52a1\u5668<\/p>\n\n\n\n<p><strong><em>2.\u5b89\u88c5Nginx\u670d\u52a1<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>###\u914d\u7f6e\u5b98\u65b9yum\u6e90\u540e\u6267\u884c\u4e0b\u65b9\u64cd\u4f5c\n&#91;root@nginx ~]# yum install nginx -y\n&#91;root@nginx ~]# systemctl start nginx\n&#91;root@nginx ~]# systemctl enable nginx<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u5b89\u88c5PHP\u670d\u52a1\uff08\u652f\u6301\u94fe\u63a5\u5404\u7c7b\u6570\u636e\u5e93\u7684\u6a21\u5757\uff09<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/\u79fb\u9664\u65e7\u7248php\n&#91;root@nginx ~]# yum remove php-mysql-5.4 php php-fpm php-common\n\n\/\/\u5b89\u88c5\u6269\u5c55\u6e90\n&#91;root@nginx ~]# rpm -Uvh https:\/\/dl.fedoraproject.org\/pub\/epel\/epel-release-latest-7.noarch.rpm\n&#91;root@nginx ~]# rpm -Uvh https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm\n\n\/\/\u5b89\u88c5php72\u7248\u672c\n&#91;root@nginx ~]# yum -y install php72w php72w-cli php72w-common php72w-devel php72w-embedded php72w-gd php72w-mbstring php72w-pdo php72w-xml php72w-fpm php72w-mysqlnd php72w-opcache\n\n\/\/\u542f\u52a8php\n&#91;root@nginx ~]# systemctl start php-fpm\n&#91;root@nginx ~]# systemctl enable php-fpm<\/code><\/pre>\n\n\n\n<p><strong><em>4.\u5b89\u88c5Mariadb\u6570\u636e\u5e93\uff08MySQL\u670d\u52a1\uff09<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&#91;root@nginx ~]# yum -y install mariadb mariadb-server.x86_64\n&#91;root@nginx ~]# systemctl start mariadb\n&#91;root@nginx ~]# systemctl enable mariadb<\/code><\/pre>\n\n\n\n<p><strong><em>5.nginx\u96c6\u6210php<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1.\u914d\u7f6enginx\u914d\u7f6e\u6587\u4ef6\n&#91;root@nginx ~]# cat \/etc\/nginx\/conf.d\/php.conf \nserver {\n        server_name sfy.com;\n        listen 80;\n        root \/code\/php;\n        index index.php index.html;\n\n        location ~ \\.php$ {\n                fastcgi_pass   127.0.0.1:9000;\n                fastcgi_index  index.php;\n                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;\n                include        fastcgi_params;\n        }\n}\n2.\u68c0\u67e5\u662f\u5426\u96c6\u6210\u6210\u529f\n&#91;root@nginx ~]# cat \/code\/php\/index.php \n&lt;?php\n        phpinfo();\n?&gt;\n<\/code><\/pre>\n\n\n\n<p><strong><em>6.php\u96c6\u6210mysql<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php\u96c6\u6210\u4e00\u822c\u662f\u5728\u4ee3\u7801\u91cc\u96c6\u6210\u7684\n\u8fd9\u91cc\u76f4\u63a5\u6d4b\u8bd5\u662f\u5426\u80fd\u94fe\u63a5\u4e0amysql\n&#91;root@nginx ~]# cat \/code\/php\/mysqli.php\n        &lt;?php\n        $servername = \"localhost\";\n        $username = \"root\";\n        $password = \"\";\n         \n        \/\/ \u521b\u5efa\u8fde\u63a5\n        $conn = mysqli_connect($servername, $username, $password);\n         \n        \/\/ \u68c0\u6d4b\u8fde\u63a5\n        if (!$conn) {\n            die(\"Connection failed: \" . mysqli_connect_error());\n        }\n        echo \"\u8fde\u63a5\u6210\u529f\";\n        ?&gt;\n<\/code><\/pre>\n\n\n\n<p><strong><em>7.\u5b89\u88c5wordpress<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>1.\u6dfb\u52a0nginx\u914d\u7f6e\u6587\u4ef6\n&#91;root@nginx ~]# cat \/etc\/nginx\/conf.d\/wordpress.conf \nserver {\n\tlisten 80;\n\tserver_name blog.com;\n\troot \/code\/wordpress;\n\tlocation \/ {\n\t\tindex index.php;\n\t}\n\tlocation ~ \\.php$ {\n\t\tfastcgi_pass 127.0.0.1:9000;\n\t\tfastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n\t\tinclude fastcgi_params;\n\t}\n}\n2.\u4e0a\u4f20wordpress\u4ee3\u7801\n&#91;root@nginx ~]# rz\n&#91;root@nginx ~]# tar xf latest-zh_CN.tar.gz -C \/code\n3.\u521b\u5efa\u4e00\u4e2awordpress\u6570\u636e\u5e93\n&#91;root@nginx ~]# mysql -e \"create database wordpress\"\n&#91;root@nginx ~]#  mysql -e \"grant all privileges on *.* to 'wordpress'@'localhost' identified by '123456';flush privileges\"\n4.\u6d89\u53ca\u5230\u7684\u76f8\u5173mysql\u547d\u4ee4\n\u6570\u636e\u5e93\u5bc6\u7801\u8bbe\u7f6e\nmysql -uroot passwd 123456\n\u6570\u636e\u5e93\u4fee\u6539\u5bc6\u7801\nmysql -uroot -p passwd 123456\n\u6570\u636e\u5e93\u5185\u90e8\u64cd\u4f5c\uff08\u8fdb\u5165\u6570\u636e\u5e93\uff09\nmysql -uroot -p123456 -h10.0.0.7\n\u521b\u5efa\u5e93\ncreate database ***\uff1b\n\u67e5\u8be2\u6570\u636e\u5e93\nshow databases\uff1b\n\u8fdb\u5165\u5e93\uff08\u76f8\u5f53\u4e8eLinux\u7684cd\uff09\nuse WordPress\uff1b\n\u67e5\u8be2\u8868\u7684user\u548chost\u5b57\u6bb5\nselect user,host from mysql.user;\n\u6388\u6743\u8fdc\u7a0b\u8fde\u63a5\u7528\u6237\ngrant all privileges on *.* to \u2018all\u2019@\u2019%\u2019 identified by \u2018123456\u2019\n\u5237\u65b0\u6743\u9650\nflush privileges\n\u5220\u9664\u7528\u6237\ndrop user \u2018root\u2019@\u2018web01\u2019\n\u67e5\u8be2\u8868\u6709\u54ea\u4e9b\u5b57\u6bb5\ndesc user;\n<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"toc_0\">3.LNMP\u67b6\u6784\u6f14\u53d8<\/h2>\n\n\n\n<p><strong><em>1.\u4ec0\u4e48\u662fLNMP\u67b6\u6784\u6f14\u53d8<\/em><\/strong><\/p>\n\n\n\n<p>\u5f53\u6240\u6709\u670d\u52a1\u90fd\u5728\u4e00\u53f0\u670d\u52a1\u5668\u4e0a\u65f6\uff0c\u5f53\u670d\u52a1\u5668\u6545\u969c\uff0c\u6240\u6709\u670d\u52a1\u90fd\u5c06\u4e0d\u53ef\u7528\uff0c\u4e14\u4f1a\u9020\u6210\u6570\u636e\u7684\u4e22\u5931\uff0c\u67b6\u6784\u62c6\u5206\u4e4b\u540e\uff0c\u670d\u52a1\u5206\u6563\u5728\u4e0d\u540c\u670d\u52a1\u5668\uff0c\u964d\u4f4e\u4e86\u98ce\u9669\uff0c\u5e76\u4e14\u53ef\u4ee5\u51cf\u8f7b\u5355\u53f0\u670d\u52a1\u5668\u7684\u538b\u529b\u3002<\/p>\n\n\n\n<p><strong><em>2.\u9759\u6001\u8d44\u6e90\u8fc1\u79fb\uff08\u5171\u4eab\u5b58\u50a8nfs\uff09<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>###\u914d\u7f6enfs\n&#91;root@nfs ~]# yum -y install nfs-utils.x86_64\n&#91;root@nfs ~]# cat \/etc\/exports\r\n\/data\/blog 172.16.1.0\/24(rw,all_squash,anonuid=666,anongid=666)\n###\u9759\u6001\u8d44\u6e90\u8fc1\u79fb\n&#91;root@web01 ~]# mv \/code\/wordpress\/wp-content\/uploads\/* \/backup\/uploads\/\r\n&#91;root@web01 ~]# mount -t nfs 172.16.1.31:\/data\/blog \/code\/wordpress\/wp-content\/uploads\/\r\n&#91;root@web01 ~]# cp  -rp \/backup\/uploads\/ \/code\/wordpress\/wp-content\/uploads\/\r\n<\/code><\/pre>\n\n\n\n<p><strong><em>3.\u6570\u636e\u5e93\u670d\u52a1\u8fc1\u79fb<\/em><\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>###\u914d\u7f6e\u6570\u636e\u5e93\u670d\u52a1\u5668\n&#91;root@db01 ~]# yum install -y mariadb-server\r\n&#91;root@db01 ~]# systemctl start mariadb\r\n&#91;root@db01 ~]# systemctl enable mariadb\r\n#web\u670d\u52a1\u5668\u5907\u4efd\u6570\u636e\u5e93\r\n&#91;root@web01 ~]# mysqldump -uroot -p123456 -A >all.sql ###\u6570\u636e\u5e93\u5168\u90e8\u5907\u4efd\r\n#\u5907\u4efd\u4f20\u9001\u5230\u6570\u636e\u5e93\u670d\u52a1\u5668\r\n&#91;root@web01 ~]# scp  all.sql.gz   172.16.1.51:\/root\r\n#\u5bfc\u5165\u5230\u65b0\u7684\u6570\u636e\u5e93\u4e2d\r\n&#91;root@db01 ~]# gzip -d all.sql.gz\r\n&#91;root@db01 ~]# mysql  &lt;all.sql\r\n #\u767b\u5f55\u6570\u636e\u5e93\u5e76\u5237\u65b0mysql #\u6743\u9650\u4fe1\u606f\u5e76\u6388\u6743root\u7528\u6237\u8fdc\u7a0b\u767b\u5f55\r\n&#91;root@db01 ~]# mysql\r\nMariaDB &#91;(none)]> flush privileges; #\u66f4\u65b0\u6388\u6743\u4fe1\u606f\r\nMariaDB &#91;(none)]> grant all on *.*  to  'all'@'%' identified by '123456';###\u6388\u6743\u8fdc\u7a0b\u767b\u5f55\r\nweb\u670d\u52a1\u5668\u91cd\u65b0\u8fde\u63a5\u6570\u636e\u5e93\r\n#\u4fee\u6539\u7a0b\u5e8f\u4ee3\u7801,\u8bbf\u95eedb01\u7684\u6570\u636e\u5e93\uff08\u53ef\u4ee5\u7528find\u67e5\u627e\uff09\n\r&#91;root@web01 ~]# cd \/code\/wordpress\/\r\n&#91;root@web01 wordpress]# grep DB_ wp-config.php \r\ndefine( 'DB_NAME', 'wordpress' );\r\ndefine( 'DB_USER', 'all' );\r\ndefine( 'DB_PASSWORD', '123456' );\r\ndefine( 'DB_HOST', '172.16.1.51' );\r\ndefine( 'DB_CHARSET', 'utf8' );\r\ndefine( 'DB_COLLATE', '' );\n#\u6d4b\u8bd5 web\u9875\u9762\u8bbf\u95ee\u6d4b\u8bd5\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b59\u5bcc\u9633\uff0c \u6c5f\u6e56\u4eba\u79f0\u6ca1\u4eba\u79f0\u3002\u591a\u5e74\u4e92\u8054\u7f51\u8fd0\u7ef4\u5de5\u4f5c\u7ecf\u9a8c\uff0c\u66fe\u8d1f\u8d23\u8fc7\u5b59\u5e03\u65af\u5927\u89c4\u6a21\u96c6\u7fa4\u67b6\u6784\u81ea\u52a8\u5316\u8fd0\u7ef4\u7ba1\u7406\u5de5\u4f5c\u3002\u64c5\u957fWeb\u96c6 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":337,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"_links":{"self":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/608"}],"collection":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=608"}],"version-history":[{"count":8,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/608\/revisions"}],"predecessor-version":[{"id":625,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/posts\/608\/revisions\/625"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=\/wp\/v2\/media\/337"}],"wp:attachment":[{"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.buyao007.icu\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}