{"id":12,"date":"2025-10-09T08:42:36","date_gmt":"2025-10-09T00:42:36","guid":{"rendered":"https:\/\/47.99.41.133\/?p=12"},"modified":"2025-10-09T08:42:36","modified_gmt":"2025-10-09T00:42:36","slug":"wordpress-%e9%87%8d%e6%96%b0%e9%85%8d%e7%bd%ae%e4%b8%8e%e6%95%b0%e6%8d%ae%e5%ba%93%e8%bf%9e%e6%8e%a5%e9%94%99%e8%af%af%e7%9a%84%e4%bf%ae%e5%a4%8d","status":"publish","type":"post","link":"https:\/\/www.lhws.top\/index.php\/2025\/10\/09\/wordpress-%e9%87%8d%e6%96%b0%e9%85%8d%e7%bd%ae%e4%b8%8e%e6%95%b0%e6%8d%ae%e5%ba%93%e8%bf%9e%e6%8e%a5%e9%94%99%e8%af%af%e7%9a%84%e4%bf%ae%e5%a4%8d\/","title":{"rendered":"WordPress \u91cd\u65b0\u914d\u7f6e\u4e0e\u6570\u636e\u5e93\u8fde\u63a5\u9519\u8bef\u7684\u4fee\u590d"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">\ud83e\udde9 \u4e00\u3001\u95ee\u9898\u80cc\u666f<\/h3>\n\n\n\n<p>\u8fc1\u79fb\u670d\u52a1\u5668\u6216\u4fee\u6539\u6570\u636e\u5e93\u540e\uff0c\u6211\u7684 WordPress \u6253\u5f00\u9875\u9762\u63d0\u793a\uff1a<\/p>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p><strong>Error establishing a database connection<\/strong><\/p>\n<\/blockquote>\n\n\n\n<p>\u540c\u65f6\uff0c\u6709\u65f6\u6839\u76ee\u5f55\u62a5 <strong>403 Forbidden<\/strong>\uff0c<br>\u800c <code>\/wordpress\/<\/code> \u9875\u9762\u5374\u80fd\u6b63\u5e38\u8bbf\u95ee\u3002<br>\u8fd9\u8bf4\u660e WordPress \u7684\u6570\u636e\u5e93\u914d\u7f6e\u6216 Nginx \u8bbe\u7f6e\u5b58\u5728\u95ee\u9898\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd0d \u4e8c\u3001\u95ee\u9898\u5206\u6790<\/h3>\n\n\n\n<p>\u901a\u8fc7\u4e00\u7cfb\u5217\u6392\u67e5\u540e\uff0c\u53d1\u73b0\u4e86\u51e0\u4e2a\u5173\u952e\u539f\u56e0\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><code>wp-config.php<\/code> \u4e2d\u7684\u6570\u636e\u5e93\u4fe1\u606f\u4e0d\u5339\u914d<\/li>\n\n\n\n<li>MySQL \u7528\u6237\u6743\u9650\u53ea\u6388\u6743\u4e86 <code>localhost<\/code>\uff0c\u6ca1\u6709\u7ed9 <code>127.0.0.1<\/code><\/li>\n\n\n\n<li>Nginx \u914d\u7f6e\u6587\u4ef6\u4e2d <code>root<\/code> \u8def\u5f84\u9519\u8bef<\/li>\n\n\n\n<li>PHP \u8fde\u63a5\u6570\u636e\u5e93\u65f6\u672a\u6b63\u786e\u4f7f\u7528 socket<\/li>\n<\/ol>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udd27 \u4e09\u3001\u89e3\u51b3\u6b65\u9aa4<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">1\ufe0f\u20e3 \u4fee\u590d MySQL \u7528\u6237\u4e0e\u6743\u9650<\/h4>\n\n\n\n<p>\u767b\u5f55\u6570\u636e\u5e93\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql -uroot -p\n<\/code><\/pre>\n\n\n\n<p>\u6267\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE DATABASE wordpress DEFAULT CHARSET utf8mb4 COLLATE utf8mb4_unicode_ci;\nCREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'LH2004lh-';\nGRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';\nFLUSH PRIVILEGES;\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">2\ufe0f\u20e3 \u7f16\u8f91 wp-config.php<\/h4>\n\n\n\n<p>\u8def\u5f84\uff1a<code>\/var\/www\/html\/wordpress\/wp-config.php<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>define('DB_NAME', 'wordpress');\ndefine('DB_USER', 'wpuser');\ndefine('DB_PASSWORD', 'LH2004lh-');\ndefine('DB_HOST', 'localhost');\ndefine('DB_CHARSET', 'utf8mb4');\ndefine('DB_COLLATE', '');\n$table_prefix = 'wp_';\ndefine('WP_DEBUG', false);\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">3\ufe0f\u20e3 \u91cd\u5199 Nginx \u914d\u7f6e\uff08\/etc\/nginx\/conf.d\/lhws.top.conf\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>server {\n    listen 80;\n    server_name lhws.top www.lhws.top;\n    return 301 https:\/\/$server_name$request_uri;\n}\n\nserver {\n    listen 443 ssl http2;\n    server_name lhws.top www.lhws.top;\n\n    ssl_certificate \/etc\/letsencrypt\/live\/lhws.top\/fullchain.pem;\n    ssl_certificate_key \/etc\/letsencrypt\/live\/lhws.top\/privkey.pem;\n    include \/etc\/letsencrypt\/options-ssl-nginx.conf;\n    ssl_dhparam \/etc\/letsencrypt\/ssl-dhparams.pem;\n\n    root \/var\/www\/html\/wordpress;\n    index index.php index.html index.htm;\n\n    location \/ {\n        try_files $uri $uri\/ \/index.php?$args;\n    }\n\n    location ~ \\.php$ {\n        include fastcgi_params;\n        fastcgi_pass unix:\/run\/php-fpm\/www.sock;\n        fastcgi_index index.php;\n        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;\n    }\n\n    error_page 403 \/403.html;\n    error_page 404 \/404.html;\n}\n<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">4\ufe0f\u20e3 \u6570\u636e\u5e93\u8fde\u63a5\u6d4b\u8bd5\u6587\u4ef6\uff08testdb.php\uff09<\/h4>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\n$db_socket = '\/var\/lib\/mysql\/mysql.sock';\n$conn = new mysqli(null, 'wpuser', 'LH2004lh-', 'wordpress', null, $db_socket);\nif ($conn-&gt;connect_error) {\n    die(\"\u274c \u6570\u636e\u5e93\u8fde\u63a5\u5931\u8d25\uff01&lt;br&gt;\u9519\u8bef\u4fe1\u606f: \" . $conn-&gt;connect_error);\n}\necho \"\u2705 \u6570\u636e\u5e93\u8fde\u63a5\u6210\u529f\uff01\";\n$conn-&gt;close();\n?&gt;\n<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\u2705 \u56db\u3001\u7ed3\u679c\u9a8c\u8bc1<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8bbf\u95ee <code>https:\/\/lhws.top\/testdb.php<\/code> \u663e\u793a \u2705 \u6570\u636e\u5e93\u8fde\u63a5\u6210\u529f\uff01<\/li>\n\n\n\n<li>WordPress \u524d\u53f0\u4e0e\u540e\u53f0\u5168\u90e8\u6062\u590d\u6b63\u5e38<\/li>\n\n\n\n<li>403\/404 \u95ee\u9898\u6d88\u5931\uff0cHTTPS \u5f3a\u5236\u8df3\u8f6c\u751f\u6548<\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">\ud83d\udca1 \u4e94\u3001\u7ecf\u9a8c\u603b\u7ed3<\/h3>\n\n\n\n<ul class=\"wp-block-list\">\n<li>WordPress \u7684\u6570\u636e\u5e93\u8fde\u63a5\u662f\u901a\u8fc7 <code>mysqli<\/code>\uff0c\u5fc5\u987b\u786e\u8ba4 socket \u4e0e\u7528\u6237\u6743\u9650\u5339\u914d<\/li>\n\n\n\n<li>\u63a8\u8350\u4f7f\u7528 <code>localhost<\/code> + Unix socket\uff08\u6bd4 TCP \u66f4\u7a33\u5b9a\uff09<\/li>\n\n\n\n<li>Nginx \u7684 <code>root<\/code> \u8def\u5f84\u5fc5\u987b\u7cbe\u786e\u6307\u5411 WordPress \u76ee\u5f55<\/li>\n\n\n\n<li>\u4e00\u5b9a\u8bb0\u5f97\u5728\u4fee\u6539\u540e\u91cd\u542f\u670d\u52a1\uff1a <code>systemctl restart nginx systemctl restart php-fpm<\/code><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p><strong>\u2705 \u6700\u7ec8\u7ed3\u679c\uff1a<\/strong><br>\u7f51\u7ad9\u5b8c\u5168\u6062\u590d\uff0c\u6570\u636e\u5e93\u8fde\u63a5\u7a33\u5b9a\uff0cHTTPS \u6b63\u5e38\u8df3\u8f6c\u3002<br>\u4e00\u6b21\u4ece\u201cError establishing a database connection\u201d\u5230\u201c\u7f51\u7ad9\u91cd\u751f\u201d\u7684\u5b8c\u6574\u4fee\u590d\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\ud83e\udde9 \u4e00\u3001\u95ee\u9898\u80cc\u666f \u8fc1\u79fb\u670d\u52a1\u5668\u6216\u4fee\u6539\u6570\u636e\u5e93\u540e\uff0c\u6211\u7684 WordPress \u6253\u5f00\u9875\u9762\u63d0\u793a\uff1a Error establ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-12","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/posts\/12","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/comments?post=12"}],"version-history":[{"count":1,"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions"}],"predecessor-version":[{"id":13,"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/posts\/12\/revisions\/13"}],"wp:attachment":[{"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/media?parent=12"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/categories?post=12"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lhws.top\/index.php\/wp-json\/wp\/v2\/tags?post=12"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}