Play with Tencent Cloud CVM to build a WordPress site
kunzhu0710
Posted on July 15, 2022
Cloud Virtual Machine (CVM) 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, 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 : 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.
- Cloud 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 DNS service.
Preconditions
You have logged in to the cloud 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.
On the Instance List page, click New. For details, see QuickConfiguration of Linux ECS .
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
- Execute the following command to install Nginx.
yum -y install nginx
- Execute the following command to open the
nginx.conf
file.vim /etc/nginx/nginx.conf
- 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.
- Execute the following command to open the
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
- Press " Esc ", enter " :wq ", save the file and return.
- 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.
Verify that nginx is installed successfully
Install and configure PHP
- 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
- Execute the following command to view all packages of PHP 7.2 that can be installed.
yum search php72w
- 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
- 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
- Execute the following command to view all packages of PHP 7.2 that can be installed.
Verify PHP-Nginx environment configuration
- Execute the following command to create a
index.php
file in the web directory.vim /usr/share/nginx/html/index.php
- 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 theindex.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.
- Press " i " or " Insert " key to switch to edit mode, and write the following content.
Verify PHP-Nginx environment configuration
Install and configure MariaDB
- 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. The mariadb component installed by default in CVM - Execute the following command to delete the existing MariaDB package.
yum remove 包名
- Execute the following command to install MariaDB.
yum -y install mariadb mariadb-serve
- 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
- 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. ## Install and configure WordPress
download
Note: WordPress can download the Chinese version of WordPress from the official WordPress website and install it. This tutorial uses the Chinese version of WordPress.
- 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
- 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.
- Execute the following command to log in to the MariaDB server as the root user.
mysql -uroot -pXXXXX(安装配置 MariaDB 设置的登录密码)
- Run the following command to create the MariaDB database. For example "wordpress".
CREATE DATABASE wordpress;
- Execute the following command to create a new user. For example "user@localhost".
CREATE USER user@localhost;
- Execute the following command to set a password for the "user@localhost" user. For example "wordpresspassword".
SET PASSWORD FOR user@localhost=PASSWORD("wordpresspassword");
- 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';
- Execute the following commands to make all configurations take effect.
FLUSH PRIVILEGES;
-
Execute the following command to exit MariaDB.
exit
write database information
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
Execute the following command to open and edit the newly created configuration file.
vim wp-config.php
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
- After the modification is completed, press " Esc ", enter " :wq ", save the file and return.
Verify WordPress installation
- 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 -
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
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 .
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.
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.
Posted on July 15, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.