Linux:Linux 操作系统,本文以 CentOS 8.4 为例。
Nginx:Web 服务器,本文以 Nginx 1.18 为例。
mariadb:数据库,本文以 mariadb 10.4 为例。
PHP:脚本语言,本文以 PHP 7.4 为例。

1.1 Mariadb

添加源

vim /etc/yum.repos.d/MariaDB.repo ##新建配置文件 
##将一下文件复制进去 # MariaDB 10.4 CentOS repository list - created 2020-06-01 04:02 UTC # http://downloads.mariadb.org/mariadb/repositories/ [mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.4/centos8-amd64 module_hotfixes=1 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1 

保存退出后执行dnf install

sudo dnf install MariaDB-server sudo systemctl start mariadb 

执行以下命令,进入 MariaDB。

mysql 

执行以下命令,创建 MariaDB 数据库。例如 “wordpress”。

CREATE DATABASE wordpress; 

执行以下命令,创建一个新用户。例如 “user”,登录密码为 123456。

CREATE USER 'user'@'localhost' IDENTIFIED BY '123456'; 

执行以下命令,赋予用户对 “wordpress” 数据库的全部权限。

GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost' IDENTIFIED BY '123456'; 

可以不用设置root账户登录密码
然后更新配置退出。

FLUSH PRIVILEGES; \q 

1.2 Nginx

dnf -y install http://nginx.org/packages/centos/8/x86_64/RPMS/nginx-1.18.0-1.el8.ngx.x86_64.rpm 

可以去http://nginx.org/packages/centos/8/x86_64/RPMS/?spm=a2c4g.11186623.2.31.557423bfYPMd6u获取最新的包名并安装
查看版本

nginx -v 

修改配置

cd /etc/nginx/conf.d
cp default.conf default.conf.bak
执行以下命令,打开 default.conf 文件。
vim default.conf
修改配置为下

server { listen 80; root /usr/share/nginx/html; server_name localhost; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; # location / { index index.php index.html index.htm; } #error_page 404 /404.html; #redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } 

注意fastcgi_pass和/etc/php-fpm.d/www.conf一致,取127.0.0.1:9000;

按照腾讯云SSL配置文档进行,下载证书并配置,具体配置可以看下方的配置详情。

修改/etc/nginx/nginx.conf中头的大小限制。

client_max_body_size 100m; 

另外还要修改/etc/php.ini文件,见后文。

最后我的配置default.conf配置如下,还配置了http转https、rewrite /wordpress / permanent;等,修改了server_name的配置。

server { listen 443 ssl; server_name *.sidney-tan.com; ssl_certificate sidney-tan.com_bundle.crt; ssl_certificate_key sidney-tan.com.key; ssl_session_timeout 5m; ssl_protocols TLSv1.2 TLSv1.3; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; ssl_prefer_server_ciphers on; rewrite /wordpress / permanent; #charset koi8-r; #access_log /var/log/nginx/log/host.access.log main; root /usr/share/nginx/html/wordpress; location / { index index.php index.html index.htm; } #error_page 404 /404.html; #redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/html; } #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # location ~ .php$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } } server { listen 80; server_name *.sidney-tan.com; return 301 https://$host$request_uri; } 

1.3 PHP的安装和配置

dnf -y install epel-release dnf update epel-release dnf clean all dnf makecache dnf module enable php:7.4 dnf install php php-curl php-dom php-exif php-fileinfo php-fpm php-gd php-hash php-json php-mbstring php-mysqli php-openssl php-pcre php-xml libsodium php -v 
systemctl start php-fpm systemctl enable php-fpm 
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php 
http://云服务器实例的公网 IP/index.php 

修改文件为nginx的user和group

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

搜索user以及grooup,把apache改为nginx

修改/etc/php.ini文件,最后的extension,然后重启php

[gd] ; Tell the jpeg decode to ignore warnings and try to create ; a gd image. The warning will then be displayed as notices ; disabled by default ; http://php.net/gd.jpeg-ignore-warning ;gd.jpeg_ignore_warning = 1 ; extension = /usr/lib64/php/modules/gd.so 

修改/etc/nginx/nginx.conf中头的大小限制。

client_max_body_size 100m; 

打开后/etc/php.ini文件,找到并设置以下选项的值:

upload_max_filesize = 100M post_max_size = 105M memory_limit = 128M max_execution_time = 30 max_input_time = 60 

2.1 下载wordpress

rm -rf /usr/share/nginx/html/index.php cd /usr/share/nginx/html wget https://cn.wordpress.org/wordpress-5.0.4-zh_CN.tar.gz #可以去官网找最新版 tar zxvf wordpress-5.0.4-zh_CN.tar.gz 

2.2 修改wordpress配置文件

cd /usr/share/nginx/html/wordpress cp wp-config-sample.php wp-config.php vim wp-config.php 

配置文件修改为:

 // ** MySQL settings - You can get this info from your web host ** // /** The name of the database for WordPress */ define('DB_NAME', 'wordpress'); /** MySQL database username */ define('DB_USER', 'user'); /** MySQL database password */ define('DB_PASSWORD', '123456'); /** MySQL hostname */ define('DB_HOST', 'localhost'); 

为了支持更新插件和素材,需要在此文件中再添加一下配置:

if ( !defined('ABSPATH') ) define('ABSPATH', dirname(__FILE__) . '/'); define('WP_TEMP_DIR', ABSPATH.'wp-content/tmp'); define("FS_METHOD", "direct"); define("FS_CHMOD_DIR", 0777); define("FS_CHMOD_FILE", 0777); define('ALLOW_UNFILTERED_UPLOADS', true); 

并且修改wordpress文件夹为nginx可以访问的权限

chown -R nginx:nginx /usr/share/nginx/html/wordpress 

url/wp-login.php去登录
注意后台设置url要设置成真实的url。

原文链接:https://blog.csdn.net/t624124600/article/details/123766386?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522166666867416800186565180%2522%252C%2522scm%2522%253A%252220140713.130102334.pc%255Fblog.%2522%257D&request_id=166666867416800186565180&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2~blog~first_rank_ecpm_v1~times_rank-17-123766386-null-null.nonecase&utm_term=wordpress

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注