{"id":53133,"date":"2024-10-09T08:35:23","date_gmt":"2024-10-09T00:35:23","guid":{"rendered":"https:\/\/server.hk\/cnblog\/53133\/"},"modified":"2024-11-14T10:35:57","modified_gmt":"2024-11-14T02:35:57","slug":"%e5%9c%a8-ubuntu-18-04-%e4%b8%8a%e5%ae%89%e8%a3%9d%e5%b8%b6%e6%9c%89-nginx%e3%80%81mariadb-10-%e5%92%8c-php-7-%e7%9a%84-wordpress","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/53133\/","title":{"rendered":"\u5728 Ubuntu 18.04 \u4e0a\u5b89\u88dd\u5e36\u6709 Nginx\u3001MariaDB 10 \u548c PHP 7 \u7684 WordPress"},"content":{"rendered":"<h1 id=\"%e5%9c%a8-ubuntu-18-04-%e4%b8%8a%e5%ae%89%e8%a3%9d%e5%b8%b6%e6%9c%89-nginx%e3%80%81mariadb-10-%e5%92%8c-php-7-%e7%9a%84-wordpress-xEWtcVkTip\">\u5728 Ubuntu 18.04 \u4e0a\u5b89\u88dd\u5e36\u6709 Nginx\u3001MariaDB 10 \u548c PHP 7 \u7684 WordPress<\/h1>\n<p>WordPress \u662f\u4e00\u500b\u6d41\u884c\u7684\u5167\u5bb9\u7ba1\u7406\u7cfb\u7d71\uff0c\u5ee3\u6cdb\u7528\u65bc\u5efa\u7acb\u7db2\u7ad9\u548c\u90e8\u843d\u683c\u3002\u672c\u6587\u5c07\u6307\u5c0e\u60a8\u5982\u4f55\u5728 Ubuntu 18.04 \u4e0a\u5b89\u88dd WordPress\uff0c\u4e26\u914d\u7f6e Nginx \u4f5c\u70ba\u7db2\u9801\u4f3a\u670d\u5668\uff0cMariaDB \u4f5c\u70ba\u8cc7\u6599\u5eab\uff0c\u53ca PHP 7 \u4f5c\u70ba\u5f8c\u7aef\u8a9e\u8a00\u3002<\/p>\n<h2 id=\"%e5%89%8d%e7%bd%ae%e6%a2%9d%e4%bb%b6-xEWtcVkTip\">\u524d\u7f6e\u689d\u4ef6<\/h2>\n<p>\u5728\u958b\u59cb\u4e4b\u524d\uff0c\u8acb\u78ba\u4fdd\u60a8\u5df2\u7d93\u64c1\u6709\u4e00\u500b\u904b\u884c\u4e2d\u7684 Ubuntu 18.04 \u4f3a\u670d\u5668\uff0c\u4e26\u4e14\u64c1\u6709 sudo \u6b0a\u9650\u3002\u60a8\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-xEWtcVkTip\">\u5b89\u88dd Nginx<\/h2>\n<p>\u9996\u5148\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd Nginx\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\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 Nginx \u4e26\u8a2d\u7f6e\u5176\u5728\u555f\u52d5\u6642\u81ea\u52d5\u904b\u884c\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\u9810\u8a2d\u9801\u9762\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-mariadb-xEWtcVkTip\">\u5b89\u88dd MariaDB<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd MariaDB\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt install mariadb-server<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 MariaDB \u4e26\u8a2d\u7f6e\u5176\u5728\u555f\u52d5\u6642\u81ea\u52d5\u904b\u884c\uff1a<\/p>\n<pre><code>sudo systemctl start mariadb\nsudo systemctl enable mariadb<\/code><\/pre>\n<p>\u70ba\u4e86\u63d0\u9ad8\u5b89\u5168\u6027\uff0c\u5efa\u8b70\u904b\u884c MariaDB \u7684\u5b89\u5168\u6027\u8173\u672c\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation<\/code><\/pre>\n<p>\u6839\u64da\u63d0\u793a\u8a2d\u7f6e root \u5bc6\u78bc\uff0c\u4e26\u9078\u64c7\u5176\u4ed6\u5b89\u5168\u9078\u9805\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-php-7-xEWtcVkTip\">\u5b89\u88dd PHP 7<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u6211\u5011\u9700\u8981\u5b89\u88dd PHP \u53ca\u5176\u76f8\u95dc\u64f4\u5c55\u3002\u4f7f\u7528\u4ee5\u4e0b\u547d\u4ee4\u9032\u884c\u5b89\u88dd\uff1a<\/p>\n<pre><code>sudo apt install php php-fpm php-mysql<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u6aa2\u67e5 PHP \u662f\u5426\u5b89\u88dd\u6210\u529f\uff1a<\/p>\n<pre><code>php -v<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-nginx-%e4%bb%a5%e6%94%af%e6%8c%81-php-xEWtcVkTip\">\u914d\u7f6e Nginx \u4ee5\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\u9810\u8a2d\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>\u4e26\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\u6bb5\u843d\uff1a<\/p>\n<pre><code>location \/ {<\/code><\/pre>\n<p>\u4e26\u5c07\u5176\u66f4\u6539\u70ba\uff1a<\/p>\n<pre><code>location \/ {\n    try_files $uri $uri\/ \/index.php?$args;\n}<\/code><\/pre>\n<p>\u63a5\u8457\uff0c\u6dfb\u52a0\u4ee5\u4e0b\u6bb5\u843d\u4ee5\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.2-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\u65b0\u555f\u52d5 Nginx\uff1a<\/p>\n<pre><code>sudo systemctl restart nginx<\/code><\/pre>\n<h2 id=\"%e5%ae%89%e8%a3%9d-wordpress-xEWtcVkTip\">\u5b89\u88dd WordPress<\/h2>\n<p>\u73fe\u5728\uff0c\u6211\u5011\u53ef\u4ee5\u4e0b\u8f09\u4e26\u5b89\u88dd WordPress\u3002\u9996\u5148\uff0c\u5b89\u88dd wget \u548c unzip\uff1a<\/p>\n<pre><code>sudo apt install wget unzip<\/code><\/pre>\n<p>\u7136\u5f8c\uff0c\u4e0b\u8f09 WordPress\uff1a<\/p>\n<pre><code>wget https:\/\/wordpress.org\/latest.zip<\/code><\/pre>\n<p>\u89e3\u58d3\u7e2e\u4e0b\u8f09\u7684\u6587\u4ef6\uff1a<\/p>\n<pre><code>unzip latest.zip<\/code><\/pre>\n<p>\u5c07 WordPress \u6587\u4ef6\u79fb\u52d5\u5230 Nginx \u7684\u6839\u76ee\u9304\uff1a<\/p>\n<pre><code>sudo mv wordpress\/* \/var\/www\/html\/<\/code><\/pre>\n<p>\u8a2d\u7f6e\u9069\u7576\u7684\u6b0a\u9650\uff1a<\/p>\n<pre><code>sudo chown -R www-data:www-data \/var\/www\/html\/\nsudo chmod -R 755 \/var\/www\/html\/<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-wordpress-xEWtcVkTip\">\u914d\u7f6e WordPress<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5275\u5efa\u4e00\u500b\u8cc7\u6599\u5eab\u548c\u7528\u6236\u4f9b WordPress \u4f7f\u7528\u3002\u9032\u5165 MariaDB\uff1a<\/p>\n<pre><code>sudo mysql -u root -p<\/code><\/pre>\n<p>\u7136\u5f8c\u57f7\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a<\/p>\n<pre><code>CREATE DATABASE wordpress;\nCREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'your_password';\nGRANT ALL PRIVILEGES ON wordpress.* TO 'wp_user'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;<\/code><\/pre>\n<p>\u63a5\u4e0b\u4f86\uff0c\u91cd\u547d\u540d WordPress \u7684\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre><code>cd \/var\/www\/html\/\ncp wp-config-sample.php wp-config.php<\/code><\/pre>\n<p>\u7de8\u8f2f wp-config.php \u6587\u4ef6\uff0c\u4e26\u586b\u5165\u8cc7\u6599\u5eab\u4fe1\u606f\uff1a<\/p>\n<pre><code>nano wp-config.php<\/code><\/pre>\n<p>\u627e\u5230\u4ee5\u4e0b\u884c\u4e26\u9032\u884c\u4fee\u6539\uff1a<\/p>\n<pre><code>define('DB_NAME', 'wordpress');\ndefine('DB_USER', 'wp_user');\ndefine('DB_PASSWORD', 'your_password');<\/code><\/pre>\n<h2 id=\"%e5%ae%8c%e6%88%90%e5%ae%89%e8%a3%9d-xEWtcVkTip\">\u5b8c\u6210\u5b89\u88dd<\/h2>\n<p>\u73fe\u5728\uff0c\u60a8\u53ef\u4ee5\u5728\u700f\u89bd\u5668\u4e2d\u8a2a\u554f\u60a8\u7684\u4f3a\u670d\u5668 IP \u5730\u5740\uff0c\u4e26\u6309\u7167 WordPress \u7684\u5b89\u88dd\u5411\u5c0e\u5b8c\u6210\u5b89\u88dd\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-xEWtcVkTip\">\u7e3d\u7d50<\/h2>\n<p>\u5728\u672c\u6587\u4e2d\uff0c\u6211\u5011\u4ecb\u7d39\u4e86\u5982\u4f55\u5728 Ubuntu 18.04 \u4e0a\u5b89\u88dd\u5e36\u6709 Nginx\u3001MariaDB 10 \u548c PHP 7 \u7684 WordPress\u3002\u9019\u500b\u904e\u7a0b\u6d89\u53ca\u5230\u591a\u500b\u6b65\u9a5f\uff0c\u5305\u62ec\u5b89\u88dd\u4f3a\u670d\u5668\u8edf\u4ef6\u3001\u914d\u7f6e\u8cc7\u6599\u5eab\u4ee5\u53ca\u8a2d\u7f6e WordPress\u3002\u82e5\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u7db2\u7ad9\u904b\u884c\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u4f86\u63d0\u5347\u60a8\u7684\u7db2\u7ad9\u6027\u80fd\u548c\u7a69\u5b9a\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 Ubuntu 18.04 \u4e0a\u5b89\u88dd WordPress\uff0c\u914d\u7f6e Nginx\u3001MariaDB 10 \u548c PHP 7\uff0c\u8f15\u9b06\u6253\u9020\u9ad8\u6548\u80fd\u7db2\u7ad9\u74b0\u5883\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-53133","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/53133","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=53133"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/53133\/revisions"}],"predecessor-version":[{"id":53134,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/53133\/revisions\/53134"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=53133"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=53133"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=53133"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}