Computer >> Hướng Dẫn Máy Tính >  >> Kết Nối Mạng >> Internet

Cách chuyển WordPress từ Localhost lên Production Server

WordPress là CMS phổ biến nhất thế giới. Từ blog cá nhân đến ecommerce phức tạp – chứng minh được sức mạnh. Nhiều dev tạo web WordPress trên localhost/PC cá nhân, hoàn thiện dev → chuyển lên live server public.

Nếu bạn thuộc nhóm này và đã xong dev localhost, đây là các bước chuyển WordPress từ localhost lên live server.

Lưu ý: Có plugin tự động hóa quy trình. Hướng dẫn này cover bước thủ công không cần plugin.

Tạo database mới trên live server

Host có cPanel → đăng nhập cPanel → "MySQL databases" section Databases.

  1. Ô "New database": đặt tên database → "Create Database". Cửa sổ mới → "Go back".
  2. Tạo user database: điền username, password mạnh → "Create user". Ghi nhớ user/pass – cần sau. "Go back".
  3. Add user to database: kéo xuống "Add user to database", chọn user vừa tạo từ dropdown user, chọn database vừa tạo từ dropdown database → "Add".
  4. Cửa sổ mới: tick "All Privileges" → "Make changes". "Go Back".
  5. Kiểm tra database chứa user vừa tạo. Xong → Home góc trên trái.

Di chuyển database từ localhost

  1. Localhost: mở phpMyAdmin (hoặc tool quản lý DB khác).
  2. Tìm database WordPress.
  3. Chọn database → cuộn xuống → "Check all".
  4. Dropdown "Select with" → chọn "Export".
  5. Màn hình tiếp: format SQL → "Go". Lưu file export đuôi .sql.

Import database

  1. Quay cPanel live server → Databases → "phpMyAdmin".
  2. Bên trái: list database. Click database vừa tạo đầu tutorial → "Import".
  3. Điều hướng file .sql trên máy local → import.
  4. OK → về phpMyAdmin main screen. Xong migrate DB lên live server.

Chuyển file localhost lên cPanel

  1. Localhost: file manager → thư mục WordPress (chứa wp-admin, wp-content, wp-includes). Nén toàn bộ folder WordPress thành file zip.
  2. cPanel live server: "File Manager" section Files. "Document root for" → chọn domain cần chuyển web → "Go".
  3. Đảm bảo "public_html" chọn bên trái → "Upload".
  4. Điều hướng file zip → upload. Xong → link "Back to".
  5. File zip hiển thị trong "public_html". Không thấy → "Refresh".
  6. Chọn file zip → "Extract" góc trên trái. Xong extract → xóa file zip.

Chỉnh sửa file wp-config

Bước cuối: sửa wp-config.php đổi toàn bộ setting localhost → production.

  1. Quay "public_html" File Manager. Chọn "wp-config.php" → "code editor".
  2. Thay database name = tên DB tạo ở cPanel. Đổi "DB_USER" và "DB_PASSWORD" = user/pass tạo trước.
  3. Kiểm tra "WP_HOME" và "WP_SITEURL". Nếu không có → thêm vào wp-config.php:
define('WP_HOME','https://your-live-url.com'); define('WP_SITEURL','https://your-live-url.com');

Nhớ đổi "your-live-url" thành domain thực tế.

  1. Lưu wp-config.php → thoát.

Gõ domain trình duyệt → site nên up và chạy. Duyệt mọi trang, login admin panel kiểm tra. Nếu lỗi → tham khảo tutorial troubleshoot WordPress.

Kết luận

Hướng dẫn toàn diện, có vẻ rối. Nhưng lặp 1-2 lần → dễ theo dõi cho mọi cài đặt WordPress. Phương pháp này khuyến nghị khi database không quá lớn.