Play with Tencent Cloud CVM to build a WordPress site
Tags: tencentcloud, cvm, wordpress
Published: 2022-07-15 03:28:27

>[Cloud Virtual Machine (CVM)](https://www.tencentcloud.com/products/cvm?from_social=dev_10) provides you with secure and flexible computing capabilities. You can enable CVM in the cloud in just minutes to meet your diverse computing needs. Through [CVM](https://www.tencentcloud.com/products/cvm?from_social=dev_10), you can easily scale up or down your computing resources as your business needs change. Billed based on your actual resource consumption, CVM reduces your computing costs and simplifies IT-related OPS.

# Operation scene

WordPress is a commonly used software for building personal blog websites, which is developed using PHP language. You can deploy WordPress and publish your personal blog through simple operations on Tencent Cloud servers.
This article introduces the method of manually deploying WordPress. If your website does not have high requirements for scalability, Tencent Cloud also provides an image method to deploy WordPress. For details, please refer to Deploying WordPress Using an Image .
This tutorial takes the Linux system CentOS 7.5 as an example to build a WordPress personal site. The specific operation methods are as follows:

# Related Introduction

The following are the services or tools that will be used in this tutorial:


- **Cloud server** : This tutorial uses Tencent Cloud Cloud Server (Cloud Virtual Machine, CVM) to create a cloud server instance to complete the construction of WordPress.
- **Domain Name Registration** : If you want to use an easy-to-remember domain name to access your WordPress site, you can use Tencent Cloud Domain Name Registration Service to purchase a domain name.
- **Website **[**filing**](https://intl.cloud.tencent.com?from_social=dev_10) : For websites whose domain names point to servers in China, website filing is required. Before the domain name obtains the record number, the website cannot be opened for use. You can record your domain name through the Tencent Cloud [website record product.](https://intl.cloud.tencent.com?from_social=dev_10)
- [**Cloud**](https://intl.cloud.tencent.com/product/ba?from_social=dev_10) DNS: After configuring domain name resolution, users can access your website through the domain name without using complex IP addresses to access your website. You can resolve domain names through Tencent Cloud's [cloud](https://intl.cloud.tencent.com/product/ba?from_social=dev_10) DNS service.


# Preconditions

You have logged in to the [cloud](https://intl.cloud.tencent.com?from_social=dev_10) server console .
# Steps

## Create and log in to a cloud server


>Note: This step is for a new purchase of a cloud server. If you have purchased a cloud server instance, you can choose the WordPress website building system by reinstalling the system.


1. On the Instance List page, click New. For details, see QuickConfiguration of Linux ECS .




1. After the cloud server is successfully created, return to the cloud server console to view and obtain the following information about the instance. As shown below:




- Cloud server instance username and password
- Cloud server instance public IP


## Build LNMP environment

LNMP is short for Linux, Nginx, MariaDB, and PHP, and this combination is one of the most common operating environments for web servers. After creating and logging in to the cloud server instance, you can start to build the LNMP environment. LNMP composition and use version description:


- Linux: Linux system, this article uses CentOS7.5
- Nginx: Web server program, used to parse Web programs, this article uses Nginx1.12.2
- MariaDB: A database management system, this article uses MariaDB10.2.4
- PHP: A program for generating web pages by a web server. This article uses PHP7.2.17


### Install software and configure using yum

After logging in to the cloud server, you have obtained root privileges by default. With root privileges, follow the steps below to install step by step.
## Install and configure Nginx


1. Execute the following command to install Nginx. `yum -y install nginx ` 
    2. Execute the following command to open the  `nginx.conf` file.
 `vim /etc/nginx/nginx.conf` 
   3. Press " **i** " or " **Insert** " to switch to edit mode,  `nginx.conf` and replace the contents of server{...} in the file with the following. It is used to cancel the monitoring of IPv6 addresses, and configure Nginx to realize linkage with PHP.
```
server {
 listen       80;
 root   /usr/share/nginx/html;
 server_name  localhost;
 #charset koi8-r;
 #access_log  /var/log/nginx/log/host.access.log  main;
 #
 location / {
         index index.php index.html index.htm;
 }
 #error_page  404              /404.html;
 #redirect server error pages to the static page /50x.html
 #
 error_page   500 502 503 504  /50x.html;
 location = /50x.html {
     root   /usr/share/nginx/html;
 }
 #pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
 #
 location ~ .php$ {
     fastcgi_pass   127.0.0.1:9000;
     fastcgi_index  index.php;
     fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
     include        fastcgi_params;
  }
}
```
copy
2. Press " **Esc** ", enter " **:wq** ", save the file and return.
3. Execute the following commands in sequence to start Nginx and set it to auto-start at boot. `systemctl start nginx ` 
 `systemctl enable nginx ` 
In a browser, visit the public IP address of the CentOS cloud server instance to check whether the Nginx service is running normally. If the following is displayed, it means that the Nginx installation and configuration are successful.


![image](https://main.qcloudimg.com/raw/dc7ccc6220299225de75c521620423b4.png)Verify that nginx is installed successfully
## Install and configure PHP


1. Execute the following command to update the PHP mirror source in yum. `rpm -Uvh https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm  ` 
 `rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm` 
    2. Execute the following command to view all packages of PHP 7.2 that can be installed.
 `yum search php72w ` 
    3. Execute the following commands to install the required packages.
 `yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64` 
   4. Execute the following commands in sequence to start the PHP-FPM service and set it to auto-start at boot.
 `systemctl start php-fpm systemctl enable php-fpm` 


## Verify PHP-Nginx environment configuration


1. Execute the following command to create a  `index.php` file in the web directory. `vim /usr/share/nginx/html/index.php` 
    2. Press " **i** " or " **Insert** " key to switch to edit mode, and write the following content.
 `<?php  echo "hello world!"; ?>` 
Press " **Esc** ", enter " **:wq** ", save the file and return.
In a browser, visit the  `index.php` file to see if the environment configuration was successful.
 `http://云服务器实例的公网 IP/index.php ` 
If the page is displayed as follows, the LNMP environment configuration is successful.


![image](https://main.qcloudimg.com/raw/7a61a5dcc24ca00b9a50036a0ba1aa12.png)Verify PHP-Nginx environment configuration
## Install and configure MariaDB

1. Execute the following command to check whether there is an existing MariaDB package in the system.
 `rpm -qa | grep -i mariadb` 
If the returned result is similar to the following, it means that MariaDB already exists, go to step 2.
![image](https://main.qcloudimg.com/raw/6fa7fb51de4a61f4da08eb036b6c3e85.png)The mariadb component installed by default in CVM
2. Execute the following command to delete the existing MariaDB package.
 `yum remove 包名` 
3. Execute the following command to install MariaDB.
 `yum -y install mariadb mariadb-serve` 
4. Execute the following commands in sequence to start the MariaDB service and set it to auto-start at boot.
 `systemctl start mariadb systemctl enable mariadb` 
Run the following commands to set the root account login password and basic configuration. Notice:


- For users who log in to MariaDB for the first time, execute the following commands to enter the user password and basic settings.
- After entering the root account password for the first time, you need to press " **Enter** " (the interface is not displayed by default when the root password is set), and enter the root password again for confirmation. Please follow the prompts on the interface to complete the basic configuration.


 `mysql_secure_installation` 

5. Run the following command to log in to MariaDB, enter the password set in step 5, and press Enter.
 `mysql -uroot -p` 
If the result is as follows, it has successfully entered MariaDB.
![image](https://main.qcloudimg.com/raw/0cfea29c0fa72075137a3dda0825c7a4.png)
## Install and configure WordPress

### download


>Note: WordPress can download the Chinese version of WordPress from the [official WordPress website](https://cn.wordpress.org/) and install it. This tutorial uses the Chinese version of WordPress.

1. Execute the following command to delete the index.php file used to test the PHP-Nginx configuration in the root directory of the website.
 `rm -rf /usr/share/nginx/html/index.php` 
2. Execute the following commands in sequence, enter the /usr/share/nginx/html/ directory, and download and decompress WordPress.
 `cd /usr/share/nginx/html wget https://cn.wordpress.org/wordpress-4.7.4-zh_CN.tar.gz ` 
 `tar zxvf wordpress-4.7.4-zh_CN.tar.gz` 
### configuration database

Before writing a blog, you need to build a database to store all kinds of data. Follow the steps below for MariaDB database configuration.
1. Execute the following command to log in to the MariaDB server as the root user.
 `mysql -uroot -pXXXXX（安装配置 MariaDB 设置的登录密码）` 
2. Run the following command to create the MariaDB database. For example "wordpress".
 `CREATE DATABASE wordpress;` 
3. Execute the following command to create a new user. For example "user@localhost".
 `CREATE USER user@localhost;` 
4. Execute the following command to set a password for the "user@localhost" user. For example "wordpresspassword".
 `SET PASSWORD FOR user@localhost=PASSWORD("wordpresspassword");` 
5. Execute the following command to give the user full permissions to the "wordpress" database.
 `GRANT ALL PRIVILEGES ON wordpress.* TO user@localhost IDENTIFIED BY 'wordpresspassword';` 
6. Execute the following commands to make all configurations take effect.
 `FLUSH PRIVILEGES;` 
7. Execute the following command to exit MariaDB.
 `exit` 
### write database information

1. Execute the following commands one by one, enter the WordPress installation directory, copy the wp-config-sample.php file to the wp-config.php file, and keep the original sample configuration file as a backup.
 `cd /usr/share/nginx/html/wordpress ` 
 `cp wp-config-sample.php wp-config.php` 
2. Execute the following command to open and edit the newly created configuration file.
 `vim wp-config.php` 
3. Press "i" or "Insert" to switch to the edit mode, find the MySQL part in the file, and write the information about the configured database in the configuration database.

```
 // ** MySQL settings - You can get this info from your web host ** //
 /** The name of the database for WordPress */
 define('DB_NAME', 'wordpress');

 /** MySQL database username */
 define('DB_USER', 'user');

 /** MySQL database password */
 define('DB_PASSWORD', 'wordpresspassword');

 /** MySQL hostname */
 define('DB_HOST', 'localhost');
```
copy
4. After the modification is completed, press " **Esc** ", enter " **:wq** ", save the file and return.

### Verify WordPress installation

1. Enter the public IP of the cloud server instance in the browser address bar or add the wordperss folder after the IP, for example:
 `http://192.xxx.xxx.xx  http://192.xxx.xxx.xx /wordpress` 
Go to the WordPress installation page and start configuring WordPress.
Configure WordPress
2. Enter the following installation information as prompted by the WordPress installation wizard, and click [Install WordPress] to complete the installation. Required Information Description Site Title WordPress Site Name. Username WordPress administrator name. For security reasons, it is recommended to set a name different from admin. Because this name is more difficult to crack than the default user name admin. The password can be a strong default password or a custom password. Do not reuse existing passwords, and be sure to keep them in a safe place. Your email The email address used to receive notifications.
You can now log in to your WordPress blog with and start publishing blog posts.
## Follow-up


1. You can set up a separate domain name for your WordPress blog site. Your users can access your website with an easy-to-remember domain name without complex IP addresses. You can purchase domain names through Tencent Cloud .
2. Websites whose domain names point to servers in China must be registered. Before the domain name obtains the record number, the website cannot be opened for use. You can record your website. The filing is free, and the review time is about 20 days.
3. You need to configure domain name resolution on Tencent Cloud DNS before users can access your website through the domain name. For guidance, refer to Domain Name Resolution .


In addition, you can scale service capacity horizontally and vertically on the Tencent Cloud platform, for example:


- Expand the CPU and memory specifications of a single CVM instance to increase the processing power of the server. 
- Add multiple CVM instances and use load balancing to balance load among multiple instances.
- With elastic scaling , the number of CVM instances can be automatically increased or decreased according to the business volume.
- Use object storage to store static web pages and massive pictures, videos, etc.