• openEuler yum 安装 LNMP 环境


    安装 常用软件

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

    yum 安装 nginx

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

    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
    
    • 1

    配置 nginx 支持 PHP

    yum -y install php-fpm
    systemctl start php-fpm.service
    systemctl enable php-fpm.service
    
    • 1
    • 2
    • 3

    修改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;
            }
        }
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
    • 54
    • 55
    • 56
    • 57
    • 58
    • 59

    编写 PHP 测试页面

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

    内容如下:

    
    	phpinfo()
    
    • 1
    • 2

    重新加载 nginx 配置

    systemctl reload nginx.service
    
    • 1

    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
    
    • 1
    • 2
    • 3
    • 4

    查看初始密码

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

    结果如下:

    [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
    
    • 1
    • 2

    使用初始密码登录

    mysql -uroot -p
    
    • 1

    修改密码

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

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

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

    退出系统

    exit;
    
    • 1

    重启 mysql 服务

    systemctl restart mysqld.service
    
    • 1

    测试登录

    mysql -h 127.0.0.1 -uroot -p
    
    • 1

    防火墙放行

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

    PHP 连接 mysql

    yum -y install php-mysqlnd
    
    • 1

    编写php文件db.php

    vim /usr/share/nginx/html/db.php
    
    • 1
    
    $servername = "localhost";
    $username = "root";
    $password = "Lihaozhe!!@@1122";
    
    try {
                $conn = new PDO("mysql:host=$servername;", $username, $password);
                    echo "连接成功";
    }
    catch(PDOException $e)
    {
                echo $e->getMessage();
    }
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    systemctl restart php-fpm
    
    • 1

    PDO

  • 相关阅读:
    面试中的MySQL主从复制|手撕MySQL|对线面试官
    (未学懂,待填坑)【数据结构】哈夫曼树
    axios配置封装
    假期get新技能?低代码模型应用工具HuggingFists
    QT使用xml流QXmlStreamReader快速读取与QXmlStreamWriter写入xml文件
    C/C++程序设计和预处理
    合并 K 个升序链表
    音响是如何把微弱声音放大呢
    群晖-使用docker套件部署Prometheus+Grafana
    基于深度学习的表格检测与识别技术的优势
  • 原文地址:https://blog.csdn.net/qq_24330181/article/details/126450060