wordpress搭建博客

前排提醒

由于本人的服务器只有1G内存,但是mysql启动就占用500M,系统占用500M,导致wordpress计划流产。

Abstract

本文将记录本人使用wordpress搭建博客的流程。

0. Requirements

系统:Ubuntu 22.04
根据wordpress官网指引,需要如下软件支持:

  • PHP version 7.4 or greater.
  • MySQL version 8.0 or greater OR MariaDB version 10.4 or greater.
  • HTTPS support

对于数据库,本人使用MySQL,http服务器选择nginx。

1. 安装php和mysql

本来预备安装最新版php,结果发现需要自己构建,就只能从apt安装。

apt install php8.1
apt install php-fpm

mysql官方提供了deb包,所以本人从mysql官方下载:
https://dev.mysql.com/downloads/mysql/
我安装了8.4.0 LTS版,需要下载以下几个包:

mysql-common_8.4.0-1ubuntu22.04_amd64.deb
mysql-community-client-plugins_8.4.0-1ubuntu22.04_amd64.deb
mysql-community-client-core_8.4.0-1ubuntu22.04_amd64.deb
mysql-community-client_8.4.0-1ubuntu22.04_amd64.deb
mysql-client_8.4.0-1ubuntu22.04_amd64.deb
mysql-community-server-core_8.4.0-1ubuntu22.04_amd64.deb
mysql-community-server_8.4.0-1ubuntu22.04_amd64.deb

并按顺序安装,因为互相之间有依赖关系。安装命令是:

apt install ./xxx.deb

安装完成后,查看mysql状态,为running:

systemctl status mysql

2. 创建数据库

本节参考:https://developer.wordpress.org/advanced-administration/before-install/creating-database/
wordpress的博客,评论等都保存在mysql数据库中,我们创建一个专门给wordpress用的数据库。
下面mysql中的命令里小写字母都是可以自己修改的,我的数据库名字叫了wordpress,用户名也叫了wordpress,自己可以修改,hstname一般就写localhost

$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \\g.  
Your MySQL connection id is 5340 to server version: 3.23.54  

Type 'help;' or '\\h' for help. Type '\\c' to clear the buffer.  

mysql> CREATE DATABASE databasename;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE USER "wordpressusername"@"hostname" IDENTIFIED BY "password";
mysql> GRANT ALL PRIVILEGES ON databasename.* TO "wordpressusername"@"hostname";
Query OK, 0 rows affected (0.00 sec)

mysql> FLUSH PRIVILEGES; 
Query OK, 0 rows affected (0.01 sec)

mysql> EXIT
Bye

此处友情提醒一下,mysql的语句都是要分号结尾的,你不要没写分号结果发现回车不会执行到处开始搜索

另外插播一句,如果你刚才安装MySQL时没有设置密码,你需要先设置root密码,至于怎么修改,敬请必应。

3. 安装wordpress

从网站下载并解压wordpress:https://cn.wordpress.org/download/releases/
截止发稿时,本人可下载的最新版本是:wordpress-6.5.3-zh_CN.tar.gz

打开wordpress文件夹,复制一份配置文件:

cp wp-config-sample.php wp-config.php

修改数据库账号名称,用户名,密码

vim wp-config.php

然后回到你的工作目录(注意不是wordpress所在的目录)。新建www文件夹用来存放wordpress网页内容,新建conf/nginx.conf用来配置nginx。本人将wordpress下的所有文件单独拷贝了一份过去到www

nginx.conf部分配置如下:

server {
		# access_log /home/ubuntu/site/blog/log/nginx/access.log;
		# error_log /home/ubuntu/site/blog/log/nginx/error.log;
		listen 8080;
		location / {
		    root /home/ubuntu/site/blog/www;  # 指定哪个目录作为Http文件服务器的根目录
		    charset utf-8; # 防止文件乱码显示, 如果用utf-8还是乱码,就改成gbk试试
		}
	}

然后开启nginx:

nginx -p $(pwd) -c conf/nginx.conf

这里需要配置nginx正确加载php
开启后,用浏览器访问:

http://xx.xxx.xxx.xxx:8080/wp-admin/install.php
posted @ 2024-06-02 20:25  王冰冰  阅读(15)  评论(2编辑  收藏  举报