Pages

Friday, 27 November 2020

用sqlite作为wordpress的数据库,安装wordpress博客

 登陆linux vps.先安装nginx(或apache)和php.然后,

apt-get install -y php7.3-mysql php7.3-sqlite3

(安装这2个包,分别解决“Your PHP installation appears to be missing the MySQL extension which is required by WordPress.”问题 和 "PDO Driver for SQLite is missing"问题)

然后下载wordpress的源码包latest.zip到你指定的网站的根目录,比如/usr/local/nginx/html :

cd /usr/local/nginx/html

wget https://wordpress.org/latest.zip

unzip latest.zip

mv wordpress/* ./

rm -rf wordpress latest.zip

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

打开wp-config.php,修改以下配置

原始文件:

/** WordPress数据库的名称 */
define('DB_NAME', 'database_name_here');

/** MySQL数据库用户名 */
define('DB_USER', 'username_here');

/** MySQL数据库密码 */
define('DB_PASSWORD', 'password_here');

/** MySQL主机 */
define('DB_HOST', 'localhost');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');

/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');

修改为:

/** WordPress数据库的名称 */
define('DB_NAME', 'MyBlog');//MyBlog是数据库名,可以自定义

/** MySQL数据库用户名 */
define('DB_USER', '');

/** MySQL数据库密码 */
define('DB_PASSWORD', '');

/** MySQL主机 */
define('DB_HOST', 'localhost');

/** 创建数据表时默认的文字编码 */
define('DB_CHARSET', 'utf8');

/** 数据库整理类型。如不确定请勿更改 */
define('DB_COLLATE', '');

//define('WP_ALLOW_REPAIR', 'true'); //数据库修复时使用
define('DB_TYPE', 'sqlite');  
然后,下载db.php文件(https://github.com/aaemnnosttv/wp-sqlite-db/raw/master/src/db.php)到wp-content:
cd wp-content
wget https://github.com/aaemnnosttv/wp-sqlite-db/raw/master/src/db.php
chmod -R 777 /usr/local/nginx/html/

然后,在浏览器里,访问你的域名,即可成功安装wordpress博客。

插件项目地址:https://github.com/aaemnnosttv/wp-sqlite-db
https://github.com/aaemnnosttv/wp-sqlite-db/blob/master/src/db.php
插件下载地址:https://github.com/aaemnnosttv/wp-sqlite-db/raw/master/src/db.php
---------------------------------------------------

另外一种安装方法。

WordPress with SQLite


Officially, WordPress only supports MySQL, but with this plugin created by kjmtsh you can use SQLite instead.

The plugin was created a long time ago, but still works like a charm on the current latest WP version (v5.2 – Jun 2019).

This solution is not meant to be used in production for large websites, but it can be an interesting option if you have a small blog with few visitors. An SQLite version works better than MySQL on a server with very limited resources.

By the way, this blog runs on SQLite 

UPDATE Nov 2020: This blog used to run on WordPress and SQLite, but I have migrated it to VuePress.

TIP

To migrate an existing site, see instructions at the end.

 Step by Step

1. Download WordPress and SQLite Integration Plugin.

wget https://wordpress.org/latest.tar.gz

wget https://downloads.wordpress.org/plugin/sqlite-integration.1.8.1.zip

(如果哪天wordpress.org官方删除了sqlite-integration.1.8.1.zip文件,那么

git clone https://github.com/aaemnnosttv/wp-sqlite-integration sqlite-integration)

  

2. Extract files

tar xvf latest.tar.gz

unzip sqlite-integration.1.8.1.zip


3. Remove zip files (optional, for cleanup)

rm latest.tar.gz

rm sqlite-integration.1.8.1.zip

 

4. Move plugin to wp-content/plugins/:

mv wordpress/* ./

rm -rf wordpress

mv sqlite-integration wp-content/plugins/


5. Move db.php to wp-content:

mv wp-content/plugins/sqlite-integration/db.php wp-content/


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

7. Run the WP installer as usual.

Start webserver:

php -S 0.0.0.0:3000

    PHP Development Server started.

    Listening on http://0.0.0.0:3000

    Press Ctrl-C to quit.

Open the page (http://vps-public-ip:3000/) and proceed with the installation:

No need to provide database information (the step will be skipped) :


Migrating an existing website:

NO NEED to convert MySQL to SQLite. Just use Duplicator (or any other migration plugin).

Install a brand new copy of WordPress with SQLite, then:

Install Duplicator (https://wordpress.org/plugins/duplicator/)plugin on both websites (existing and brand new copy instances);

Do a backup of your existing website using Duplicator;

Restore the backup on the brand new instance using Duplicator’s "restore";

Done!

This tutorial on video (3 min, no sound):

 
from https://learnwithdaniel.com/2019/06/wordpress-with-sqlite/




No comments:

Post a Comment