环境:
Ubuntu 24.04
PHP 8.1.2-1ubuntu2.18
Nginx/1.18.0 (Ubuntu)
WordPress 6.6.1
Mysql 8
文章目录
- 1. 安装php
- 2. 配置nginx
- 2.1. 安装nginx
- 2.2. 配置
- 3. 下载wordpress
- 3.1. 配置wordpress
- 4. mysql配置wordpress数据库和用户
- 4.1. 安装和远程连接
- 4.2. 创建wordpress数据库和用户
- 5. 访问wordpress
1. 安装php
sudo apt-get update
sudo apt-get install php-fpm php-mysql -y
# 查看版本
php -v
# PHP 8.1.2 (cli) (built: Jun 13 2024 15:23:20) (NTS)
# 查看php*-fpm.sock 文件名称
ls /run/php/
# php8.1-fpm.pid php8.1-fpm.sock php-fpm.sock
这个路径后面需要填入nginx配置
/run/php/php8.1-fpm.sock
2. 配置nginx
2.1. 安装nginx
sudo apt-get nginx -y
# 重启
systemctl reload nginx
访问 localhost:80 出现Welcome to nginx页面即可
2.2. 配置
# 创建wordpress.conf配置文件
vim /etc/nginx/conf.d/wordpress.conf
填入以下内容
server {
# 端口自填
listen 8081;
listen [::]:8081;
server_name www.wordpress wordpress;
# 解压的wordpress文件路径
root /var/www/html/wordpress/;
index index.php index.html index.htm index.nginx-debian.html;
# 文件上传大小限制
client_max_body_size 500M;
location / {
try_files $uri $uri/ /index.php;
}
location ~ \.php$ {
# 配置php*-fpm.sock 文件路径
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
include snippets/fastcgi-php.conf;
}
# A long browser cache lifetime can speed up repeat visits to your page
location ~* \.(jpg|jpeg|gif|png|webp|svg|woff|woff2|ttf|css|js|ico|xml)$ {
access_log off;
log_not_found off;
expires 360d;
}
}
nginx -t
# 重启
systemctl reload nginx
3. 下载wordpress
官网链接
cd /var/www/html
wget https://cn.wordpress.org/latest-zh_CN.zip
unzip latest-zh_CN.zip
ls
# index.nginx-debian.html latest-zh_CN.zip wordpress
# 需要给予文件写入的权限,默认的用户是www-data
sudo chown -R www-data /var/www/html/wordpress
3.1. 配置wordpress
cd /var/www/html/wordpress
cp wp-config-sample.php wp-config.php
vim wp-config.php
修改DB_NAME、DB_USER、DB_PASSWORD、DB_HOST
/** 数据库名 */
define( 'DB_NAME', 'wordpress' );
/** wordpress的mysql用户 */
define( 'DB_USER', 'wordpress' );
/** Database password */
define( 'DB_PASSWORD', 'wordpress' );
/** Database hostname */
define( 'DB_HOST', 'localhost' );
/** 假设端口不是3306,可以添加:port*/
/** define( 'DB_HOST', '127.0.0.1:3307' ); */
4. mysql配置wordpress数据库和用户
4.1. 安装和远程连接
# 安装mysql
sudo apt install mysql -y
# 修改远程连接,注释掉 bind-address = 127.0.0.1
vim /etc/mysql/mysql.conf.d/mysqld.cnf
# 如果要修改密码强度
validate_password.policy=LOW
validate_password.length=4
validate_password.number_count=0
validate_password.special_char_count=0
validate_password.mixed_case_count=0
# 重启
systemctl restart mysql
进入数据库
mysql -u root -p
查看root的host
use mysql;
select user,host from user;
修改root的host为%
update user set host='%' where user='root' and host='localhost';
flush privileges
4.2. 创建wordpress数据库和用户
CREATE DATABASE wordpress;
ALTER USER 'wordpress'@'%' IDENTIFIED BY 'wordpress';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wordpress'@'%' WITH GRANT OPTION;
FLUSH PRIVILEGES;
5. 访问wordpress
http://localhost:8081
附:修改上传文件大小限制
完结 撒花!