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.
- Ô "New database": đặt tên database → "Create Database". Cửa sổ mới → "Go back".
- Tạo user database: điền username, password mạnh → "Create user". Ghi nhớ user/pass – cần sau. "Go back".
- 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".
- Cửa sổ mới: tick "All Privileges" → "Make changes". "Go Back".
- 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
- Localhost: mở phpMyAdmin (hoặc tool quản lý DB khác).
- Tìm database WordPress.
- Chọn database → cuộn xuống → "Check all".
- Dropdown "Select with" → chọn "Export".
- Màn hình tiếp: format SQL → "Go". Lưu file export đuôi
.sql.
Import database
- Quay cPanel live server → Databases → "phpMyAdmin".
- Bên trái: list database. Click database vừa tạo đầu tutorial → "Import".
- Điều hướng file .sql trên máy local → import.
- OK → về phpMyAdmin main screen. Xong migrate DB lên live server.
Chuyển file localhost lên cPanel
- 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.
- cPanel live server: "File Manager" section Files. "Document root for" → chọn domain cần chuyển web → "Go".
- Đảm bảo "public_html" chọn bên trái → "Upload".
- Điều hướng file zip → upload. Xong → link "Back to".
- File zip hiển thị trong "public_html". Không thấy → "Refresh".
- 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.
- Quay "public_html" File Manager. Chọn "wp-config.php" → "code editor".
- Thay database name = tên DB tạo ở cPanel. Đổi "DB_USER" và "DB_PASSWORD" = user/pass tạo trước.
- 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ế.
- 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.