CentOS Stream 8 部署 Apache2.4+PHP8+MySQL8环境

一、确保您的系统是最新的。

sudo clean all
sudo dnf update
sudo dnf install dnf-utils

二、Apache的部署

1、Apache的基础安装:

安装Apache:

sudo dnf install httpd

启动服务并设置开机自启动:

sudo systemctl enable --now httpd

检查服务状态:

sudo systemctl status httpd

查看火墙信息:

sudo firewall-cmd --list-all

配置http和https防火墙:

sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https

刷新防火墙:

sudo firewall-cmd --reload

浏览器输入服务器ip:80,出现测试页即标志配置成功

2、Apache自定义设置:

  • 注:
  • 1、vi/vim命令可参考菜鸟教程:https://www.runoob.com/linux/linux-vim.html
  • 2、无特殊要求可只修改发布文件,其余不修改。
  • 3、默认主页位于/var/www/html下
  • 4、以下设置均可将/etc/httpd/conf/httpd.conf文件拷贝出来用记事本一类的软件进行修改,修改完成拷回后,重启服务。

1、Apache端口修改(建议使用默认端口):

vim /etc/httpd/conf/httpd.conf

在Listen 80前加#在下一行加上Listen 你要改的端口,保存退出文件,更新防火墙:

firewall-cmd --permanent --add-port=你修改的端口/tcp
firewall-cmd --reload

添加默认端口之外的端口,查询默认支持的端口:

semanage port -l | grep http

若没有你添加的端口,手动添加端口:

semanage port -a -t  http_port_t -p tcp 你要添加的端口

重启服务:

systemctl restart httpd

2、默认发布文件修改(可以添加其他的类型,但一定要加上index.php):

vim /etc/httpd/conf/httpd.conf

找到下列内容:

<IfModule dir_module>
    DirectoryIndex index.html
</IfModule>

在index.html前加上index.php

重启服务:

systemctl restart httpd

3.默认发布目录修改

vim /etc/httpd/conf/httpd.conf

找到下列内容:

DocumentRoot "/var/www/html"

在其前面加#并在下一行添加如下内容(注意要先创建目录,并且分配775权限):

DocumentRoot "修改的目录"
<Directory "修改的目录">
        Require all granted
</Directory>

重启服务:

semanage fcontext -a -t httpd_sys_content_t '你的目录(/.*)?'
restorecon -RvvF 你的目录
systemctl restart httpd

三、PHP8部署

PHP 8.0在您需要安装Remi存储库的默认存储库中不可用:

sudo dnf install http://rpms.remirepo.net/enterprise/remi-release-8.rpm

重置模块并启用PHP 8.0:

sudo dnf module reset php
sudo dnf module install php:remi-8.0

安装PHP 8:

sudo dnf install php

查看PHP的版本:

php -v

安装PHP 8扩展:

sudo dnf install php-(拓展名字)

这里我只安装以下拓展:

sudo dnf install php-{common,mysqlnd,xml,xmlrpc,curl,gd,imagick,cli,fpm,mbstring,opcache,zip}

启动服务并设置开机自启动:

sudo systemctl enable php-fpm
sudo systemctl start php-fpm
sudo systemctl status php-fpm

在Apache安装的主页默认目录下创建index.php文件内容如下:

<?php
phpinfo();
?>

访问主页,出现php信息页面即配置完成。

四、MySQL8的部署

安装MySQL8:

sudo dnf install @mysql

启动服务并设置开机自启动:

sudo systemctl enable --now mysqld

检查服务状态:

sudo systemctl status mysqld

添加密码及安全设置:

  • 运行mysql_secure_installation脚本:
sudo mysql_secure_installation
  • 出现下面代码
    VALIDATE PASSWORD COMPONENT can be used to test passwords and improve security. It checks the strength of password and allows the users to set only those passwords which are secure enough. Would you like to setup VALIDATE PASSWORD component?
    Press y|Y for Yes, any other key for No:
  • 配置VALIDATE PASSWORD component(验证密码组件):输入y
  • 回车进入该配置:
    There are three levels of password validation policy:

    LOW Length >= 8
    MEDIUM Length >= 8, numeric, mixed case, and special characters
    STRONG Length >= 8, numeric, mixed case, special characters and dictionary file
    Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG:
  • 选择密码验证策略等级,我这里选择0(low):输入0
  • 回车:
    Please set the password for root here.
    New password:
  • 输入新密码,回车:(要求要匹配你选择密码验证策略等级)
    Re-enter new password:
  • 再次输入刚刚的密码,回车:
    Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) :
  • 确认是否继续使用提供的密码?输入y,回车:
    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 environment.

    Remove anonymous users? (Press y|Y for Yes, any other key for No) :
  • 移除匿名用户?推荐输入y,回车:
    Normally, root should only be allowed to connect from 'localhost'.This ensures that someone cannot guess at the root password from the network.

    Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
  • 不允许root远程登陆?如果需要远程登陆,输入n,回车:
    … skipping.
    By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing,and should be removed before moving into a production environment.

    Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
  • 移除test数据库?移除输入y,不移除输入n,回车:
    … skipping.
    Reloading the privilege tables will ensure that all changes
    made so far will take effect immediately.


    Reload privilege tables now? (Press y|Y for Yes, any other key for No) :
  • 重新载入权限表?输入y,回车:出现下面内容即完成!
    Success.
    All done!

到此全部安装已完成


暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇