{"id":36,"date":"2021-11-04T20:27:24","date_gmt":"2021-11-04T12:27:24","guid":{"rendered":"https:\/\/www.helloalong.xyz\/?p=36"},"modified":"2021-11-09T20:18:15","modified_gmt":"2021-11-09T12:18:15","slug":"%e6%90%ad%e5%bb%balnmp%e7%8e%af%e5%a2%83linuxnginxmariadbphp","status":"publish","type":"post","link":"https:\/\/www.alonya.cn\/?p=36","title":{"rendered":"\u642d\u5efaLNMP\u73af\u5883(Linux+Nginx+MariaDB+PHP)"},"content":{"rendered":"<h2>\u5b89\u88c5Nginx<\/h2>\n<pre><code class=\"language-shell\">#\u6dfb\u52a0nginx-repo\nvi \/etc\/yum.repos.d\/nginx.repo\n#\u7f16\u8f91\u6e90\n[nginx] \nname = nginx repo \nbaseurl = https:\/\/nginx.org\/packages\/mainline\/centos\/7\/$basearch\/ \ngpgcheck = 0 \nenabled = 1\n#\u4fdd\u5b58\u9000\u51fa\n:wq\n\n#\u5b89\u88c5Nginx\nyum install -y nginx\n#\u4fee\u6539\u914d\u7f6e\u6587\u4ef6\nvim \/etc\/nginx\/conf.d\/default.conf\n#\u7f16\u8f91Nginx(\u53d6\u6d88IPV6\u76d1\u542c\u5e76\u8054\u52a8PHP)\nserver {\n    listen       80;\n    root   \/usr\/share\/nginx\/html;\n    server_name  localhost;\n    #charset koi8-r;\n    #access_log  \/var\/log\/nginx\/log\/host.access.log  main;\n    #\n    location \/ {\n          index index.php index.html index.htm;\n    }\n    #error_page  404              \/404.html;\n    #redirect server error pages to the static page \/50x.html\n    #\n    error_page   500 502 503 504  \/50x.html;\n    location = \/50x.html {\n      root   \/usr\/share\/nginx\/html;\n    }\n    #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000\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}\n#\u4fdd\u5b58\u9000\u51fa\n:wq\n#\u542f\u52a8Nginx\nsystemctl start nginx\n#\u8bbe\u7f6e\u5f00\u673a\u542f\u52a8\nsystemctl enable nginx\n#\u6d4f\u89c8\u5668\u8bbf\u95ee\u672c\u673aIP\uff0c\u5982\u9875\u9762\u663e\u793a&quot;Welcome to nginx&quot;\u5219\u4ee3\u8868nginx\u8fd0\u884c\u6b63\u5e38<\/code><\/pre>\n<h2>\u5b89\u88c5MariaDB\u6570\u636e\u5e93<\/h2>\n<pre><code class=\"language-shell\">#\u67e5\u8be2\u672c\u673a\u662f\u5426\u6709\u65e7\u7248MariaDB\nrpm -qa | grep -i mariadb\n#\u5b58\u5728mariadb\u7684\u8bdd\u5c06\u5176\u5168\u90e8\u5378\u8f7d\nyum -y remove \u5305\u540d\n#\u6dfb\u52a0mariadb-repo\nvi \/etc\/yum.repos.d\/MariaDB.repo\n# MariaDB 10.4 CentOS repository list - created 2019-11-05 11:56 UTC\n# http:\/\/downloads.mariadb.org\/mariadb\/repositories\/\n[mariadb]\nname = MariaDB\nbaseurl = https:\/\/mirrors.cloud.tencent.com\/mariadb\/yum\/10.4\/centos7-amd64\ngpgkey=https:\/\/mirrors.cloud.tencent.com\/mariadb\/yum\/RPM-GPG-KEY-MariaDB\ngpgcheck=1\n#\u4fdd\u5b58\u9000\u51fa\n:wq\n#\u5b89\u88c5MariaDB\nyum -y install MariaDB-client MariaDB-server\n#\u542f\u52a8MariaDB\nsystemctl start mariadb\n#\u8bbe\u7f6eMariaDB\u5f00\u673a\u542f\u52a8\nsystemctl enable mariadb\n#\u9a8c\u8bc1MariaDB\nmysql\n#\u5982\u663e\u793a&quot;Welcome to the MariaDB monitor&quot;\u5219\u8868\u793aMariaDB\u8fd0\u884c\u6b63\u5e38\uff0c\u6b64\u65f6\u53ef\u9000\u51fa\u6570\u636e\u5e93\n\\q<\/code><\/pre>\n<h2>\u5b89\u88c5PHP<\/h2>\n<pre><code class=\"language-shell\">#\u66f4\u65b0yum\u4e2dPHP\u7684\u8f6f\u4ef6\u6e90\nrpm -Uvh https:\/\/mirrors.cloud.tencent.com\/epel\/epel-release-latest-7.noarch.rpm\n#\u66f4\u65b0yum\u4e2dPHP\u7684\u8f6f\u4ef6\u6e90\nrpm -Uvh https:\/\/mirror.webtatic.com\/yum\/el7\/webtatic-release.rpm\n#\u5b89\u88c5\u4f9d\u8d56\nyum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64\n#\u542f\u52a8PHP-FPM\u670d\u52a1\nsystemctl start php-fpm\n#\u8bbe\u7f6ePHP-FPM\u5f00\u673a\u542f\u52a8\nsystemctl enable php-fpm\n#\u751f\u6210PHP\u793a\u4f8b\u6587\u4ef6\necho &quot;&lt;?php phpinfo(); ?&gt;&quot; &gt;&gt; \/usr\/share\/nginx\/html\/index.php\n#\u91cd\u542fNginx\nsystemctl restart nginx\n#\u8bbf\u95ee\u672c\u673aIP\uff0c\u5982\u663e\u793a&quot;PHP Version&quot;\u5219PHP\u6b63\u5e38\u8fd0\u884c<\/code><\/pre>\n<h1>\u5b89\u88c5WordPress<\/h1>\n<h2>\u914d\u7f6eMariaDB<\/h2>\n<pre><code class=\"language-shell\">#\u8fdb\u5165\u6570\u636e\u5e93\nmysql\n#\u521b\u5efa\u6570\u636e\u5e93\nCREATE DATABASE wordpress;\n#\u521b\u5efa\u7528\u6237\nCREATE USER &#039;user&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;123456&#039;;\n#\u7ed9\u7528\u6237\u8d4b\u4e88\u5168\u90e8\u6743\u9650\nGRANT ALL PRIVILEGES ON wordpress.* TO &#039;user&#039;@&#039;localhost&#039; IDENTIFIED BY &#039;123456&#039;;\n#\u8bbe\u7f6eroot\u7528\u6237\u5bc6\u7801\nALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD(&#039;\u8f93\u5165\u60a8\u7684\u5bc6\u7801&#039;);\n#\u4f7f\u914d\u7f6e\u7acb\u5373\u751f\u6548\nFLUSH PRIVILEGES;\n#\u9000\u51fa\u6570\u636e\u5e93\n\\q<\/code><\/pre>\n<h2>\u914d\u7f6eWordPress<\/h2>\n<pre><code class=\"language-shell\">#\u5220\u9664\u6d4b\u8bd5\u65f6\u521b\u5efa\u7684PHP\u6587\u4ef6\nrm -rf \/usr\/share\/nginx\/html\/index.php\n#\u8fdb\u5165Nginx\u7f51\u7ad9\u76ee\u5f55\ncd \/usr\/share\/nginx\/html\n#\u4e0b\u8f7dWordPress\nwget https:\/\/cn.wordpress.org\/wordpress-5.0.4-zh_CN.tar.gz\n#\u89e3\u538bWordPress\u6587\u4ef6\ntar zxvf wordpress-5.0.4-zh_CN.tar.gz\n#\u590d\u5236\u793a\u4f8b\u914d\u7f6e\u6587\u4ef6\ncd \/usr\/share\/nginx\/html\/wordpress\ncp wp-config-sample.php wp-config.php\n#\u4fee\u6539WordPress\u914d\u7f6e\u6587\u4ef6\nvim wp-config.php\n#\u7f16\u8f91\u914d\u7f6e\n\/\/ ** MySQL settings - You can get this info from your web host ** \/\/\n \/** The name of the database for WordPress *\/\n define(&#039;DB_NAME&#039;, &#039;wordpress&#039;);\n\n \/** MySQL database username *\/\n define(&#039;DB_USER&#039;, &#039;user&#039;);\n\n \/** MySQL database password *\/\n define(&#039;DB_PASSWORD&#039;, &#039;123456&#039;);\n\n \/** MySQL hostname *\/\n define(&#039;DB_HOST&#039;, &#039;localhost&#039;);\n #\u4fdd\u5b58\u9000\u51fa\n :wq\n #\u6d4f\u89c8\u5668\u8bbf\u95ee\u672c\u673aIP+\/wordpress\uff0c\u5982\u663e\u793a&quot;WordPress\u4e94\u5206\u949f\u5b89\u88c5\u7a0b\u5e8f&quot;\uff0c\u5219WordPress\u5b89\u88c5\u6210\u529f<\/code><\/pre>\n<h3>\u606d\u559c\uff0c\u73b0\u5728\u53ef\u4ee5\u5f00\u59cb\u5199\u535a\u5ba2\u4e86<\/h3>\n<pre><code class=\"language-shell\">#\u67e5\u8be2\u9632\u706b\u5899\u72b6\u6001\nsystemctl status firewalld.service\n#\u4e34\u65f6\u5173\u95ed\u9632\u706b\u5899\nsystemctl stop firewalld.service\n#\u6c38\u4e45\u5173\u95ed\u9632\u706b\u5899\nsystemctl disable firewalld.service\n#\u5f00\u653eMariaDB\u7aef\u53e3\nfirewall-cmd --zone=public --add-port=3306\/tcp --permanent\n#\u5f00\u653e\u4e00\u6bb5\u533a\u95f4\u5185\u7684\u7aef\u53e3\nfirewall-cmd --zone=public --add-port=40000-49999\/tcp --permanent\n#\u91cd\u542f\u9632\u706b\u5899\u7acb\u5373\u751f\u6548\nfirewall-cmd --reload\n#\u4fee\u6539mariadb\u5bc6\u7801\nmysqladmin -uroot -poldpassword password newpassword\n#\u67e5\u770bmariadb\u7528\u6237\nSELECT User, Host, Password FROM mysql.user;\n#mariadb\u5f00\u542f\u8fdc\u7a0b\u8fde\u63a5\nGRANT ALL PRIVILEGES ON *.* TO &#039;root&#039;@&#039;%&#039;IDENTIFIED BY &#039;123456&#039; WITH GRANT OPTION;\n#\u5237\u65b0\nflush privileges;\n#\u8865\u5145\uff0c\u5982\u679c\u8fd8\u65e0\u6cd5\u8bbf\u95ee\uff0c\u6ce8\u91ca\u6389\u672c\u5730\u76d1\u542c\u7ed1\u5b9a\n# bind-address = 127.0.0.1\n\n#\u8df3\u8fc7wordpress\u8981\u6c42\u7684ftp\u64cd\u4f5c\n#\u7f16\u8f91wp-config.php\n#\u5728if ( !defined(&#039;ABSPATH&#039;) )define(&#039;ABSPATH&#039;, dirname(__FILE__) . &#039;\/&#039;);\n#\u65b0\u5efatmp\u6587\u4ef6\u5939\ncd .\/html\/wordpress\/wp-content\nmkdir tmp\n#\u540e\u9762\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\ndefine(&#039;WP_TEMP_DIR&#039;, ABSPATH.&#039;wp-content\/tmp&#039;);\ndefine(&quot;FS_METHOD&quot;, &quot;direct&quot;);  \ndefine(&quot;FS_CHMOD_DIR&quot;, 0777);  \ndefine(&quot;FS_CHMOD_FILE&quot;, 0777); \n#\u5c06\u4e3b\u9898\u548c\u63d2\u4ef6\u7236\u76ee\u5f55\u8bbe\u7f6e777\u6743\u9650\nchmod -R 777 wordpress\/wp-content<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5b89\u88c5Nginx #\u6dfb\u52a0nginx-repo vi \/etc\/yum.repos.d\/nginx.repo #\u7f16 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,15],"tags":[],"class_list":["post-36","post","type-post","status-publish","format-standard","hentry","category-linux","category-os"],"_links":{"self":[{"href":"https:\/\/www.alonya.cn\/index.php?rest_route=\/wp\/v2\/posts\/36","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.alonya.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.alonya.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.alonya.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.alonya.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=36"}],"version-history":[{"count":2,"href":"https:\/\/www.alonya.cn\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions"}],"predecessor-version":[{"id":56,"href":"https:\/\/www.alonya.cn\/index.php?rest_route=\/wp\/v2\/posts\/36\/revisions\/56"}],"wp:attachment":[{"href":"https:\/\/www.alonya.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=36"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.alonya.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=36"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.alonya.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=36"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}