{"id":63689,"date":"2025-04-29T10:59:35","date_gmt":"2025-04-29T02:59:35","guid":{"rendered":"https:\/\/fwq.ai\/blog\/63689\/"},"modified":"2025-04-29T10:59:35","modified_gmt":"2025-04-29T02:59:35","slug":"linux%e6%80%8e%e4%b9%88%e6%90%ad%e5%bb%baphp%e7%8e%af%e5%a2%83-2","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/63689\/","title":{"rendered":"linux\u600e\u4e48\u642d\u5efaphp\u73af\u5883"},"content":{"rendered":"<blockquote><p>\n  \u5728 linux \u4e0a\u642d\u5efa php \u73af\u5883\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b89\u88c5 apache web \u670d\u52a1\u5668\u5b89\u88c5 mysql \u6570\u636e\u5e93\u5b89\u88c5 php \u53ca\u6a21\u5757\u521b\u5efa php \u6587\u4ef6\u8fde\u63a5\u5230 mysql \u6570\u636e\u5e93\u6267\u884c sql \u67e5\u8be2\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/04\/2024060412062030565.jpg\" class=\"aligncenter\" title=\"linux\u600e\u4e48\u642d\u5efaphp\u73af\u5883\u63d2\u56fe\" alt=\"linux\u600e\u4e48\u642d\u5efaphp\u73af\u5883\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 Linux \u4e0a\u642d\u5efa PHP \u73af\u5883<\/strong><\/p>\n<p>\u5728 Linux \u4e0a\u642d\u5efa PHP \u73af\u5883\u76f8\u5bf9\u7b80\u5355\uff0c\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a<\/p>\n<p><strong>1. \u5b89\u88c5 Apache Web \u670d\u52a1\u5668<\/strong><\/p>\n<pre>sudo apt-get install apache2<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u5b89\u88c5 MySQL \u6570\u636e\u5e93<\/strong><\/p>\n<p><span>\u7acb\u5373\u5b66\u4e60<\/span>\u201c\u201d\uff1b<\/p>\n<pre>sudo apt-get install mysql-server<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u5b89\u88c5 PHP<\/strong><\/p>\n<pre>sudo apt-get install php libapache2-mod-php php-mysql<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>4. \u542f\u7528 PHP \u6a21\u5757<\/strong><\/p>\n<pre>sudo a2enmod php7.4<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>5. \u91cd\u542f Apache<\/strong><\/p>\n<pre>sudo systemctl restart apache2<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>6. \u521b\u5efa\u4e00\u4e2a PHP \u6587\u4ef6<\/strong><\/p>\n<p>\u5728 \/var\/www\/html \u76ee\u5f55\u4e2d\u521b\u5efa\u540d\u4e3a info.php \u7684\u6587\u4ef6\uff1a<\/p>\n<pre>&lt;?php\nphpinfo();\n?&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>7. \u8bbf\u95ee PHP \u6587\u4ef6<\/strong><\/p>\n<p>\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee http:\/\/localhost\/info.php\uff0c\u60a8\u5e94\u8be5\u4f1a\u770b\u5230 PHP \u7684\u4fe1\u606f\u9875\u9762\uff0c\u8868\u660e PHP \u5df2\u6210\u529f\u914d\u7f6e\u3002<\/p>\n<p><strong>8. \u8fde\u63a5\u5230\u6570\u636e\u5e93<\/strong><\/p>\n<p>\u5728 info.php \u6587\u4ef6\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4ee3\u7801\u4ee5\u8fde\u63a5\u5230 MySQL \u6570\u636e\u5e93\uff1a<\/p>\n<pre>$servername = \"localhost\";\n$username = \"root\";\n$password = \"your_password\";\n$dbname = \"your_database\";\n\n\/\/ Create connection\n$conn = new mysqli($servername, $username, $password, $dbname);\n\n\/\/ Check connection\nif ($conn-&gt;connect_error) {\n  die(\"Connection failed: \" . $conn-&gt;connect_error);\n} <\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>9. \u6267\u884c SQL \u67e5\u8be2<\/strong><\/p>\n<pre>$sql = \"SELECT * FROM table_name\";\n$result = $conn-&gt;query($sql);\n\nif ($result-&gt;num_rows &gt; 0) {\n  \/\/ Output data of each row\n  while($row = $result-&gt;fetch_assoc()) {\n    echo \"id: \" . $row[\"id\"] . \" - Name: \" . $row[\"name\"] . \"&lt;br&gt;\";\n  }\n} else {\n  echo \"0 results\";\n}<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u73b0\u5728\uff0c\u60a8\u5df2\u7ecf\u6210\u529f\u5728 Linux \u4e0a\u642d\u5efa\u4e86\u4e00\u4e2a\u529f\u80fd\u9f50\u5168\u7684 PHP \u73af\u5883\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u600e\u4e48\u642d\u5efaphp\u73af\u5883\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8FDCServers\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5728 linux \u4e0a\u642d\u5efa php \u73af\u5883\u6d89\u53ca\u4ee5\u4e0b\u6b65\u9aa4\uff1a\u5b89\u88c5 apache web \u670d\u52a1\u5668\u5b89\u88c5 mysql \u6570\u636e\u5e93\u5b89\u88c5 php \u53ca\u6a21\u5757\u521b\u5efa php \u6587\u4ef6\u8fde\u63a5\u5230 mysql \u6570\u636e\u5e93\u6267\u884c sql \u67e5\u8be2 \u5982\u4f55\u5728 Linux \u4e0a\u642d\u5efa PHP \u73af\u5883 \u5728 Linux \u4e0a\u642d\u5efa PHP \u73af\u5883\u76f8\u5bf9\u7b80\u5355\uff0c\u9700\u8981\u4ee5\u4e0b\u6b65\u9aa4\uff1a 1. \u5b89\u88c5 Apache Web \u670d\u52a1\u5668 sudo apt-get install apache2 \u767b\u5f55\u540e\u590d\u5236 2. \u5b89\u88c5 MySQL \u6570\u636e\u5e93 \u7acb\u5373\u5b66\u4e60\u201c\u201d\uff1b sudo apt-get install mysql-server \u767b\u5f55\u540e\u590d\u5236 3. \u5b89\u88c5 PHP sudo apt-get install php [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[],"class_list":["post-63689","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63689","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=63689"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/63689\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=63689"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=63689"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=63689"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}