When the financial budget or human resources are limited, WordPress is still the best choice to quickly build a blog or corporate website.

Recently, I used WordPress while learning to build a simple official website for a brother company. The code is debugged locally. Today I learned how to publish this program on the server.

Note: The server is a cloud host on Tencent, and the operating system is CentOS 6.8 64-bit.

1. Prepare LNMP environment

LNMP is the abbreviation of Linux, Nginx, MySQL and PHP and is the basic operating environment that the WordPress blog system relies on. Let’s first prepare the LNMP environment.

1.1 Install Nginx

Install Nginx using yum:

yum install nginx -y

Modify /etc/nginx/conf.d/default.conf to remove the monitoring of IPv6 addresses (CentOS 6 does not support IPv6, you need to cancel the monitoring of IPv6 addresses, otherwise Nginx cannot start successfully), you can refer to the following example:

server { listen 80 default_server; # listen [::]:80 default_server; server_name _; root /usr/share/nginx/html;

Load configuration files for the default server block.

    include /etc/nginx/default.d/*.conf;

location/{ }

error_page 404 /404.html; location = /40x.html { }

error_page 500 502 503 504 /50x.html; location = /50x.html { }

}

After the modification is completed, start Nginx:

nginx

At this point, you can access the external HTTP service of the cloud host to confirm whether the installation has been successful.

Set Nginx to start automatically at boot:

chkconfig nginx on

1.2 Install MySQL

Install MySQL using yum:

yum install mysql-server -y

After the installation is complete, start the MySQL service:

service mysqld restart

Set the MySQL account root password:

/usr/bin/mysqladmin -u root password ‘yourPassword4WordPress’

Set MySQL to start automatically at boot:

chkconfig mysqld on

1.3 Install PHP

Install PHP using yum:

yum install php-fpm php-mysql -y

(CentOs 6 has PHP-FPM and PHP-MYSQL installed by default. Executing the above command may prompt that they are already installed.)

After installation, start the PHP-FPM process:

service php-fpm start

After starting, you can use the following command to check which port the PHP-FPM process is listening on (PHP-FPM listens to port 9000 by default)

netstat -nlpt | grep php-fpm

Set PHP-FPM to start automatically at boot:

chkconfig php-fpm on

2. Install and configure WordPress

2.1 Install WordPress

After configuring the LNMP environment, continue to use yum to install WordPress:

yum install wordpress -y

After the installation is complete, you can see the source code of WordPress in /usr/share/wordpress.

2.2 Configure database

Configuration to enter MySQL:

mysql -uroot –password=‘yourPassword4WordPress’

Create a database for WordPress:

CREATE DATABASE wordpress;

The MySQL part is set up, we exit the MySQL environment:

exit

To synchronize the above DB configuration to the configuration file of WordPress, please refer to the following configuration: