{"id":41854,"date":"2024-10-02T11:32:48","date_gmt":"2024-10-02T03:32:48","guid":{"rendered":"https:\/\/server.hk\/cnblog\/41854\/"},"modified":"2024-10-02T11:32:48","modified_gmt":"2024-10-02T03:32:48","slug":"apache%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e4%bc%ba%e6%9c%8d%e5%99%a8%e8%a8%ad%e7%bd%aeapache","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/41854\/","title":{"rendered":"Apache\u65b0\u624b\u6559\u7a0b\uff1a\u4f7f\u7528\u6578\u64da\u5eab\u4f3a\u670d\u5668\u8a2d\u7f6eApache"},"content":{"rendered":"<h1 id=\"apache%e6%96%b0%e6%89%8b%e6%95%99%e7%a8%8b%ef%bc%9a%e4%bd%bf%e7%94%a8%e6%95%b8%e6%93%9a%e5%ba%ab%e4%bc%ba%e6%9c%8d%e5%99%a8%e8%a8%ad%e7%bd%aeapache-GZhwRMyTvQ\">Apache\u65b0\u624b\u6559\u7a0b\uff1a\u4f7f\u7528\u6578\u64da\u5eab\u4f3a\u670d\u5668\u8a2d\u7f6eApache<\/h1>\n<p>Apache HTTP \u4f3a\u670d\u5668\u662f\u7576\u4eca\u6700\u6d41\u884c\u7684\u7db2\u9801\u4f3a\u670d\u5668\u4e4b\u4e00\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u5404\u7a2e\u7db2\u7ad9\u548c\u61c9\u7528\u7a0b\u5e8f\u3002\u5c0d\u65bc\u65b0\u624b\u4f86\u8aaa\uff0c\u8a2d\u7f6e Apache \u4f3a\u670d\u5668\u4e26\u8207\u6578\u64da\u5eab\u4f3a\u670d\u5668\uff08\u5982 MySQL \u6216 MariaDB\uff09\u9032\u884c\u6574\u5408\u53ef\u80fd\u6703\u611f\u5230\u56f0\u96e3\u3002\u672c\u6587\u5c07\u63d0\u4f9b\u4e00\u500b\u8a73\u7d30\u7684\u6307\u5357\uff0c\u5e6b\u52a9\u60a8\u5728\u81ea\u5df1\u7684\u4f3a\u670d\u5668\u4e0a\u8a2d\u7f6e Apache \u4e26\u9023\u63a5\u5230\u6578\u64da\u5eab\u4f3a\u670d\u5668\u3002<\/p>\n<h2 id=\"1-%e5%ae%89%e8%a3%9d-apache-GZhwRMyTvQ\">1. \u5b89\u88dd Apache<\/h2>\n<p>\u9996\u5148\uff0c\u60a8\u9700\u8981\u5728\u60a8\u7684\u4f3a\u670d\u5668\u4e0a\u5b89\u88dd Apache\u3002\u4ee5\u4e0b\u662f\u57fa\u65bc Ubuntu \u7cfb\u7d71\u7684\u5b89\u88dd\u6b65\u9a5f\uff1a<\/p>\n<pre><code>sudo apt update\nsudo apt install apache2\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u5728\u700f\u89bd\u5668\u4e2d\u8f38\u5165\u4f3a\u670d\u5668\u7684 IP \u5730\u5740\u4f86\u6aa2\u67e5 Apache \u662f\u5426\u904b\u884c\u3002\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u61c9\u8a72\u6703\u770b\u5230 Apache \u7684\u9810\u8a2d\u9801\u9762\u3002<\/p>\n<h2 id=\"2-%e5%ae%89%e8%a3%9d%e6%95%b8%e6%93%9a%e5%ba%ab%e4%bc%ba%e6%9c%8d%e5%99%a8-GZhwRMyTvQ\">2. \u5b89\u88dd\u6578\u64da\u5eab\u4f3a\u670d\u5668<\/h2>\n<p>\u63a5\u4e0b\u4f86\uff0c\u60a8\u9700\u8981\u5b89\u88dd\u4e00\u500b\u6578\u64da\u5eab\u4f3a\u670d\u5668\u3002\u9019\u88e1\u4ee5 MySQL \u70ba\u4f8b\uff1a<\/p>\n<pre><code>sudo apt install mysql-server\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u901a\u904e\u4ee5\u4e0b\u547d\u4ee4\u555f\u52d5 MySQL \u670d\u52d9\uff1a<\/p>\n<pre><code>sudo systemctl start mysql\nsudo systemctl enable mysql\n<\/code><\/pre>\n<h2 id=\"3-%e9%85%8d%e7%bd%ae%e6%95%b8%e6%93%9a%e5%ba%ab-GZhwRMyTvQ\">3. \u914d\u7f6e\u6578\u64da\u5eab<\/h2>\n<p>\u5728\u5b89\u88dd\u5b8c MySQL \u4e4b\u5f8c\uff0c\u60a8\u9700\u8981\u9032\u884c\u4e00\u4e9b\u57fa\u672c\u914d\u7f6e\u3002\u9996\u5148\uff0c\u904b\u884c\u5b89\u5168\u6027\u8173\u672c\u4f86\u52a0\u5f37 MySQL \u7684\u5b89\u5168\u6027\uff1a<\/p>\n<pre><code>sudo mysql_secure_installation\n<\/code><\/pre>\n<p>\u6839\u64da\u63d0\u793a\u8a2d\u7f6e root \u5bc6\u78bc\uff0c\u4e26\u9078\u64c7\u5176\u4ed6\u5b89\u5168\u9078\u9805\u3002\u63a5\u4e0b\u4f86\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u4e00\u500b\u65b0\u7684\u6578\u64da\u5eab\u548c\u7528\u6236\uff1a<\/p>\n<pre><code>sudo mysql -u root -p\nCREATE DATABASE my_database;\nCREATE USER 'my_user'@'localhost' IDENTIFIED BY 'my_password';\nGRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'localhost';\nFLUSH PRIVILEGES;\nEXIT;\n<\/code><\/pre>\n<h2 id=\"4-%e5%ae%89%e8%a3%9d-php-GZhwRMyTvQ\">4. \u5b89\u88dd PHP<\/h2>\n<p>\u5982\u679c\u60a8\u7684\u7db2\u7ad9\u9700\u8981\u4f7f\u7528 PHP\uff0c\u60a8\u9700\u8981\u5b89\u88dd PHP \u53ca\u5176\u76f8\u95dc\u6a21\u7d44\uff1a<\/p>\n<pre><code>sudo apt install php libapache2-mod-php php-mysql\n<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u60a8\u53ef\u4ee5\u5275\u5efa\u4e00\u500b PHP \u6e2c\u8a66\u6587\u4ef6\u4f86\u6aa2\u67e5 PHP \u662f\u5426\u6b63\u5e38\u904b\u884c\uff1a<\/p>\n<pre><code>echo &lt;?php phpinfo(); ?&gt; | sudo tee \/var\/www\/html\/info.php\n<\/code><\/pre>\n<p>\u7136\u5f8c\u5728\u700f\u89bd\u5668\u4e2d\u8a2a\u554f <code>http:\/\/your_server_ip\/info.php<\/code>\uff0c\u60a8\u61c9\u8a72\u80fd\u770b\u5230 PHP \u7684\u4fe1\u606f\u9801\u9762\u3002<\/p>\n<h2 id=\"5-%e9%85%8d%e7%bd%ae-apache-%e8%88%87%e6%95%b8%e6%93%9a%e5%ba%ab%e7%9a%84%e9%80%a3%e6%8e%a5-GZhwRMyTvQ\">5. \u914d\u7f6e Apache \u8207\u6578\u64da\u5eab\u7684\u9023\u63a5<\/h2>\n<p>\u5728\u60a8\u7684 PHP \u61c9\u7528\u7a0b\u5e8f\u4e2d\uff0c\u60a8\u9700\u8981\u4f7f\u7528\u4ee5\u4e0b\u4ee3\u78bc\u4f86\u9023\u63a5\u5230 MySQL \u6578\u64da\u5eab\uff1a<\/p>\n<pre><code>&lt;?php\n$servername = \"localhost\";\n$username = \"my_user\";\n$password = \"my_password\";\n$dbname = \"my_database\";\n\n\/\/ \u5275\u5efa\u9023\u63a5\n$conn = new mysqli($servername, $username, $password, $dbname);\n\n\/\/ \u6aa2\u67e5\u9023\u63a5\nif ($conn-&gt;connect_error) {\n    die(\"\u9023\u63a5\u5931\u6557: \" . $conn-&gt;connect_error);\n}\necho \"\u9023\u63a5\u6210\u529f\";\n?&gt;\n<\/code><\/pre>\n<p>\u5c07\u4e0a\u8ff0\u4ee3\u78bc\u4fdd\u5b58\u70ba <code>test.php<\/code>\uff0c\u4e26\u653e\u7f6e\u5728 <code>\/var\/www\/html\/<\/code> \u76ee\u9304\u4e0b\u3002\u7136\u5f8c\u5728\u700f\u89bd\u5668\u4e2d\u8a2a\u554f <code>http:\/\/your_server_ip\/test.php<\/code>\uff0c\u5982\u679c\u4e00\u5207\u6b63\u5e38\uff0c\u60a8\u61c9\u8a72\u6703\u770b\u5230\u201c\u9023\u63a5\u6210\u529f\u201d\u7684\u6d88\u606f\u3002<\/p>\n<h2 id=\"6-%e7%b8%bd%e7%b5%90-GZhwRMyTvQ\">6. \u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4ee5\u4e0a\u6b65\u9a5f\uff0c\u60a8\u5df2\u7d93\u6210\u529f\u8a2d\u7f6e\u4e86 Apache \u4f3a\u670d\u5668\u4e26\u8207\u6578\u64da\u5eab\u4f3a\u670d\u5668\u9032\u884c\u4e86\u9023\u63a5\u3002\u9019\u4e9b\u57fa\u790e\u77e5\u8b58\u5c07\u5e6b\u52a9\u60a8\u5728\u672a\u4f86\u7684\u958b\u767c\u4e2d\u66f4\u597d\u5730\u4f7f\u7528 Apache \u548c\u6578\u64da\u5eab\u3002<\/p>\n<p>\u5982\u679c\u60a8\u9700\u8981\u66f4\u9ad8\u6548\u7684\u89e3\u6c7a\u65b9\u6848\uff0c\u8003\u616e\u4f7f\u7528 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u670d\u52d9\uff0c\u9019\u5c07\u70ba\u60a8\u7684\u7db2\u7ad9\u63d0\u4f9b\u66f4\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u66f4\u597d\u7684\u5b89\u5168\u6027\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5b78\u7fd2\u5982\u4f55\u8a2d\u7f6eApache\u4f3a\u670d\u5668\u8207\u6578\u64da\u5eab\u7684\u9023\u63a5\uff0c\u9069\u5408\u65b0\u624b\u7684\u8a73\u7d30\u6b65\u9a5f\u548c\u5be6\u7528\u6280\u5de7\uff0c\u8f15\u9b06\u4e0a\u624b\u7db2\u7ad9\u958b\u767c\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-41854","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/41854","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=41854"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/41854\/revisions"}],"predecessor-version":[{"id":41855,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/41854\/revisions\/41855"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=41854"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=41854"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=41854"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}