CentOS7下nginx+php8.1+mysql8.0安装

更新yum
yum update

安装yum-utils
yum install yum-utils

1、安装nginx

获取比较新的nginx的yum源数据
rpm -Uvh http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

安装nginx
yum install nginx

启动nginx
systemctl start nginx

设置nginx服务器开机自启动
systemctl enable nginx

检查开机自动是否设置成功
systemctl list-dependencies | grep nginx

2、安装PHP8.1

安装EPEL源:
yum install epel-release

安装REMI源:
yum install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

yum repolist all |grep php
yum-config-manager --disable remi-php*
yum-config-manager --enable remi-php81

安装PHP
yum install php-cli php-fpm php-mysqlnd php-zip php-gd php-mbstring php-curl php-xml php-json

配置PHP
vi /etc/php-fpm.d/www.conf
user = nginx
group = nginx
;php_admin_value[error_log] = /var/log/php-fpm/www-error.log

vi /etc/php.ini
error_log = _error.log

php -v #查看版本
systemctl enable php-fpm #开启开机自启
systemctl start php-fpm #启动
systemctl restart php-fpm #重启
systemctl stop php-fpm #关闭
systemctl status php-fpm #检查状态

3、集成NGINX+PHP
vi /etc/nginx/conf.d/default.conf

server {
  server_name domain.com www.domain.com;

  location / {
    root /www/htdocs;
    index index.php index.html index.htm;
  }

  location ~ \.php$ {
    root /www/htdocs;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_index index.php;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
  }

  error_page 404 /404.html;
  location = /404.html {
  }

  error_page 500 502 503 504 /50x.html;
  location = /50x.html {
  }

  listen 443 ssl;
  ssl_certificate /etc/nginx/certs/domain.com/cert.pem;
  ssl_certificate_key /etc/nginx/certs/domain.com/key.pem;
}

server {
  if ($host = www.domain.com) {
    return 301 https://$host$request_uri;
  }

  listen 80;
  server_name domain.com www.domain.com;
  
  #return 444;
}

4、安装mysql8.0

卸载MariaDB
rpm -qa | grep mariadb
rpm -e mariadb-libs-5.5.68-1.el7.x86_64
rpm -qa | grep mariadb

在MySQL官网中获取YUM源rpm包地址
https://dev.mysql.com/downloads/repo/yum/

更新YUM源
wget https://dev.mysql.com/get/mysql80-community-release-el7-6.noarch.rpm

yum localinstall mysql80-community-release-el7-6.noarch.rpm
yum clean all
yum makecache

更新mysql的rpm签名
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022

安装mysql
yum install mysql-community-server

编辑配置
vi /etc/my.cnf

启动mysql
service mysqld start

查看初始登录密码
cat /var/log/mysqld.log | grep password

登录
mysql -uroot -p

修改密码
ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_PASSWORD';
FLUSH PRIVILEGES;

设置自动启动
systemctl enable mysqld

参考:
https://www.cnblogs.com/jinpingzhao/p/12695435.html
https://blog.csdn.net/chipiaobai6529/article/details/100934021
https://www.cnblogs.com/skyblue123/p/13287028.html