安装 常用软件

yum -y update
yum -y install vim tar wget zip unzip net-tools

yum 安装 nginx

yum -y install nginx
systemctl start nginx.service
systemctl enable nginx.service
firewall-cmd --zone=public --add-port=80/tcp --permanent
firewall-cmd --reload 

openEuler nginx

yum 安装 PHP8

yum -y install  php-cli php-fpm php-mysqlnd php-zip php-devel php-gd php-mbstring php-curl php-xml php-pear php-bcmath php-json php-redis  --skip-broken

配置 nginx 支持 PHP

yum -y install php-fpm
systemctl start php-fpm.service
systemctl enable php-fpm.service

修改PHP配置文件如下:

events {
    worker_connections 1024;
}http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';    access_log  /var/log/nginx/access.log  main;    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 4096;    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
    include /etc/nginx/conf.d/*.conf;    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;
    # for more information.
    include /etc/nginx/conf.d/*.conf;    server {
        listen       80;
        listen       [::]:80;
        server_name  _;
        root         /usr/share/nginx/html;        # Load configuration files for the default server block.
        include /etc/nginx/default.d/*.conf;        error_page 404 /404.html;
            location = /40x.html {
        }        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
        # 该部分为后追加的整合配置
        location ~ \.php$ {
                root           html;
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
                include        fastcgi_params;
        }
    }
}

编写 PHP 测试页面

vim /usr/share/nginx/html/phpinfo.php

内容如下:

<?php
	phpinfo()

重新加载 nginx 配置

systemctl reload nginx.service

phpinfo

yum 安装 mysql

yum -y install https://repo.mysql.com//mysql80-community-release-el8-4.noarch.rpm
yum -y install mysql-community-server
systemctl start mysqld.service
systemctl enable mysqld.service

查看初始密码

grep 'temporary password' /var/log/mysqld.log

结果如下:

[root@openEuler nginx]#  grep 'temporary password' /var/log/mysqld.log
2022-08-21T05:38:36.448107Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: g.h*q/zFy5!k

使用初始密码登录

mysql -uroot -p

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'Lihaozhe!!@@1122';
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Lihaozhe!!@@1122';
FLUSH PRIVILEGES;

设置root用户远程客户端访问

update mysql.user set host = '%',plugin='mysql_native_password' where user='root';
FLUSH PRIVILEGES;

退出系统

exit;

重启 mysql 服务

systemctl restart mysqld.service

测试登录

mysql -h 127.0.0.1 -uroot -p

防火墙放行

firewall-cmd --zone=public --add-port=3306/tcp --add-port=33060/tcp --permanent
firewall-cmd --reload 

PHP 连接 mysql

yum -y install php-mysqlnd

编写php文件db.php

vim /usr/share/nginx/html/db.php
<?php
$servername = "localhost";
$username = "root";
$password = "Lihaozhe!!@@1122";try {
            $conn = new PDO("mysql:host=$servername;", $username, $password);
                echo "连接成功";
}
catch(PDOException $e)
{
            echo $e->getMessage();
}
systemctl restart php-fpm

PDO

点赞(0) 打赏

Comment list 共有 0 条评论

暂无评论

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部