
Hướng dẫn upload/cài đặt website, cấu hình DNS tên miền trên Google clound platform
Giá: 0 vnđ/
Bài viết sẽ hướng dẫn các bạn cách cài đặt website wordpress mới hoặc upload website có sẵn lên server và cài đặt DNS trỏ tên miền về Goolgle Clound Platform
- Cài mới Website WordPress
- Upload website/ source có sẵn lên server Google CLound
- Cấu hình DNS tên miền mua bất cứ đâu về Google Clound
- Hướng dẫn upload các file cập nhật từ máy tính lên Google Clound Platform
Tóm tắt
1. Tạo tài khoản Google Cloud Platform
First things first. Create yourself a Google Cloud Platform (GCP) account. This video will walk you through the process of setting up your GCP account if you don’t already have one.
2. Vào mục Compute Engine VM
From the GCP dashboard, click on Compute Engine. Create a VM instance.
In order to create your VM instance on the free tier, you must configure your VM with the following restrictions:
Non-preemptible f1-micro VM instance
US regions: Oregon (us-west1), Iowa (us-central1), or South Carolina (us-east1)
Up to 30 GB-months HDD
Google Cloud Platform Compute Engine VM free tierPin
Notice how it says “Your first 744 hours of f1-micro instance usage are free this month”. This number will vary depending on how many days are in the current month. For example, this screenshot was from October which has 31 days.
31 days x 24 hours = 744 hours
Feel free to choose any operating systems for the boot disk. In this tutorial, I chose Ubuntu 20.04 LTS.
Get $300 Free Google Cloud Credits
3. Kết nối với tên miền (cấu hình DNS)
You can optionally associate a domain name with your IP address. If you don’t have a domain name, feel free to skip ahead to the next step.
Otherwise, you can use create a DNS A record at your domain registrar with a value of the IP address of your Google Cloud Platform VM instance.
In Google Domains, for example, you can add the DNS A records for your domain name. The screenshot assumes the IP address of your VM instance is 35.222.110.120.
Google Domains A record for IP addressPin
It can take up to 48 hours for your domain name to become associated with your IP address, but it usually happens within a few minutes.
4. Đăng nhập vào Server
You have a few different options for logging in to your VM instance. The easiest way is to select the “Open in browser window” which will log you in to your VM instance without the need to provide any credentials.
Open in browser window GCP VM instancePin
You can also use the gcloud command to log in via the command line or terminal.
5. Update Your VM
Once you’re logged in to your server, the first thing you want to do is update your system.
- sudo apt update
- sudo apt upgrade
6. Cài đặt phiên bản phần mềm Web Server, Database, PHP
Use the apt package manager to install the Nginx web server, Mariadb database, and PHP.
- sudo apt-get install nginx mariadb-server php-fpm php-mysql
7. Cài đặt cơ sở dữ liệu WordPress Database
First, secure your database installation. After executing the following command, answer Y for each security configuration option.
- sudo mysql_secure_installation
And check PHP and SQL version:
- php –version
- mysql –version
Create a database and user with appropriate privileges for WordPress. Access the MySQL command prompt by simply typing mysql.
- sudo mysql -u root -p
- create database example_db default character set utf8 collate utf8_unicode_ci;
- create user ‘example_username’@’localhost’ identified by ‘example_password’;
- grant all privileges on example_db.* TO ‘example_username’@’localhost’;
- flush privileges;
- exit
8. Cài đặt WordPress
Next let’s download and install the latest version of WordPress from the official website.
- cd /var/www
- sudo wget https://wordpress.org/latest.tar.gz
- sudo tar -zxvf latest.tar.gz
- sudo rm latest.tar.gz
Also, change the owner and group of the WordPress root directory to www-data.
- sudo chown www-data:www-data -R wordpress/
9. Cấu hình máy chủ Nginx đến WordPress Website
Make a configuration file for your WordPress website at /etc/nginx/sites-available/example.conf with the following content adjusted accordingly for your website. Of course, feel free to name your configuration as you see fit.
- cd /etc/nginx/
- cd sites-available/
and create file configure: domain.conf. For example, if your domain is abc.com, you will create a file with the name: abc.conf:
- sudo vim abc.conf
and copy the following code paste it, then enter “:x” to save it and exit
upstream example-php-handler {
server unix:/var/run/php/php7.4-fpm.sock;
}
server {listen 80;
server_name your-domain.com www.your-domain.com;
root /var/www/wordpress;
index index.php;
location / {
try_files $uri $uri/ /index.php?$args;}
location ~ \.php$ {include snippets/fastcgi-php.conf;
fastcgi_pass example-php-handler;}
}
You will need to change the server_name option to your domain name, or if you don’t have a domain name, simply change this line to server_name _;.
Example:
server_name your-domain.com www.your-domain.com;
or
server_name your-domain.net www.your-domain.net;
Also, depending on what version of PHP was installed, you may need to update line 2 to the actual version of PHP that’s installed on your server.
Finally, publish your website by making a symlink from your sites-available/example.conf file to the sites-enabled directory.
- sudo ln -s /etc/nginx/sites-available/example.conf /etc/nginx/sites-enabled/
You will also want to remove the default Nginx config file like this.
- sudo rm /etc/nginx/sites-enabled/default // or skip
Test your Nginx configuration changes and restart the web server.
- nginx -t // or skip
- systemctl restart nginx
10. Setup WordPress
Navigate to your IP address or domain name (in this case example.com) and you’ll see the famous five-minute WordPress installation process. In reality, it take about a minute to fill out this form.
Give your website a title, username, and secure password.
Famous five-minute WordPress installation processPin
After clicking on the Install WordPress button, you’ll have a brand-spanking new copy of WordPress on your web server. Feel free to pick out a theme (I recommend GeneratePress), write some blog posts, and make your website fast with caching plugins.
If you want to make another WordPress website, you can follow this tutorial that will teach you how to host multiple WordPress websites on a single server. This won’t incur any additional charges on Google Cloud Platform, but please be aware that you are limited to 1 GB of network egress per month. If you don’t know what this means, I explain it all in this video.
Other next steps include installing an SSL certificate on your server to enable HTTPS and make your website secure.
Any questions, let me know in the comments below.