{"id":205,"date":"2022-09-02T09:20:09","date_gmt":"2022-09-02T01:20:09","guid":{"rendered":"https:\/\/www.jchj.top\/?p=205"},"modified":"2025-09-26T11:28:23","modified_gmt":"2025-09-26T03:28:23","slug":"lnmp%e7%8e%af%e5%a2%83%e6%90%ad%e5%bb%ba%ef%bf%bc","status":"publish","type":"post","link":"https:\/\/www.jchj.top\/?p=205","title":{"rendered":"LNMP\u73af\u5883\u624b\u52a8\u642d\u5efa\u8be6\u7a0b"},"content":{"rendered":"\n<h4 class=\"wp-block-heading\">\u4e00\uff1a\u5b89\u88c5nginx<\/h4>\n\n\n\n<p>[root@localhost \/]# yum list | grep nginx<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1063\" height=\"413\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/1.png\" alt=\"\" class=\"wp-image-206\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# yum install nginx.x86_64 -y<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"628\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/2.png\" alt=\"\" class=\"wp-image-207\"\/><\/figure>\n\n\n\n<p>\u67e5\u770bnginx\u7684\u914d\u7f6e\u6587\u4ef6<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/3.png\" alt=\"\" class=\"wp-image-208\" width=\"840\" height=\"275\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# cat \/etc\/nginx\/nginx.conf \u67e5\u770bnginx\u7684\u914d\u7f6e\u6587\u4ef6(\u5177\u4f53\u6bcf\u9879\u8868\u793a\u53ef\u53c2\u8003nginx\u5b89\u88c5\u7684\u6587\u6863))<\/p>\n\n\n\n<p>\u5728root\u5bf9\u5e94\u76ee\u5f55\u4e0b\u52a0\u5165index.php\u6587\u4ef6\uff1a<\/p>\n\n\n\n<p>location \/ {<\/p>\n\n\n\n<p>root \/opt\/nginx\/tg-t2;<\/p>\n\n\n\n<p>index index.php index.htm index.html;<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"756\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/4.png\" alt=\"\" class=\"wp-image-209\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# systemctl start nginx<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"86\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/5.png\" alt=\"\" class=\"wp-image-210\"\/><\/figure>\n\n\n\n<p>\u6d4f\u89c8\u5668\u4e2d\u8f93\u516510.0.0.170\u6216\u662f10.0.0.170\/index.html (\u6ce8\u610f\u9700\u8981\u5173\u95ed\u9632\u706b\u5899\u7b49\u5b89\u5168\u914d\u7f6e)<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"394\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/6.png\" alt=\"\" class=\"wp-image-211\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">\u4e8c\uff1a\u5b89\u88c5mariadb\u6570\u636e\u5e93\uff08centos7\u7cfb\u7edf\u9ed8\u8ba4\u7531mysql\u66f4\u6362\u4e3amariadb\u6570\u636e\u5e93\uff09<\/h4>\n\n\n\n<p>[root@localhost \/]# yum list |grep mariadb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1131\" height=\"343\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/7.png\" alt=\"\" class=\"wp-image-212\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# yum install mariadb-server.x86_64 mariadb.x86_64 -y<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"671\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/8.png\" alt=\"\" class=\"wp-image-213\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# systemctl start mariadb<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/9.png\" alt=\"\" class=\"wp-image-214\" width=\"840\" height=\"64\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# cp \/etc\/my.cnf \/etc\/my.cnf.bkg \u5907\u4efd\u6570\u636e\u5e93\u914d\u7f6e\u6587\u4ef6<\/p>\n\n\n\n<p>[root@localhost \/]# vim \/etc\/my.cnf \u7f16\u8f91\u6570\u636e\u5e93\u6587\u4ef6\u589e\u52a0\u5982\u4e0b\u4e24\u9879\u914d\u7f6e<\/p>\n\n\n\n<p>skip_name_resolve = ON \u7981\u6b62\u4e3b\u673a\u540d\u89e3\u6790<\/p>\n\n\n\n<p>innodb_file_per_table = ON \u542f\u7528innodb\u5b58\u50a8\u5f15\u64ce<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"650\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/10.png\" alt=\"\" class=\"wp-image-215\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# systemctl restart mariadb \u91cd\u542f\u6570\u636e\u5e93<\/p>\n\n\n\n<p>\u5f00\u673a\u81ea\u542f\u52a8#systemctl enable mariadb.service<\/p>\n\n\n\n<p>\u5b89\u88c5\u542f\u52a8\u6570\u636e\u5e93\u540e\u5148\u521d\u59cb\u5316\u6570\u636e\u5e93#mysql_secure_installation<\/p>\n\n\n\n<p>[root@localhost \/]# mysql_secure_installation<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"728\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/11.png\" alt=\"\" class=\"wp-image-216\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# mysql -uroot -p123456<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1036\" height=\"261\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/12.png\" alt=\"\" class=\"wp-image-217\"\/><\/figure>\n\n\n\n<p>MariaDB [(none)]&gt; show databases; \u67e5\u770b\u6570\u636e\u5e93<\/p>\n\n\n\n<p>MariaDB [(none)]&gt; CREATE DATABASE nginx_php CHARSET &#8216;utf8&#8217;; \u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93<\/p>\n\n\n\n<p>MariaDB [(none)]&gt; GRANT ALL ON nginx_php.* TO &#8216;root&#8217;@&#8217;localhost&#8217; IDENTIFIED BY &#8216;123456&#8217;; \u6388\u6743\u672c\u5730\u7528\u6237\u8bbf\u95ee\u8be5\u6570\u636e\u5e93\u7684\u6743\u9650\u3002<\/p>\n\n\n\n<p>MariaDB [(none)]&gt; GRANT ALL PRIVILEGES ON *.* TO &#8216;root&#8217;@&#8217;%&#8217; IDENTIFIED BY &#8216;123456&#8217;;\u6388\u6743\u80fd\u8fdc\u7a0b\u8fde\u63a5\u7684\u7528\u6237<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1268\" height=\"614\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/13.png\" alt=\"\" class=\"wp-image-218\"\/><\/figure>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1036\" height=\"107\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/14.png\" alt=\"\" class=\"wp-image-219\"\/><\/figure>\n\n\n\n<p>flush privileges; \u5237\u65b0\u6570\u636e\u5e93\u6743\u9650<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"683\" height=\"117\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/15.png\" alt=\"\" class=\"wp-image-220\"\/><\/figure>\n\n\n\n<h4 class=\"wp-block-heading\">\u4e09\uff1a\u5b89\u88c5php\u4ee5\u53caphp\u8fde\u63a5\u6570\u636e\u5e93\u7684\u9a71\u52a8\u7b49\u7a0b\u5e8f<\/h4>\n\n\n\n<p>[root@localhost \/]# yum install php php-mysql php-fpm -y<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"663\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/16.png\" alt=\"\" class=\"wp-image-221\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# vim etc\/nginx\/nginx.conf \u589e\u52a0\u5982\u4e0b\u914d\u7f6e\u4fe1\u606f<\/p>\n\n\n\n<p>location ~ .php$ {<\/p>\n\n\n\n<p>root \/usr\/share\/nginx\/html; #\u5c06\/usr\/share\/nginx\/html\u66ff\u6362\u4e3a\u60a8\u7684\u7f51\u7ad9\u6839\u76ee\u5f55\uff0c\u672c\u6587\u4f7f\u7528\/usr\/share\/nginx\/html\u4f5c\u4e3a\u7f51\u7ad9\u6839\u76ee\u5f55\u3002<\/p>\n\n\n\n<p>fastcgi_pass 127.0.0.1:9000; #Nginx\u901a\u8fc7\u672c\u673a\u76849000\u7aef\u53e3\u5c06PHP\u8bf7\u6c42\u8f6c\u53d1\u7ed9PHP-FPM\u8fdb\u884c\u5904\u7406\u3002<\/p>\n\n\n\n<p>fastcgi_index index.php;<\/p>\n\n\n\n<p>fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<\/p>\n\n\n\n<p>include fastcgi_params; #Nginx\u8c03\u7528fastcgi\u63a5\u53e3\u5904\u7406PHP\u8bf7\u6c42\u3002<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1233\" height=\"1280\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/17.png\" alt=\"\" class=\"wp-image-222\"\/><\/figure>\n\n\n\n<p>location ~ .php$ {<\/p>\n\n\n\n<p>root \/usr\/share\/nginx\/html;<\/p>\n\n\n\n<p>fastcgi_pass 127.0.0.1:9000;<\/p>\n\n\n\n<p>fastcgi_index index.php;<\/p>\n\n\n\n<p>fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;<\/p>\n\n\n\n<p>include fastcgi_params;<\/p>\n\n\n\n<p>}<\/p>\n\n\n\n<p>\u6ce8\uff1a\u5982\u5728\u5b9e\u9645\u73af\u5883\u4e2d\u9700\u8981\u66f4\u6539\u5b58\u653e\u7f51\u7ad9\u7684\u9ed8\u8ba4\u8def\u5f84\uff0c\u5982\u679c\u66f4\u6539root\u53c2\u6570\u65e0\u6cd5\u751f\u6548\uff0c\u53ef\u4ee5\u52a0\u4e0a\u4e00\u9879location\u914d\u7f6e\u53c2\u6570\uff0c\u5982\u4e0b:<\/p>\n\n\n\n<p>location \/ { root \/data\/www;<\/p>\n\n\n\n<p>index index.html index.php; }<\/p>\n\n\n\n<p>[root@localhost \/]# systemctl restart nginx \u91cd\u542fnginx\u670d\u52a1<\/p>\n\n\n\n<p>[root@localhost \/]# systemctl enable nginx \u5f00\u673a\u542f\u52a8nginx\u670d\u52a1<\/p>\n\n\n\n<p>[root@localhost \/]# systemctl restart php-fpm \u91cd\u542fphp-fpm<\/p>\n\n\n\n<p>[root@localhost \/]# ss -tnl \u67e5\u770bphpde 9000\u7aef\u53e3\u662f\u5426\u5904\u4e8e\u76d1\u542c\u72b6\u6001<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"93\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/18.png\" alt=\"\" class=\"wp-image-224\"\/><\/figure>\n\n\n\n<p>[root@localhost \/]# cd \/usr\/share\/nginx\/html \u8fdb\u5165\u7f51\u7ad9\u4e3a\/usr\/share\/nginx\/html\u7684\u8ddf\u76ee\u5f55<\/p>\n\n\n\n<p>[root@localhost html]# vim phpinfo.php \u7f16\u8f91\u6d4b\u8bd5\u9875\u9762\u5185 \u5185\u5982\u5982\u4e0b<\/p>\n\n\n\n<p>&lt;html&gt;<\/p>\n\n\n\n<p>&lt;title&gt;\u6d4b\u8bd5&lt;\/title&gt;<\/p>\n\n\n\n<p>&lt;?php<\/p>\n\n\n\n<p>phpinfo();<\/p>\n\n\n\n<p>?&gt;<\/p>\n\n\n\n<p>&lt;\/html&gt;<\/p>\n\n\n\n<p>\u6d4f\u89c8\u5668\u8f93\u5165\u8bbf\u95ee\u9875\u9762 10.0.0.170\/phpinfo.php<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"621\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/19.png\" alt=\"\" class=\"wp-image-226\"\/><\/figure>\n\n\n\n<p>\u6570\u636e\u5e93mariadb\uff08mysql\uff09\u4e5f\u5df2\u5f00\u542f<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1280\" height=\"630\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/20.png\" alt=\"\" class=\"wp-image-227\"\/><\/figure>\n\n\n\n<p>\u8fd8\u53ef\u4ee5\u4f7f\u7528\u7f16\u8f91\u811a\u672c\u518d\u6b21\u6d4b\u8bd5mariadb\u6570\u636e\u5e93\u7684\u8fde\u63a5\u662f\u5426\u6b63\u5e38<\/p>\n\n\n\n<p>[root@localhost \/]# vim \/usr\/share\/nginx\/html\/php_mariadb.php<\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/www.jchj.top\/wp-content\/uploads\/2022\/09\/21.png\" alt=\"\" class=\"wp-image-228\" width=\"840\" height=\"294\"\/><\/figure>\n\n\n\n<p>&lt;?php<\/p>\n\n\n\n<p>$conn = mysql_connect(&#8216;10.0.0.170&#8242;,&#8217;root&#8217;,&#8217;123456&#8242;);<\/p>\n\n\n\n<p>if ($conn)<\/p>\n\n\n\n<p>echo &#8220;OK&#8221;;<\/p>\n\n\n\n<p>else<\/p>\n\n\n\n<p>echo &#8220;Failure&#8221;;<\/p>\n\n\n\n<p>?&gt;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\uff1a\u5b89\u88c5nginx [root@localhost&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21,7,1],"tags":[],"class_list":["post-205","post","type-post","status-publish","format-standard","hentry","category-linux","category-7","category-1"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/www.jchj.top\/index.php?rest_route=\/wp\/v2\/posts\/205","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.jchj.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.jchj.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.jchj.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.jchj.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=205"}],"version-history":[{"count":5,"href":"https:\/\/www.jchj.top\/index.php?rest_route=\/wp\/v2\/posts\/205\/revisions"}],"predecessor-version":[{"id":242,"href":"https:\/\/www.jchj.top\/index.php?rest_route=\/wp\/v2\/posts\/205\/revisions\/242"}],"wp:attachment":[{"href":"https:\/\/www.jchj.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=205"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.jchj.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=205"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.jchj.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}