一些主機間遷移 WordPress 的操作流程和注意事項。
從 FTP 遍歷下載代碼
遞歸下載根目錄所有內容
Shell
wget -rm -nH ftp://user:password@example.com/
參數 -r 表示遞歸, -m 開啓鏡像 (複製文件的元數據), -nH 表示不把文件保存到主機名對應的路徑下。 (不加的話,會建立一個名為 example.com 的文件夾,然後把下載的文件放到裏面。)
下載某個子目錄的內容
Shell
wget -rm -nH --cut-dirs=3 ftp://example.com/path/to/dir/
參數 --cut-dirs 表示從路徑中切除前三段 (本例中為 path/to/dir ) 。 (不加的話,會嚴格按照服務器用户相對路徑在本機建立對應文件夾。)
下載時使用絕對路徑
Shell
wget -rm -nH ftp://user:password@example.com//usr/share/nginx/path/to/file/
多加一個 / 就可以使用絕對路徑。
導出 MySQL 數據庫
只需要導出在 wp-config.php 中設置的數據庫即可。
命令行方式
Shell
mysqldump --databases wp_somedb --result-file=backup.sql
GUI 方式
可以使用 Sequel Pro 等工具完成操作。
Nginx 基礎配置
WordPress(無任何緩存插件)+ Nginx + PHP5-FPM
Default
server {
listen 80;
listen
root /usr/share/nginx/example.com;
index index.php index.html index.htm;
server_name www.example.com;
# WordPress single blog rules.
# Designed to be included in any server {} block.
# This order might seem weird - this is attempted to match last if rules below fail.
# http://wiki.nginx.org/HttpCoreModule
location / {
try_files $uri $uri/ /index.php?$args;
}
# Add trailing slash to */wp-admin requests.
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
# Directives to send expires headers and turn off 404 error logging.
location ~* ^.+\.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|rss|atom|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf)$ {
access_log off; log_not_found off; expires max;
}
error_page 404 /404.html;
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/wordpress;
}
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass unix:/var/run/php5-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
非 www 到 www 域名的 301 跳轉
Default
server {
server_name example.com;
rewrite ^/(.*)$ http://www.example.com/$1 permanent;
}
修改文件權限
Shell
chown -R www-data:www-data /usr/share/nginx/example.com
find /usr/share/nginx/example.com -type d -exec chmod 755 {} \; # 把文件夾權限改為 rwxr-xr-x
find /usr/share/nginx/example.com -type f -exec chmod 644 {} \; # 把文件權限改為 rw-r--r--
導入 MySQL 數據庫
打開 MySQL 控制枱
Shell
mysql -u root -p
建立新數據庫
MySQL
CREATE DATABASE wp_somedb;
導入備份數據
MySQL
use wp_somedb;
source path/to/backup.sql;
建立用户並授予權限
MySQL
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON wp_somedb.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
修改 WordPress 配置
編輯 wp-config.php ,修改數據庫配置:
PHP
define('DB_NAME', 'wp_somedb');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'localhost');
保存即生效。
驗證 WordPress 狀態
編輯 wp-config.php ,修改 debug 配置:
PHP
define('WP_DEBUG', true);
然後訪問各頁面,看是否輸出錯誤信息。如有,檢查對應的代碼。最後別忘了把 debug 選項關掉。
其他步驟
Hardening WordPress – wordpress.org
Nginx – wordpress.org
遷移到 uWSGI – blog.phoenixlzx.com