安装 常用软件
yum -y updateyum -y install vim tar wget zip unzip net-tools
yum 安装 nginx
yum -y install nginxsystemctl start nginx.servicesystemctl enable nginx.service
firewall-cmd --zone=public --add-port=80/tcp --permanentfirewall-cmd --reload
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-fpmsystemctl start php-fpm.servicesystemctl 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
内容如下:
phpinfo()
重新加载 nginx 配置
systemctl reload nginx.service
yum 安装 mysql
yum -y install https://repo.mysql.com//mysql80-community-release-el8-4.noarch.rpmyum -y install mysql-community-serversystemctl start mysqld.servicesystemctl enable mysqld.service
查看初始密码
grep 'temporary password' /var/log/mysqld.log
结果如下:
[root@openEuler nginx]# grep 'temporary password' /var/log/mysqld.log2022-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 --permanentfirewall-cmd --reload
PHP 连接 mysql
yum -y install php-mysqlnd
编写php文件db.php
vim /usr/share/nginx/html/db.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
来源地址:https://blog.csdn.net/qq_24330181/article/details/126450060