Wordpress轉移

因為是用Docker佈建的

0. 先把舊站的cache/lazy load之類的停掉(不然cache會有舊站資訊)
1. 把/var/www/html的部分備份移至新地方(注意權限)
2. 把SQL的資料夾整個移到新地方(注意權限)
3. 在/var/www/html下面掛上phpmyadmin
4. 啟動docker
5. 設定phpmyadmin的database網址(修改config.inc.php中host的位置,查詢docker ip可以用
 
docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' container_name_or_container_id
 

這個指令)
6. 連進去phpmyadmin
7. 使用SQL指令修改


USE wordpress;
UPDATE wp_options SET option_value = replace(option_value, 'https://www.oldurl', 'https://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';
UPDATE wp_posts SET guid = replace(guid, 'https://www.oldurl','https://www.newurl');
UPDATE wp_posts SET post_content = replace(post_content, 'https://www.oldurl', 'https://www.newurl');
UPDATE wp_postmeta SET meta_value = replace(meta_value,'https://www.oldurl','https://www.newurl');
            
8. 在wp-config.php檔案內設定新網址
define('WP_SITEURL', 'http://www.newurl');
define('WP_HOME', 'http://www.newurl');
9. 然後理論上可以連進WP後台了,再到後台用插件工具(例如elementor)更新

補充:
PHP上傳預設是2M
所以要記得把PHP的設定一起轉移
先建立一個uploads.ini

file_uploads = On
memory_limit = 500M
upload_max_filesize = 30M
post_max_size = 30M
max_execution_time = 600


然後在docker-compose.yml修改

wordpress:
    volumes:
      - ./uploads.ini:/usr/local/etc/php/conf.d/uploads.ini

補充在Nginx當Reverse Proxy的話:

  location / {
        proxy_pass http://127.0.0.1:8000; # 注意這邊跟上面docker-compose設定的port相同
        add_header X-Frame-Options SAMEORIGIN;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_hide_header X-Frame-Options;
  }
  
補充:
如果前面有Nginx作LB的話,記得確認上傳檔案(Post Data)的大小也要跟著改,否則只改php是沒用的
server {
  client_max_body_size 30M;

  //other lines...
}
參考文獻:
https://xzos.net/docker-install-wordpress/
https://networker.tw/migrating-wordpress-website/
https://gordon168.tw/wordpress-how-to-migrate-or-change-url/
https://blog.yowko.com/container-ip/
https://www.chengxulvtu.com/how-to-resolve-the-error-that-exceed-upload_max_filesize-in-defined-in-php-ini/
https://softman.blog/2019/07/26/nginx-reverse-proxy-to-dockerized-wordpress-the-basic/comment-page-1/

留言

熱門文章