CentOS7 配置PHP-FPM + Nginx部署 WordPress 项目

上传文件

  • 使用sftp
    # 连接到远程服务器
    sftp root@123.57.xxx.xx
    
    # 切换到home目录
    cd /home
    
    # 创建web目录用于存放项目文件
    mkdir web
    
    # 上传项目文件
    put D:\Doc\项目文件 [target_path]
    
    # 更多: -help
    
  • 解压文件
    cd /home/web # 切换到存放路径
    tar -xvzf 项目文件 # 解压文件 (*.tar.gz文件)
    tar -xvf 项目文件 # 解压 (*.tar文件)
    
  • 使用vim编辑文件
    vim test.c # 创建test.c
    Shift+i # INSERT 模式
    Esc # 到命令模式
    u # 撤销
    :wq # 保存退出
    :q! # 强制退出
    
    # 更多: https://www.runoob.com/linux/linux-vim.html
    

数据库安装

Centos 7

安装配置

# 获取yum资源包
wget https://repo.mysql.com//mysql80-community-release-el7-3.noarch.rpm

 #-i:安装、-v:显示安装过程、-h:显示安装进度
rpm -ivh mysql80-community-release-el7-3.noarch.rpm

# 升级所有包同时升级软件和系统内核
yum -y update

# 安装MySQL服务
yum -y install mysql-server

mysql

  • 数据库配置
    # 初始化
    mysqld --initialize
    
    # 为MySQL数据目录分配相应权限, -R 指目录下所有
    chown -R mysql:mysql /var/lib/mysql
    
    vim /etc/my.cnf
    [mysqld]
    
    datadir=/var/lib/mysql
    socket=/var/lib/mysql/mysql.sock
    
    # 日志
    log-error=/var/log/mysqld.log
    pid-file=/var/run/mysqld/mysqld.pid
    
    # 跳过DNS解析,MySQL授权列表中HOST字段将不能使用主机名、域名,只能使用IP
    skip-name-resolve
    
    # 设置sql-mode,可解决sql导入时: ERROR 1067 (42000): Invalid default value for 'xxxxxx'
    sql-mode=STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION
    
  • 启动mysql服务

    systemctl start mysqld

使用MySQL

  • 在日志中获取到初始密码 (/var/log/mysql.log)
    password

  • 进入mysql

    mysql -uroot -p

  • 更改密码(此处为SQL语句,注意" ; ")

    ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY '新密码';
    

关于Navicat连接问题

  • lost connection to mysql server at ‘waiting for initial communication packet’

    vim /etc/my.cnf # 打开MySQL配置文件
    
    # 在[mysqld]下添加以下字段; 是MySQL跳过DNS解析,可提高响应速度
    skip-name-resolve
    

    注:进行此设置后MySQL访问授权列表中HOST字段将不能使用主机名、域名,只能使用IP

  • mysql:Can’t connect to MySQL server (10060)
    在阿里云防火墙添加规则
    连接

Windows下安装MySQL

https://blog.csdn.net/qq_42766994/article/details/89401754#MySQL_80_20

PHP-FPM + Nginx部署

php7 安装配置

  • 安装php 7.2及必需扩展
    yum -y install yum-utils
    yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm
    yum-config-manager --enable remi-php72
    yum install php-cli php-fpm php-mysql php-json php-opcache php-mbstring php-xml php-gd php-curl
    
  • 修改php-fpm配置 (FPM: FastCGI进程管理器 )

    vim /etc/php-fpm.d/www.conf

    user = nginx
    group = nginx
    listen = 127.0.0.1:9000
    ;listen = /var/run/php-fpm/www.sock ; 使用unix套接字
    listen.owner = nginx
    listen.group = nginx
    
  • 启用php-fpm服务
    systemctl enable php-fpm # 设置为开机自启动
    systemctl start php-fpm # 启动该服务
    

nginx 安装配置

  • 安装nginx

    yum -y install nginx

  • 配置nginx

    vim /etc/nginx/conf.d/config.conf

    server 
    {
    	listen 80;
    	server_name 123.57.xxx.xx xxx.com www.xxx.com;
    
    	# 将http访问重定向为https
    	return 301 https://xxx.com$request_uri;
    }
    
    server
    {
    	listen 443 ssl http2;
    	server_name xxx.com;
    
    	# 项目根目录
    	root /home/web/xxxxxx;
    	index index.php;
    
    	# SSL配置
    	ssl_certificate /etc/ssl/xxx.com/*.pem; # 公钥
    	ssl_certificate_key /etc/ssl/xxx.com/*.key; # 私钥
    
    	# 日志配置
    	access_log /home/web/xxxxxx/nginx.access.log;
    	error_log /home/web/xxxxxx/nginx.error.log;
    
    	location ~ \.php$ {
    		try_files $uri = 404;
    		
    		fastcgi_pass 127.0.0.1:9000;
    		# fastcgi_pass unix:/var/run/php-fpm/www.sock;
    		fastcgi_index index.php;
    		fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    		include fastcgi_params;
    	}
    	
    	location / {
    		try_files $uri $uri/ /index.php?$args;
    	}
    	
    	location = /favicon.ico {
    		log_not_found off;
    		access_log off;
    	}
    
    	location = /robots.txt {
    		allow all;
    		log_not_found off;
    		access_log off;
    	}
    	
    	location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
    		expires max;
    		log_not_found off;
    	}
    
    	# 配置验证文件访问(Let's Encrypt验证服务)
    	location ^~ /.well-known/acme-challenge/ {
            alias /etc/ssl/challenges/;
            try_files $uri =404;
        }
    }
    
  • 检查配置语法

    nginx -t

  • 权限分配

    chown -R root:nginx /var/lib/php
    chown -R nginx: /home/web/xxxxxx
    
  • 使用nginx服务

    systemctl start nginx # 启动
    systemctl restart nginx # 重启
    systemctl stop nginx # 停止
    

SSL证书

  • 申请及相关配置:https://blog.csdn.net/qq_42766994/article/details/104580107
  • 关于WordPress使用https访问
    /* 在文件wp-config.php末尾添加,强制https配置 */
    define('FORCE_SSL_LOGIN', true);
    define('FORCE_SSL_ADMIN', true);
    
  • 注意修改数据库wp_options表中siteurl和home值
  • 若是从http转为https,数据库中存在http的链接需运行如下sql语句,这样资源文件才不会访问不了
    update wp_posts set post_content = replace(post_content, 'http://xxx.com','https://xxx.com');
    

注:配置及日志路径

  • 配置
    MySQL配置:
    	/etc/my.cnf
    PHP-FPM配置:
    	/etc/php-fpm.d/www.conf
    Nginx配置:
    	/etc/nginx/conf.d/config.conf
    
  • 日志
    MySQL日志:
    	/var/log/mysqld.log
    Nginx代理日志:
    	/home/web/xxxxxx/nginx.access.log
    	/home/web/xxxxxx/nginx.error.log;
    

参考链接
sftp:https://blog.csdn.net/cen50958/article/details/89503723
vim:https://www.runoob.com/linux/linux-vim.html
mysql:https://www.runoob.com/mysql/mysql-install.html
sql_mode:https://blog.csdn.net/wyzxg/article/details/8787878
connect1:https://blog.csdn.net/Architect_CSDN/article/details/90785478
connect2:https://www.cnblogs.com/flzs/p/10161969.html
权限问题:https://blog.csdn.net/syr1136877833/article/details/85854262
部署:https://linuxize.com/post/how-to-install-wordpress-with-nginx-on-centos-7/#prerequisites
WordPress使用https参考:https://ws234.com/344.html

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值