#重构#64MB内存安装WordPress(Caddy/PHP7.0/Sqlite)

2019年2月8日19:56:24 2 2,605 views

简介

2017年写过一篇64MB搭建Wordpress文章,当时使用的是Lighttpd/SQLite/PHP5,今年换上比较流行的Caddy+PHP7再来水一篇文章。

系统:Debian-8.0-x86_64-minimal

前妻准备

更新系统,加上源(Debian8无法直接安装PHP7)

echo "deb http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list
echo "deb-src http://packages.dotdeb.org jessie all" >> /etc/apt/sources.list
wget https://www.dotdeb.org/dotdeb.gpg
apt-key add dotdeb.gpg
apt-get update && apt-get upgrade
reboot

安装PHP/Sqlite/Caddy

安装Sqlite

apt-get install sqlite #安装Sqlite

安装Caddy这里使用逗比脚本

wget -N --no-check-certificate https://raw.githubusercontent.com/ToyoDAdoubiBackup/doubi/master/caddy_install.sh && chmod +x caddy_install.sh && bash caddy_install.sh

安装PHP7:

apt-get install php7.0-fpm php7.0-cgi php7.0-sqlite3 php7.0-curl php7.0-gd php7.0-mbstring php7.0-mcrypt php7.0-xml php7.0-xmlrpc php7.0-zip php7.0-opcache -y
sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/' /etc/php/7.0/cgi/php.ini

配置Caddy

目录:/usr/local/caddy/,新建文件名为:Caddyfile

编辑它:

www.zai.ge {
    redir https://zai.ge{url}
    }
zai.ge {
    root /home/wwwroot/zaige
    tls [email protected]
    gzip
    fastcgi / /run/php/php7.0-fpm.sock php
 rewrite {
  if {path} not_match ^\/wp-admin
  to {path} {path}/ /index.php?{query}
}
}

解释一下:

第一段:www.zai.ge是跳转到https://zai.ge

下面:

root 是网站根目录

tls 是是否自动配置Lets SSL证书

fastcgi 是配置PHP

rewrite 是Wordpress的伪静态。

重启Caddy

/etc/init.d/caddy restart

配置WP

1、下载WP

apt-get install unzip
cd /home/wwwroot/zaige
wget http://cn.wordpress.org/latest-zh_CN.zip
unzip *.zip
mv wordpress/* ./
rm -rf *.zip wordpress

2、使WP可以使用Sqlite

wget https://downloads.wordpress.org/plugin/sqlite-integration.1.8.1.zip
unzip *.zip
mv sqlite-integration wp-content/plugins
cp wp-content/plugins/sqlite-integration/db.php wp-content
rm *.zip

3、修改WordPress配置文件:

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

4、把下面几行注释或删除掉:

define('DB_NAME', 'database_name_here');
define('DB_USER', 'username_here');
define('DB_PASSWORD', 'password_here');
define('DB_HOST', 'localhost');

5、替换或加上

define('DB_FILE', '64mb');
define('DB_DIR', '/home/wwwroot/zaige/db');

6、修改权限

chmod -R 755 /home/wwwroot/zaige
chown www-data:www-data -R /home/wwwroot/zaige

Caddy说明

启动:/etc/init.d/caddy start
停止:/etc/init.d/caddy stop
重启:/etc/init.d/caddy restart
查看状态:/etc/init.d/caddy status
查看Caddy启动日志:tail -f /tmp/caddy.log
安装目录:/usr/local/caddy
Caddy配置文件位置:/usr/local/caddy/Caddyfile
Caddy自动申请SSL证书位置:/.caddy/acme/acme-v01.api.letsencrypt.org/sites/xxx.xxx(域名)/

后记

经测试没有Swap运行WP特别特别死,经常502

参考:https://www.moerats.com/archives/651/

  • Line群组
  • 阔乐博客Line群了解一下
  • weinxin
  • Telegram群组
  • Telegram群了解一下
  • weinxin

广告位招募               加入TG群组

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:2   其中:访客  1   博主  1

    • avatar 初见 0

      有个错别字

        • avatar CokeMine Admin

          @初见 最近头昏眼花,宽容一下 :shock: