Yêu cầu trước khi bắt đầu:
1. Máy chủ Google Cloud (f1-micro) đã được tạo và khởi chạy.
2. Đã mở cổng HTTP (Port 80) trong Firewall của Google Cloud.
3. Tên miền 9xcongit.com đã được trỏ đến IP của VM (tạo bản ghi DNS với loại A, trỏ tới IP tĩnh của VM).
🔹Bước 1: SSH vào VM
1. Truy cập vào Google Cloud Console.
2. Đi tới Compute Engine → VM instances.
3. Bấm vào SSH để kết nối vào máy chủ của bạn.
🔹Bước 2: Cập nhật hệ thống
Cập nhật tất cả các gói hệ thống:
sudo apt update && sudo apt upgrade -y
3.1 Cài Apache (Web Server)
sudo apt install apache2 -y
sudo systemctl start apache2
sudo systemctl enable apache2
Nếu bạn thấy trang mặc định của Apache, vậy là thành công.
3.2 Cài MariaDB (Database Server)
sudo apt install mariadb-server mariadb-client -y
sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
sudo mysql -u root -p
CREATE DATABASE wordpress DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;
CREATE USER 'wpuser'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON wordpress.* TO 'wpuser'@'localhost';
FLUSH PRIVILEGES;
EXIT;
- wpuser: Tên người dùng
- your_password: Mật khẩu cho người dùng wpuser
3.3 Cài PHP
sudo apt install php php-mysql libapache2-mod-php php-cli php-curl php-xml php-mbstring unzip -y
sudo systemctl restart apache2
4.1 Tải WordPress
cd /tmp
curl -O https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo mv wordpress /var/www/html/
sudo chown -R www-data:www-data /var/www/html/wordpress
sudo chmod -R 755 /var/www/html/wordpress
5.1 Tạo cấu hình Apache cho WordPress
Tạo một file cấu hình cho Apache:
sudo nano /etc/apache2/sites-available/wordpress.conf
<VirtualHost *:80>
ServerAdmin admin@9xcongit.com
DocumentRoot /var/www/html/wordpress
ServerName 9xcongit.com
ServerAlias www.9xcongit.com
<Directory /var/www/html/wordpress>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
1. Mở trình duyệt và truy cập vào http://9xcongit.com (hoặc IP của máy ảo).
2. Bạn sẽ thấy giao diện cài đặt WordPress:
- Chọn ngôn ngữ và nhấn Continue.
- Nhập thông tin cơ sở dữ liệu mà bạn đã tạo:
- Database Name: wordpress
- Username: wpuser
- Password: your_password
- Database Host: localhost
- Table Prefix: wp_
- Bấm Submit, sau đó Run the Install.
3. Sau khi cài xong, bạn sẽ được yêu cầu nhập các thông tin quản trị:
- Site Title: Chọn tên cho website của bạn.
- Username: Đặt tên tài khoản admin.
- Password: Đặt mật khẩu cho admin.
- Email: Địa chỉ email của bạn.
🔒 (Tùy chọn) Cài SSL với Let's Encrypt
Để bảo mật cho website, bạn có thể cài SSL miễn phí với Let's Encrypt:
1. Cài Certbot:
sudo apt install certbot python3-certbot-apache -y
sudo certbot --apache
✅ Hoàn thành!
Giờ bạn đã có một website WordPress chạy trên Google Cloud với tên miền 9xcongit.com và máy chủ f1-micro.