前些日子我終于下定決心買 VPS,然后就把這個博客從虛擬主機上遷移過去,因為域名不變,只是換空間,所以大部分步驟是按 WordPress 提供的文檔操作,不過過程中碰上不少問題,最終且算是解決了,所以做一總結.
備份舊服務器上的數據庫,舊的虛擬主機上提供有 cPanel 界面,所以操作十分簡單,備份舊服務器上的文件,同樣可以借助 cPanel。
導入舊數據庫到新服務器,因為 VPS 上沒有 cPanel,所以數據庫的導入是通過命令行執行的.
首先通過 SSH 登錄到服務器,代碼如下:
ssh zfanw
然后執行 MySQL 命令:
[email protected]:mysql -u mysqlusername -p databaseName < Vevb.com.bak.sql
導入的過程非常快,如果不確信是否成功,可以執行 MySQL 命令查看:
use zfanwcom;
show tables;
結果如下:
- mysql> show tables;
- +---------------------------+
- | Tables_in_zfanwcom |
- +---------------------------+
- | wp_PopularPostsdata |
- | wp_commentmeta |
- | wp_comments |
- | wp_links |
- | wp_options |
- | wp_postmeta |
- | wp_posts |
- | wp_sucuri_lastlogins |
- | wp_term_relationships |
- | wp_term_taxonomy |
- | wp_terms |
- | wp_usermeta |
- | wp_users |
- +---------------------------+
復制舊文件到新服務器,數據庫導入完成后,將虛擬主機上備份的文件上傳到 VPS 并解壓到相應目錄.
解析域名,將域名重新解析到新的 IP 上.
錯誤情況,解析完成后訪問新 IP 上的博客,就出現了各種情況.
先來看下 /etc/apache2/vhosts.d/ 目錄下 Vevb.com.conf 這個虛擬主機文件的配置:
- <VirtualHost *:80>
- ServerName Vevb.com
- ServerAlias www.companysz.com
- ServerAdmin [email protected]
- DocumentRoot /srv/www/vhosts/Vevb.com
- <Directory "/srv/www/vhosts/Vevb.com">
- AllowOverride All
- Options FollowSymLinks
- Order allow,deny
- Allow from all
- </Directory>
- </VirtualHost>
我碰到的情況中,有一種錯誤是這樣,代碼如下:
- Object not found!
- The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.
- If you think this is a server error, please contact the webmaster.
- Error 404
- www.companysz.com
- Apache/2.4.6 (Linux/SUSE)
網上的資料有說是 .htaccess 文件的問題,因為我自定義了 WordPress 的固定鏈接,但我的 .htaccess 文件內容如下:
- # BEGIN WordPress
- <IfModule mod_rewrite.c>
- RewriteEngine On
- RewriteBase /
- RewriteRule ^index.php$ - [L]
- RewriteCond %{REQUEST_FILENAME} !-f
- RewriteCond %{REQUEST_FILENAME} !-d
- RewriteRule . /index.php [L]
- </IfModule>
- # END WordPress
這是 WordPress 默認的,另外,使用上一篇介紹的方法,可以看到我的服務器上已經安裝了 mod_rewrite 模塊.
我的情況下,問題出在 /etc/apache2/httpd.conf 文件,WordPress 說明如下:
- Your server may not have the AllowOverride directive enabled. If the AllowOverride directive is set to None in your Apache httpd.config file, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem. When this directive is set to All, then any directive which has the .htaccess Context is allowed in .htaccess files.
如果 Apache 的 httpd.conf (openSUSE 下安裝的 Apache 里配置文件是叫這個) 中 AllowOverride 被設置為 None,則 .htaccess 文件完全被忽視,所以我需要修改 httpd.conf 文件內容,結果如下:
- <Directory />
- Options FollowSymLinks
- AllowOverride All
- </Directory>
重啟 Apache 服務器:sudo rcapache2 restart
再度訪問博客,問題消失了,不過這篇是事后整理,碰上的許多枝末問題已經遺忘,不一定完整.
新聞熱點
疑難解答
圖片精選