🌐 Hướng dẫn cài đặt WordPress trên Google Cloud (VM f1-micro)

wp


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
🔹Bước 3: Cài đặt LAMP Stack 

3.1 Cài Apache (Web Server)

sudo apt install apache2 -y
Sau khi cài xong, khởi động và kiểm tra Apache:

sudo systemctl start apache2 sudo systemctl enable apache2
Kiểm tra Apache bằng cách vào trình duyệt: http://your_ip_address 

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
Khởi động và cấu hình MariaDB:

sudo systemctl start mariadb
sudo systemctl enable mariadb
sudo mysql_secure_installation
Sau khi cài xong, đăng nhập vào MariaDB để tạo database cho WordPress:

sudo mysql -u root -p
Nhập mật khẩu root của MariaDB rồi thực hiện các lệnh sau:
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;
- wordpress: Tên cơ sở dữ liệu 
- 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
Khởi động lại Apache để PHP có thể hoạt động:

sudo systemctl restart apache2
🔹Bước 4: Cài đặt WordPress 

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/
4.2 Cấu hình quyền sở hữu và quyền truy cập

sudo chown -R www-data:www-data /var/www/html/wordpress sudo chmod -R 755 /var/www/html/wordpress
🔹Bước 5: Cấu hình Apache cho WordPres

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
Thêm vào nội dung sau:
<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>
5.2 Kích hoạt cấu hình và mod_rewrite Kích hoạt website và module rewrite của Apache:
sudo a2ensite wordpress.conf
sudo a2enmod rewrite
sudo systemctl restart apache2
🔹Bước 6: Cài đặt WordPress qua Trình duyệt

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
2. Chạy lệnh sau để cài SSL:

sudo certbot --apache
3.Follow các bước hướng dẫn, và chứng chỉ SSL sẽ được cài tự động. 

✅ 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.

Post a Comment

Previous Post Next Post