mysql安装
1.1 安装MariaDB服务器软件包:
sudo apt install mariadb-server
sudo systemctl start mariadb
sudo systemctl status mariadb
sudo systemctl enable mariadb
1.2 默认情况下,MariaDB的root用户无密码;使用以下命令设置root密码:
sudo mysql_secure_installation
1.2.1 Switch to unix_socket authentication [Y/n]
询问您是否要切换到使用UNIX套接字文件进行身份验证,建议否。
如果输入"Y"并按下回车键,则MySQL将禁用密码身份验证,并支持UNIX套接字文件身份验证。这意味着只有本地用户(系统上的用户)才能访问MySQL服务器,而无法通过网络连接进行访问。这对于保护MySQL服务器安全性非常有用。
1.2.2 Change the root password? [Y/n]
询问您是否要更改MySQL root用户的密码。注意,默认情况下MySQL root用户没有密码,建议为其设置一个安全的密码以提高MySQL服务器的安全性。
1.2.3 Reload privilege tables now? [Y/n]
询问您是否要重新加载MySQL权限表。如果您进行了任何更改,则需要重新加载MySQL权限表才能使更改生效。
1.3 生成数据库与用户
1.3.0 生成数据库
CREATE DATABASE IF NOT EXISTS wordpress DEFAULT CHARACTER SET = utf8mb4 DEFAULT COLLATE = utf8mb4_general_ci;
1.3.1 输入以下命令创建一个数据库用户 wordpress
用来操作上面创建的 wordpress
数据库。你需要修改命令中的 {password}
为你自己的密码。
CREATE USER 'wordpress'@'localhost' IDENTIFIED BY '{password}';
1.3. 2 授予用户 wordpress
拥有数据库 wordpress
的所有权限:
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'localhost' WITH GRANT OPTION;
1.3.3 随后输入下面的命令刷新权限:
FLUSH PRIVILEGES;
1.3.4 最后,退出数据库:
exit
php及其扩展安装
apt install php-fpm php-mysql php-gd php-curl php-dom php-mbstring php-imagick php-zip
默认安装php7.4
下载wordpress源码
curl https://wordpress.org/latest.zip -o /var/www/latest.zip
cd /var/www
unzip wordpress.tar.gz
chown -R www-data:www-data /var/www/wordpress
nginx安装及其配置
安装nginx
apt update -y
apt install nginx -y
在/etc/nginx/conf.d目录下创建wordpress.conf文件,输入以下内容:
server {
listen 80;
listen [::]:80;
root /var/www/wordpress;
server_name example.com;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
return 301 https://$server_name$request_uri;
}
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
root /var/www/wordpress;
server_name example.com;
index index.php index.html index.htm;
ssl_protocols TLSv1 TLSv1.1 TLSv1.2 TLSv1.3;
ssl_certificate /xxx/xxx/example.pem; #修改你的证书目录
ssl_certificate_key /xxx/xxx/example.pem; #修改你的证书目录
location = /favicon.ico {
log_not_found off;
access_log off;
}
location = /robots.txt {
allow all;
log_not_found off;
access_log off;
}
location ~ /\. {
deny all;
}
location ~* /(?:uploads|files)/.*\.php$ {
deny all;
}
location / {
try_files $uri $uri/ /index.php?$args;
}
location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
expires max;
log_not_found off;
}
location /wordpress {
try_files $uri $uri/ /wordpress/index.php?$args;
}
location ~ \.php$ {
include fastcgi.conf;
fastcgi_pass unix:/var/run/php/php7.3-fpm.sock;
fastcgi_index index.php;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
}
配置nginx时注意伪静态配置,注意php版本
去掉“自豪地采用WordPress”
外观--编辑--页脚(footer.php),删除代码:
<a href="<?php echo esc_url( __( 'https://wordpress.org/', 'twentyfifteen' ) ); ?>" class="imprint">
<?php
/* translators: %s: WordPress */
printf( __( 'Proudly powered by %s', 'twentyfifteen' ), 'WordPress' );
?>
</a>
Comments | NOTHING