{"id":16761,"date":"2024-11-18T12:53:10","date_gmt":"2024-11-18T04:53:10","guid":{"rendered":"https:\/\/fwq.ai\/blog\/16761\/"},"modified":"2024-11-18T12:53:10","modified_gmt":"2024-11-18T04:53:10","slug":"%e6%8e%8c%e6%8f%a1centos%e4%b8%8a%e6%90%ad%e5%bb%baweb%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84%e6%96%b9%e6%b3%95%ef%bc%8c%e9%81%bf%e5%85%8d%e5%b8%b8%e8%a7%81%e9%94%99%e8%af%af","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/16761\/","title":{"rendered":"\u638c\u63e1CentOS\u4e0a\u642d\u5efaweb\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u907f\u514d\u5e38\u89c1\u9519\u8bef"},"content":{"rendered":"<p>\u638c\u63e1\u4e0a\u642d\u5efaweb\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u907f\u514d\u5e38\u89c1\u9519\u8bef<\/p>\n<p>\u4f5c\u4e3a\u4e00\u6b3e\u5f00\u6e90\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0cCentOS\u5728\u670d\u52a1\u5668\u9886\u57df\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\u3002\u642d\u5efaweb\u670d\u52a1\u5668\u662f\u4f7f\u7528CentOS\u7684\u5e38\u89c1\u9700\u6c42\u4e4b\u4e00\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u642d\u5efaweb\u670d\u52a1\u5668\u7684\u8be6\u7ec6\u65b9\u6cd5\uff0c\u5e76\u63d0\u9192\u8bfb\u8005\u907f\u514d\u5e38\u89c1\u9519\u8bef\u3002<\/p>\n<p>\u4e00\u3001\u5b89\u88c5Apache<\/p>\n<p>Apache\u662f\u4e00\u6b3e\u5f3a\u5927\u800c\u7a33\u5b9a\u7684web\u670d\u52a1\u5668\u8f6f\u4ef6\uff0c\u4f7f\u7528\u5e7f\u6cdb\u3002\u6211\u4eec\u9996\u5148\u8981\u5b89\u88c5Apache\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Apache\uff1a<\/p>\n<pre>sudo yum install httpd<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u542f\u52a8Apache\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\u52a8\uff1a<\/p>\n<pre>sudo systemctl start httpd\nsudo systemctl enable httpd<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e8c\u3001\u914d\u7f6eApache<\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u9700\u8981\u8fdb\u884cApache\u7684\u914d\u7f6e\u3002\u6253\u5f00Apache\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre>sudo vi \/etc\/httpd\/conf\/httpd.conf<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0b\u4e3a\u4e00\u4e9b\u5e38\u89c1\u914d\u7f6e\u9879\u53ca\u5176\u793a\u4f8b\uff1a<\/p>\n<ol>\n<li>\n<p>\u76d1\u542c\u7aef\u53e3<\/p>\n<pre>Listen 80<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u7f51\u7ad9\u6839\u76ee\u5f55<\/p>\n<pre>DocumentRoot \"\/var\/www\/html\"\n&lt;directory&gt;\n AllowOverride None\n Require all granted\n&lt;\/directory&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u8bbe\u7f6e\u9ed8\u8ba4\u9875\u9762<\/p>\n<pre>DirectoryIndex index.html index.php<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u8bbe\u7f6e\u865a\u62df\u4e3b\u673a<\/p>\n<pre>&lt;virtualhost&gt;\n DocumentRoot \"\/var\/www\/html\/example\"\n ServerName example.com\n&lt;\/virtualhost&gt;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u4fdd\u5b58\u6587\u4ef6\u5e76\u91cd\u542fApache\uff1a<\/p>\n<pre>sudo systemctl restart httpd<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e09\u3001\u5b89\u88c5PHP<\/p>\n<p>PHP\u662f\u4e00\u79cd\u5728\u670d\u52a1\u5668\u7aef\u6267\u884c\u7684\u811a\u672c\u8bed\u8a00\uff0c\u914d\u5408Apache\u53ef\u4ee5\u5b9e\u73b0\u52a8\u6001\u7f51\u9875\u7684\u5f00\u53d1\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5PHP\u53ca\u76f8\u5173\u6269\u5c55\uff1a<\/p>\n<pre>sudo yum install php\nsudo yum install php-mysql php-gd php-opcache php-devel php-mbstring<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u7f16\u8f91PHP\u914d\u7f6e\u6587\u4ef6\uff1a<\/p>\n<pre>sudo vi \/etc\/php.ini<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0b\u4e3a\u4e00\u4e9b\u5e38\u89c1\u914d\u7f6e\u9879\u53ca\u5176\u793a\u4f8b\uff1a<\/p>\n<ol>\n<li>\n<p>\u8bbe\u7f6e\u9ed8\u8ba4\u65f6\u533a<\/p>\n<pre>date.timezone = Asia\/Shanghai<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u8bbe\u7f6e\u4e0a\u4f20\u6587\u4ef6\u5927\u5c0f\u9650\u5236<\/p>\n<pre>upload_max_filesize = 8M\npost_max_size = 8M<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p>\u914d\u7f6e\u5b8c\u6210\u540e\uff0c\u4fdd\u5b58\u6587\u4ef6\u5e76\u91cd\u542fApache\uff1a<\/p>\n<pre>sudo systemctl restart httpd<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u56db\u3001\u5b89\u88c5MySQL<\/p>\n<p>MySQL\u662f\u4e00\u6b3e\u6d41\u884c\u7684\u5173\u7cfb\u578b\u6570\u636e\u5e93\u7ba1\u7406\u7cfb\u7edf\uff0c\u7528\u4e8e\u5b58\u50a8\u548c\u7ba1\u7406web\u5e94\u7528\u7684\u6570\u636e\u3002<\/p>\n<p>\u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5MySQL\u53ca\u76f8\u5173\u5de5\u5177\uff1a<\/p>\n<pre>sudo yum install mariadb-server mariadb<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u542f\u52a8MySQL\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\u52a8\uff1a<\/p>\n<pre>sudo systemctl start mariadb\nsudo systemctl enable mariadb<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u8fd0\u884c\u5b89\u5168\u811a\u672c\u8fdb\u884c\u521d\u59cb\u5316\u8bbe\u7f6e\uff1a<\/p>\n<pre>sudo mysql_secure_installation<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4e94\u3001\u914d\u7f6e\u6570\u636e\u5e93<\/p>\n<p>\u521b\u5efa\u4e00\u4e2a\u6570\u636e\u5e93\u548c\u4e00\u4e2a\u65b0\u7528\u6237\uff0c\u5e76\u8d4b\u4e88\u8be5\u7528\u6237\u8bbf\u95ee\u6570\u636e\u5e93\u7684\u6743\u9650\u3002<\/p>\n<p>\u767b\u5f55MySQL\uff1a<\/p>\n<pre>sudo mysql -u root -p<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u521b\u5efa\u6570\u636e\u5e93\uff1a<\/p>\n<pre>CREATE DATABASE example;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u521b\u5efa\u65b0\u7528\u6237\uff1a<\/p>\n<pre>CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u8d4b\u4e88\u6743\u9650\uff1a<\/p>\n<pre>GRANT ALL PRIVILEGES ON example.* TO 'user'@'localhost';\nFLUSH PRIVILEGES;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u516d\u3001\u6d4b\u8bd5\u548c\u8c03\u8bd5<\/p>\n<p>\u5b8c\u6210\u4ee5\u4e0a\u6b65\u9aa4\u540e\uff0c\u60a8\u7684CentOS\u670d\u52a1\u5668\u5df2\u642d\u5efa\u597dweb\u670d\u52a1\u5668\u3002\u60a8\u53ef\u4ee5\u5728\u6d4f\u89c8\u5668\u4e2d\u8bbf\u95ee\u670d\u52a1\u5668\u7684IP\u5730\u5740\uff0c\u5e94\u8be5\u80fd\u770b\u5230Apache\u9ed8\u8ba4\u9875\u9762\u3002<\/p>\n<p>\u5982\u679c\u51fa\u73b0\u4efb\u4f55\u95ee\u9898\uff0c\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u6cd5\u8fdb\u884c\u8c03\u8bd5\uff1a<\/p>\n<ol>\n<li>\n<p>\u67e5\u770bApache\u65e5\u5fd7<\/p>\n<pre>sudo tail -f \/var\/log\/httpd\/access_log\nsudo tail -f \/var\/log\/httpd\/error_log<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u67e5\u770bPHP\u9519\u8bef\u65e5\u5fd7<\/p>\n<pre>sudo tail -f \/var\/log\/httpd\/php_error_log<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<li>\n<p>\u67e5\u770bMySQL\u65e5\u5fd7<\/p>\n<pre>sudo tail -f \/var\/log\/mariadb\/mariadb.log<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/li>\n<\/ol>\n<p>\u4e03\u3001\u907f\u514d\u5e38\u89c1\u9519\u8bef<\/p>\n<p>\u5728\u642d\u5efaweb\u670d\u52a1\u5668\u8fc7\u7a0b\u4e2d\uff0c\u5bb9\u6613\u72af\u4e00\u4e9b\u5e38\u89c1\u9519\u8bef\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u9700\u8981\u6ce8\u610f\u7684\u5730\u65b9\uff1a<\/p>\n<ol>\n<li>\u6743\u9650\u95ee\u9898<\/li>\n<\/ol>\n<p>\u786e\u4fddApache\u53ca\u76f8\u5173\u6587\u4ef6\u5939\u548c\u6587\u4ef6\u7684\u6743\u9650\u8bbe\u7f6e\u6b63\u786e\u3002\u793a\u4f8b\uff1a<\/p>\n<pre>sudo chown -R apache:apache \/var\/www\/html\nsudo chmod -R 755 \/var\/www\/html<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u9632\u706b\u5899\u8bbe\u7f6e<\/li>\n<\/ol>\n<p>\u5982\u679c\u60a8\u7684\u670d\u52a1\u5668\u542f\u7528\u4e86\u9632\u706b\u5899\uff0c\u786e\u4fdd\u5df2\u6253\u5f00HTTP\u548cHTTPS\u670d\u52a1\u7aef\u53e3\u3002\u793a\u4f8b\uff1a<\/p>\n<pre>sudo firewall-cmd --zone=public --add-service=http --permanent\nsudo firewall-cmd --zone=public --add-service=https --permanent\nsudo firewall-cmd --reload<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ol>\n<li>\u6587\u4ef6\u8def\u5f84\u9519\u8bef<\/li>\n<\/ol>\n<p>\u5728\u914d\u7f6eApache\u548cPHP\u65f6\uff0c\u786e\u4fdd\u6587\u4ef6\u8def\u5f84\u7684\u6b63\u786e\u6027\u3002<\/p>\n<ol>\n<li>\u670d\u52a1\u672a\u542f\u52a8\u6216\u672a\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\u52a8<\/li>\n<\/ol>\n<p>\u786e\u4fddApache\u3001PHP\u3001MySQL\u7b49\u670d\u52a1\u5df2\u542f\u52a8\u5e76\u8bbe\u7f6e\u4e3a\u5f00\u673a\u81ea\u542f\u52a8\u3002<\/p>\n<p>\u7ed3\u8bed<\/p>\n<p>\u672c\u6587\u8be6\u7ec6\u4ecb\u7ecd\u4e86\u5728CentOS\u4e0a\u642d\u5efaweb\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u5e76\u63d0\u9192\u8bfb\u8005\u907f\u514d\u5e38\u89c1\u9519\u8bef\u3002\u5e0c\u671b\u8bfb\u8005\u53ef\u4ee5\u901a\u8fc7\u672c\u6587\u5f97\u5230\u5e2e\u52a9\uff0c\u987a\u5229\u642d\u5efa\u81ea\u5df1\u7684web\u670d\u52a1\u5668\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u638c\u63e1CentOS\u4e0a\u642d\u5efaweb\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u907f\u514d\u5e38\u89c1\u9519\u8bef\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u638c\u63e1\u4e0a\u642d\u5efaweb\u670d\u52a1\u5668\u7684\u65b9\u6cd5\uff0c\u907f\u514d\u5e38\u89c1\u9519\u8bef \u4f5c\u4e3a\u4e00\u6b3e\u5f00\u6e90\u7684\u64cd\u4f5c\u7cfb\u7edf\uff0cCentOS\u5728\u670d\u52a1\u5668\u9886\u57df\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\u3002\u642d\u5efaweb\u670d\u52a1\u5668\u662f\u4f7f\u7528CentOS\u7684\u5e38\u89c1\u9700\u6c42\u4e4b\u4e00\u3002\u672c\u6587\u5c06\u4ecb\u7ecd\u642d\u5efaweb\u670d\u52a1\u5668\u7684\u8be6\u7ec6\u65b9\u6cd5\uff0c\u5e76\u63d0\u9192\u8bfb\u8005\u907f\u514d\u5e38\u89c1\u9519\u8bef\u3002 \u4e00\u3001\u5b89\u88c5Apache Apache\u662f\u4e00\u6b3e\u5f3a\u5927\u800c\u7a33\u5b9a\u7684web\u670d\u52a1\u5668\u8f6f\u4ef6\uff0c\u4f7f\u7528\u5e7f\u6cdb\u3002\u6211\u4eec\u9996\u5148\u8981\u5b89\u88c5Apache\u3002 \u5728\u7ec8\u7aef\u8f93\u5165\u4ee5\u4e0b\u547d\u4ee4\u5b89\u88c5Apache\uff1a sudo yum install httpd \u767b\u5f55\u540e\u590d\u5236 \u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u542f\u52a8Apache\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\u52a8\uff1a sudo systemctl start httpd sudo systemctl enable httpd \u767b\u5f55\u540e\u590d\u5236 \u4e8c\u3001\u914d\u7f6eApache \u5b89\u88c5\u5b8c\u6210\u540e\uff0c\u6211\u4eec\u9700\u8981\u8fdb\u884cApache\u7684\u914d\u7f6e\u3002\u6253\u5f00Apache\u914d\u7f6e\u6587\u4ef6\uff1a sudo vi \/etc\/httpd\/conf\/httpd.conf \u767b\u5f55\u540e\u590d\u5236 \u4ee5\u4e0b\u4e3a\u4e00\u4e9b\u5e38\u89c1\u914d\u7f6e\u9879\u53ca\u5176\u793a\u4f8b\uff1a \u76d1\u542c\u7aef\u53e3 Listen 80 \u767b\u5f55\u540e\u590d\u5236 \u7f51\u7ad9\u6839\u76ee\u5f55 DocumentRoot &#8220;\/var\/www\/html&#8221; &lt;directory&gt; AllowOverride None Require all granted &lt;\/directory&gt; \u767b\u5f55\u540e\u590d\u5236 \u8bbe\u7f6e\u9ed8\u8ba4\u9875\u9762 DirectoryIndex index.html index.php \u767b\u5f55\u540e\u590d\u5236 \u8bbe\u7f6e\u865a\u62df\u4e3b\u673a &lt;virtualhost&gt; DocumentRoot &#8220;\/var\/www\/html\/example&#8221; ServerName example.com &lt;\/virtualhost&gt; \u767b\u5f55\u540e\u590d\u5236 [&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-16761","post","type-post","status-publish","format-standard","hentry","category-os"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/16761","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=16761"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/16761\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=16761"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=16761"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=16761"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}