前言
今天把在虚拟主机上面的wordpress博客转移到VPS上面了
因为域名是CC,无法备案,不能在国内。所以弄了香港的VPS。折腾了大半天
从升级虚拟主机,到换VPS
也因为实在是受不了网站加载 Waiting (TTFB) 加载速度了。点一个页面要2-5秒。
测速全红,记录下坑
系统:Linux debian 8.0
平台:Wordpress 4.9.0
插件:memcache,autoptmize
迁移后效果图
安装步骤
http://soft.vpser.net/lnmp/lnmp1.2-full.tar.gz && tar zxf lnmp1.2-full.tar.gz && cd lnmp1.2-full && ./install.sh lnmp
按上述命令执行后,会出现如下提示:
+------------------------------------------------------------------------+ | LNMP V1.2 for Ubuntu Linux Server, Written by Licess | +------------------------------------------------------------------------+ | A tool to auto-compile & install LNMP/LNMPA/LAMP on Linux | +------------------------------------------------------------------------+ | For more information please visit http://www.lnmp.org | +------------------------------------------------------------------------+ Please setup root password of MySQL.(Default password: root) Please enter: ---------------------
需要设置MySQL的root密码(不输入直接回车将会设置为root),输入后回车进入下一步,如下图所示:
Do you want to enable or disable the InnoDB Storage Engine? Default enable,Enter your choice [Y/n]:
这里需要确认是否启用MySQL InnoDB,如果不确定是否启用可以输入 y ,输入 y 表示启用,输入 n 表示不启用。默认为y 启用,输入后回车进入下一步,选择MySQL版本:
You have 5 options for your DataBase install. 1: Install MySQL 5.1.73 2: Install MySQL 5.5.42 (Default) 3: Install MySQL 5.6.23 4: Install MariaDB 5.5.42 5: Install MariaDB 10.0.17 Enter your choice (1, 2, 3, 4 or 5):
输入MySQL或MariaDB版本的序号,回车进入下一步,选择PHP版本:
You have 5 options for your PHP install. 1: Install PHP 5.2.17 2: Install PHP 5.3.29 3: Install PHP 5.4.41 (Default) 4: Install PHP 5.5.25 5: Install PHP 5.6.9 Enter your choice (1, 2, 3, 4 or 5):
输入PHP版本的序号,回车进入下一步,选择是否安装内存优化:
You have 3 options for your Memory Allocator install. 1: Don't install Memory Allocator. (Default) 2: Install Jemalloc 3: Install TCMalloc Enter your choice (1, 2 or 3):
可以选择不安装、Jemalloc或TCmalloc,输入对应序号回车。
如果是LNMPA或LAMP的话还需要设置管理员邮箱,再选择Apache版本
提示”Press any key to install…or Press Ctrl+c to cancel”后,按回车键确认开始安装。 LNMP脚本就会自动安装编译Nginx、MySQL、PHP、phpMyAdmin、Zend Optimizer这几个软件。
============================== Check install ============================== Checking ... Nginx: OK MySQL: OK PHP: OK PHP-FPM: OK +------------------------------------------------------------------------+ | LNMP V1.2 for Ubuntu Linux Server, Written by Licess | +------------------------------------------------------------------------+ | For more information please visit http://www.lnmp.org | +------------------------------------------------------------------------+ | lnmp status manage: lnmp {start|stop|reload|restart|kill|status} | +------------------------------------------------------------------------+ | phpMyAdmin: http://IP/phpmyadmin/ | | phpinfo: http://IP/phpinfo.php | | Prober: http://IP/p.php | +------------------------------------------------------------------------+ | Add VirtualHost: lnmp vhost add | +------------------------------------------------------------------------+ | Default directory: /home/wwwroot/default | +------------------------------------------------------------------------+ | MySQL/MariaDB root password: root | +------------------------------------------------------------------------+ +-------------------------------------------+ | Manager for LNMP, Written by Licess | +-------------------------------------------+ | http://lnmp.org | +-------------------------------------------+ nginx (pid 31181 31179) is running... php-fpm is runing! * MySQL running (31504) Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:3306 0.0.0.0:* LISTEN tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN tcp6 0 0 :::22 :::* LISTEN
安装时间可能会几十分钟到几个小时不等,主要是机器的配置网速等原因会造成影响。
如果显示Nginx: OK,MySQL: OK,PHP: OK
并且Nginx、MySQL、PHP都是running,80和3306端口都存在,并Install lnmp V1.2 completed! enjoy it.的话,说明已经安装成功。
添加虚拟主机
执行:lnmp vhost add 出现如下界面:
root@host:~/lnmp1.2-full# lnmp vhost add +-------------------------------------------+ | Manager for LNMP, Written by Licess | +-------------------------------------------+ | http://lnmp.org | +-------------------------------------------+ Please enter domain(example: www.lnmp.org): 265android.com ====================================== Your domain: 265android.com ====================================== Do you want to add more domain name? (y/n) y Enter domain name(example: lnmp.org *.lnmp.org): www.265android.com domain list: www.265android.com Please enter the directory for the domain: 265android.com (Default directory: /home/wwwroot/265android.com): Virtual Host Directory: /home/wwwroot/265android.com =========================== Allow Rewrite rule? (y/n) =========================== y Please enter the rewrite of programme: wordpress,discuz,typecho,sablog,dabr rewrite was exist. (Default rewrite: other):wordpress =========================== You choose rewrite=wordpress =========================== =========================== Allow access_log? (y/n) =========================== n ====================================================== Create database and MySQL user with same name (y/n) ====================================================== y verify your current MySQL root password: root MySQL root password correct. Enter database name: root Your will create a database and MySQL user with same name: root Please enter password for mysql user root: root Your password: root ====================================================== Create ftp account (y/n) ====================================================== y Enter ftp account name: user Enter password for ftp account user: user Press any key to start create virtul host...
上面这部可能会出错。我这里提示MYSQL ROOT密码不对。
自己进入MYSQL在重置一下密码
mysql> use mysql; delete from mysql.user where user='';//删除用户为空的用户,我这里出现了2个 mysql> update user set password=password('123') where user='root'; mysql> flush privileges;
安装完成后FTP没有安装上。
在lnmp目录下:./pureftpd.sh
按提示输入当前MySQL的root密码,输入完成,回车确认,会提示如下信息:
这一步是设置FTP用户管理后台的登陆密码。输入完成回车确认
因为PHP管理后台需要连接数据库,所以会在MySQL上创建一个ftp用户,这里设置的就是这个用户的密码。输入完成,回车确认。
回车 显示 “Press any key to start install Pure-FTPd…” 再次回车确认即可开始安装。
FTP添加用户
lnmp ftp add
Enter ftp account name:登陆FTP的账户
Enter password for ftp account vpser:FTP密码
Enter directory for ftp account vpser:FTP分配的目录(或者直接跟根目录)/home/wwwroot/
继续折腾
到这里基本可以打开网站了,数据库或者FTP,直接把WORDPRESS的数据上传到FTP
但是加载WORDPRESS慢的问题还是没有解决。各种百度,GOOGLE,貌似WORDPRESS就是这个了样子
不开缓存好像都好慢。那就继续折腾吧
因为我安装的LNMP1.2版本。也仅适用于LNMP1.2、1.3及1.4等以后的版本
进入lnmp解压后的目录,执行:./addons.sh install eaccelerator
可以根据自己的需求选择php-memcache或php-memcached扩展,
这里我输入对应的序号2,回车,再次确认回车开始安装。
wordpress配置
1,下载 object-cache.php 文件,解压后上传至 /wp-content 目录
https://github.com/tollmanz/wordpress-pecl-memcached-object-cache/blob/master/object-cache.php
2,编辑 wp-config.php 文件,添加如下代码:define(‘ENABLE_CACHE’, true);
3,batcache1.4:https://downloads.wordpress.org/plugin/batcache.1.4.zip
batcache.php传至 /wp-content/plugins 目录
advanced-cache.php传至 /wp-content 目录
var $max_age = 300; // 缓存有效时间 (0关闭) var $remote = 0; // Zero disables sending buffers to remote datacenters (req/sec is never sent) var $times = 2; // 几次访问开启缓存 (2个以上) var $seconds = 120; // 多久生效 (0马上生效)
4,在线监控:http://pecl.php.net/get/memcache-3.0.8.tgz
$MEMCACHE_SERVERS[] = '127.0.0.1:11211'; //改一个,后面一条屏蔽
卸载方法
执行:./addons.sh uninstall memcached
autoptmize
官方插件搜索,开启HTML,CSS即可。立马见效。