{"id":184,"date":"2021-02-02T16:12:49","date_gmt":"2021-02-02T08:12:49","guid":{"rendered":"https:\/\/www.constantinefun.com\/?p=184"},"modified":"2022-02-28T12:35:41","modified_gmt":"2022-02-28T04:35:41","slug":"centos-stream-8-%e9%83%a8%e7%bd%b2-apache2-4php8mysql8%e7%8e%af%e5%a2%83","status":"publish","type":"post","link":"https:\/\/www.constantinefun.com\/?p=184","title":{"rendered":"CentOS Stream 8 \u90e8\u7f72 Apache2.4+PHP8+MySQL8\u73af\u5883"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u4e00\u3001\u786e\u4fdd\u60a8\u7684\u7cfb\u7edf\u662f\u6700\u65b0\u7684\u3002<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo clean all\nsudo dnf update\nsudo dnf install dnf-utils<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u3001Apache\u7684\u90e8\u7f72<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1\u3001Apache\u7684\u57fa\u7840\u5b89\u88c5\uff1a<\/h3>\n\n\n\n<p>\u5b89\u88c5Apache\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install httpd<\/code><\/pre>\n\n\n\n<p>\u542f\u52a8\u670d\u52a1\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\u52a8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable --now httpd<\/code><\/pre>\n\n\n\n<p>\u68c0\u67e5\u670d\u52a1\u72b6\u6001\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status httpd<\/code><\/pre>\n\n\n\n<p>\u67e5\u770b\u706b\u5899\u4fe1\u606f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --list-all<\/code><\/pre>\n\n\n\n<p>\u914d\u7f6ehttp\u548chttps\u9632\u706b\u5899\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --permanent --add-service=http\nsudo firewall-cmd --permanent --add-service=https<\/code><\/pre>\n\n\n\n<p>\u5237\u65b0\u9632\u706b\u5899\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo firewall-cmd --reload<\/code><\/pre>\n\n\n\n<p>\u6d4f\u89c8\u5668\u8f93\u5165\u670d\u52a1\u5668ip:80,\u51fa\u73b0\u6d4b\u8bd5\u9875\u5373\u6807\u5fd7\u914d\u7f6e\u6210\u529f<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2\u3001Apache\u81ea\u5b9a\u4e49\u8bbe\u7f6e\uff1a<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>\u6ce8\uff1a<\/li><li>1\u3001vi\/vim\u547d\u4ee4\u53ef\u53c2\u8003\u83dc\u9e1f\u6559\u7a0b\uff1a<a rel=\"noreferrer noopener\" href=\"https:\/\/www.runoob.com\/linux\/linux-vim.html\" target=\"_blank\">https:\/\/www.runoob.com\/linux\/linux-vim.html<\/a><\/li><li>2\u3001\u65e0\u7279\u6b8a\u8981\u6c42\u53ef\u53ea\u4fee\u6539\u53d1\u5e03\u6587\u4ef6\uff0c\u5176\u4f59\u4e0d\u4fee\u6539\u3002<\/li><li>3\u3001\u9ed8\u8ba4\u4e3b\u9875\u4f4d\u4e8e\/var\/www\/html\u4e0b<\/li><li>4\u3001\u4ee5\u4e0b\u8bbe\u7f6e\u5747\u53ef\u5c06\/etc\/httpd\/conf\/httpd.conf\u6587\u4ef6\u62f7\u8d1d\u51fa\u6765\u7528\u8bb0\u4e8b\u672c\u4e00\u7c7b\u7684\u8f6f\u4ef6\u8fdb\u884c\u4fee\u6539\uff0c\u4fee\u6539\u5b8c\u6210\u62f7\u56de\u540e\uff0c\u91cd\u542f\u670d\u52a1\u3002<\/li><\/ul>\n\n\n\n<p><strong>1\u3001Apache\u7aef\u53e3\u4fee\u6539\uff08\u5efa\u8bae\u4f7f\u7528\u9ed8\u8ba4\u7aef\u53e3\uff09\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/httpd\/conf\/httpd.conf<\/code><\/pre>\n\n\n\n<p>\u5728Listen 80\u524d\u52a0#\u5728\u4e0b\u4e00\u884c\u52a0\u4e0aListen \u4f60\u8981\u6539\u7684\u7aef\u53e3\uff0c\u4fdd\u5b58\u9000\u51fa\u6587\u4ef6\uff0c\u66f4\u65b0\u9632\u706b\u5899\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>firewall-cmd --permanent --add-port=\u4f60\u4fee\u6539\u7684\u7aef\u53e3\/tcp\nfirewall-cmd --reload<\/code><\/pre>\n\n\n\n<p>\u6dfb\u52a0\u9ed8\u8ba4\u7aef\u53e3\u4e4b\u5916\u7684\u7aef\u53e3\uff0c\u67e5\u8be2\u9ed8\u8ba4\u652f\u6301\u7684\u7aef\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>semanage port -l | grep http<\/code><\/pre>\n\n\n\n<p>\u82e5\u6ca1\u6709\u4f60\u6dfb\u52a0\u7684\u7aef\u53e3\uff0c\u624b\u52a8\u6dfb\u52a0\u7aef\u53e3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>semanage port -a -t \u3000http_port_t -p tcp \u4f60\u8981\u6dfb\u52a0\u7684\u7aef\u53e3<\/code><\/pre>\n\n\n\n<p>\u91cd\u542f\u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart httpd<\/code><\/pre>\n\n\n\n<p><strong>2\u3001\u9ed8\u8ba4\u53d1\u5e03\u6587\u4ef6\u4fee\u6539\uff08\u53ef\u4ee5\u6dfb\u52a0\u5176\u4ed6\u7684\u7c7b\u578b\uff0c\u4f46\u4e00\u5b9a\u8981\u52a0\u4e0aindex.php\uff09\uff1a<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim \/etc\/httpd\/conf\/httpd.conf<\/code><\/pre>\n\n\n\n<p>\u627e\u5230\u4e0b\u5217\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;IfModule dir_module&gt;\n    DirectoryIndex index.html\n&lt;\/IfModule&gt;\n<\/code><\/pre>\n\n\n\n<p>\u5728index.html\u524d\u52a0\u4e0aindex.php<\/p>\n\n\n\n<p>\u91cd\u542f\u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>systemctl restart httpd<\/code><\/pre>\n\n\n\n<p><strong>3.\u9ed8\u8ba4\u53d1\u5e03\u76ee\u5f55\u4fee\u6539<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>vim\u3000\/etc\/httpd\/conf\/httpd.conf<\/code><\/pre>\n\n\n\n<p>\u627e\u5230\u4e0b\u5217\u5185\u5bb9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DocumentRoot \"\/var\/www\/html\"\n<\/code><\/pre>\n\n\n\n<p>\u5728\u5176\u524d\u9762\u52a0#\u5e76\u5728\u4e0b\u4e00\u884c\u6dfb\u52a0\u5982\u4e0b\u5185\u5bb9\uff08\u6ce8\u610f\u8981\u5148\u521b\u5efa\u76ee\u5f55\uff0c\u5e76\u4e14\u5206\u914d775\u6743\u9650\uff09\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>DocumentRoot \"\u4fee\u6539\u7684\u76ee\u5f55\"\n&lt;Directory \"\u4fee\u6539\u7684\u76ee\u5f55\"&gt;\n        Require all granted\n&lt;\/Directory&gt;\n<\/code><\/pre>\n\n\n\n<p>\u91cd\u542f\u670d\u52a1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>semanage fcontext -a -t httpd_sys_content_t '\u4f60\u7684\u76ee\u5f55(\/.*)?'\nrestorecon -RvvF \u4f60\u7684\u76ee\u5f55\nsystemctl restart httpd<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e09\u3001PHP8\u90e8\u7f72<\/h2>\n\n\n\n<p>PHP 8.0\u5728\u60a8\u9700\u8981\u5b89\u88c5Remi\u5b58\u50a8\u5e93\u7684\u9ed8\u8ba4\u5b58\u50a8\u5e93\u4e2d\u4e0d\u53ef\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install http:\/\/rpms.remirepo.net\/enterprise\/remi-release-8.rpm<\/code><\/pre>\n\n\n\n<p>\u91cd\u7f6e\u6a21\u5757\u5e76\u542f\u7528PHP 8.0\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf module reset php\nsudo dnf module install php:remi-8.0<\/code><\/pre>\n\n\n\n<p>\u5b89\u88c5PHP 8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install php<\/code><\/pre>\n\n\n\n<p>\u67e5\u770bPHP\u7684\u7248\u672c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>php -v<\/code><\/pre>\n\n\n\n<p>\u5b89\u88c5PHP 8\u6269\u5c55\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install php-(\u62d3\u5c55\u540d\u5b57)<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc\u6211\u53ea\u5b89\u88c5\u4ee5\u4e0b\u62d3\u5c55\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install php-{common,mysqlnd,xml,xmlrpc,curl,gd,imagick,cli,fpm,mbstring,opcache,zip}<\/code><\/pre>\n\n\n\n<p>\u542f\u52a8\u670d\u52a1\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\u52a8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable php-fpm\nsudo systemctl start php-fpm\nsudo systemctl status php-fpm<\/code><\/pre>\n\n\n\n<p>\u5728Apache\u5b89\u88c5\u7684\u4e3b\u9875\u9ed8\u8ba4\u76ee\u5f55\u4e0b\u521b\u5efaindex.php\u6587\u4ef6\u5185\u5bb9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;?php\nphpinfo();\n?&gt;<\/code><\/pre>\n\n\n\n<p>\u8bbf\u95ee\u4e3b\u9875\uff0c\u51fa\u73b0php\u4fe1\u606f\u9875\u9762\u5373\u914d\u7f6e\u5b8c\u6210\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u56db\u3001MySQL8\u7684\u90e8\u7f72<\/h2>\n\n\n\n<p>\u5b89\u88c5MySQL8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo dnf install @mysql<\/code><\/pre>\n\n\n\n<p>\u542f\u52a8\u670d\u52a1\u5e76\u8bbe\u7f6e\u5f00\u673a\u81ea\u542f\u52a8\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl enable --now mysqld<\/code><\/pre>\n\n\n\n<p>\u68c0\u67e5\u670d\u52a1\u72b6\u6001\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo systemctl status mysqld<\/code><\/pre>\n\n\n\n<p>\u6dfb\u52a0\u5bc6\u7801\u53ca\u5b89\u5168\u8bbe\u7f6e\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>\u8fd0\u884cmysql_secure_installation\u811a\u672c\uff1a<\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>sudo mysql_secure_installation<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\"><li>\u51fa\u73b0\u4e0b\u9762\u4ee3\u7801<br><code>VALIDATE PASSWORD COMPONENT can be used to test passwords<\/code> <code>and improve security. It checks the strength of password<\/code> <code>and allows the users to set only those passwords which are<\/code> <code>secure enough. Would you like to setup VALIDATE PASSWORD component?<\/code> <br><code>Press y|Y for Yes, any other key for No:<\/code><\/li><li>\u914d\u7f6eVALIDATE PASSWORD component\uff08\u9a8c\u8bc1\u5bc6\u7801\u7ec4\u4ef6\uff09\uff1a\u8f93\u5165y<\/li><li>\u56de\u8f66\u8fdb\u5165\u8be5\u914d\u7f6e\uff1a<br><code>There are three levels of password validation policy:<\/code><br><br><code>LOW Length &gt;= 8<\/code><br><code>MEDIUM Length &gt;= 8, numeric, mixed case, and special characters<\/code><br><code>STRONG Length &gt;= 8, numeric, mixed case, special characters and dictionary file <\/code><br><code>Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:<\/code><\/li><li>\u9009\u62e9\u5bc6\u7801\u9a8c\u8bc1\u7b56\u7565\u7b49\u7ea7\uff0c\u6211\u8fd9\u91cc\u9009\u62e90\uff08low\uff09\uff1a\u8f93\u51650<\/li><li>\u56de\u8f66\uff1a<br><code>Please set the password for root here.<br>New password:<\/code><\/li><li>\u8f93\u5165\u65b0\u5bc6\u7801\uff0c\u56de\u8f66\uff1a\uff08\u8981\u6c42\u8981\u5339\u914d\u4f60\u9009\u62e9\u5bc6\u7801\u9a8c\u8bc1\u7b56\u7565\u7b49\u7ea7\uff09<br><code>Re-enter new password:<\/code><\/li><li>\u518d\u6b21\u8f93\u5165\u521a\u521a\u7684\u5bc6\u7801\uff0c\u56de\u8f66\uff1a<br><code>Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :<\/code><\/li><li>\u786e\u8ba4\u662f\u5426\u7ee7\u7eed\u4f7f\u7528\u63d0\u4f9b\u7684\u5bc6\u7801\uff1f\u8f93\u5165y\uff0c\u56de\u8f66\uff1a<br><code>By default, a MySQL installation has an anonymous user,allowing anyone to log into MySQL without having to havea user account created for them. This is intended only fortesting, and to make the installation go a bit smoother.You should remove them before moving into a production<\/code> <code>environment.<\/code><br><br><code>Remove anonymous users? (Press y|Y for Yes, any other key for No) :<\/code><\/li><li>\u79fb\u9664\u533f\u540d\u7528\u6237\uff1f\u63a8\u8350\u8f93\u5165y\uff0c\u56de\u8f66\uff1a<br><code>Normally, root should only be allowed to connect from<\/code> <code>'localhost'.This ensures that someone cannot guess at<\/code> <code>the root password from the network.<\/code><br><br><code>Disallow root login remotely? (Press y|Y for Yes, any other key for No) :<\/code><\/li><li>\u4e0d\u5141\u8bb8root\u8fdc\u7a0b\u767b\u9646\uff1f\u5982\u679c\u9700\u8981\u8fdc\u7a0b\u767b\u9646\uff0c\u8f93\u5165n\uff0c\u56de\u8f66\uff1a<br><code>\u2026 skipping.<\/code><br><code>By default, MySQL comes with a database named 'test' that<\/code> <code>anyone can access. This is also intended only for testing,and should be removed before moving into a production<\/code> <code>environment.<br><\/code><br><code>Remove test database and access to it? (Press y|Y for Yes, any other key for No) : <\/code><\/li><li>\u79fb\u9664test\u6570\u636e\u5e93\uff1f\u79fb\u9664\u8f93\u5165y\uff0c\u4e0d\u79fb\u9664\u8f93\u5165n\uff0c\u56de\u8f66\uff1a<br><code>\u2026 skipping.<br>Reloading the privilege tables will ensure that all changes<br>made so far will take effect immediately.<\/code><br><code><br>Reload privilege tables now? (Press y|Y for Yes, any other key for No) :<\/code><\/li><li>\u91cd\u65b0\u8f7d\u5165\u6743\u9650\u8868\uff1f\u8f93\u5165y\uff0c\u56de\u8f66\uff1a\u51fa\u73b0\u4e0b\u9762\u5185\u5bb9\u5373\u5b8c\u6210\uff01<br><code>Success.<br>All done!<\/code><\/li><\/ul>\n\n\n\n<p>\u5230\u6b64\u5168\u90e8\u5b89\u88c5\u5df2\u5b8c\u6210<\/p>\n\n\n\n<p><br><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u3001\u786e\u4fdd\u60a8\u7684\u7cfb\u7edf\u662f\u6700\u65b0\u7684\u3002 \u4e8c\u3001Apache\u7684\u90e8\u7f72 1\u3001Apache\u7684\u57fa\u7840\u5b89\u88c5\uff1a \u5b89\u88c5Apache\uff1a \u542f\u52a8\u670d\u52a1 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24,35,25,23,37,21],"tags":[36],"class_list":["post-184","post","type-post","status-publish","format-standard","hentry","category-apache","category-linux","category-mysql","category-php","category-37","category-21","tag-centos-stream-8--apache2-4php8mysql8"],"_links":{"self":[{"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=\/wp\/v2\/posts\/184","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=184"}],"version-history":[{"count":15,"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions"}],"predecessor-version":[{"id":201,"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=\/wp\/v2\/posts\/184\/revisions\/201"}],"wp:attachment":[{"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=184"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=184"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.constantinefun.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=184"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}