Server building personal website

1. Prepare LNMP environment

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 modification, start Nginx:


    At this time, you can access the HTTP service of the external network of the experimental machine( )To confirm that the installation was successful.

    Set Nginx to power on and start automatically:

    chkconfig nginx on
  • Install MySQL

    Install MySQL using yum:

    yum install mysql-server -y

    After installation, start the MySQL service:

    service mysqld restart

    Set the MySQL account root password:

    /usr/bin/mysqladmin -u root password 'MyPas$word4Word_Press'

    Set MySQL to power on and start automatically:

    chkconfig mysqld on
  • Install PHP

    Install PHP using yum:

    yum install php-fpm php-mysql -y

    After installation, start the PHP-FPM process:

    service php-fpm start

    After startup, you can use the following command to see which port the PHP-FPM process listens to

    netstat -nlpt | grep php-fpm

    Set PHP-FPM to start automatically after power on:

    chkconfig php-fpm on

2. Install and configure WordPress

  • Install WordPress

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

    yum install wordpress -y

    After installation, you can/usr/share/wordpress See the source code of WordPress.

  • Configuration database

    Enter MySQL:

    mysql -uroot --password='MyPas$word4Word_Press'

    Create a database for WordPress:

    CREATE DATABASE wordpress;

    After the MySQL part is set, we exit the MySQL environment:


    Configure the above DBSync to WordPress configuration In the file, refer to the following configuration:


 * The base configuration for WordPress
 * The wp-config.php creation script uses this file during the
 * installation. You don't have to use the web site, you can
 * copy this file to "wp-config.php" and fill in the values.
 * This file contains the following configurations:
 * * MySQL settings
 * * Secret keys
 * * Database table prefix
 * @link
 * @package WordPress

// ** 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', 'root');

/** MySQL database password */
define('DB_PASSWORD', 'MyPas$word4Word_Press');

/** MySQL hostname */
define('DB_HOST', 'localhost');

/** Database Charset to use in creating database tables. */
define('DB_CHARSET', 'utf8');

/** The Database Collate type. Don't change this if in doubt. */
define('DB_COLLATE', '');

 * Authentication Unique Keys and Salts.
 * Change these to different unique phrases!
 * You can generate these using the {@link secret-key service}
 * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
 * @since 2.6.0
define('AUTH_KEY',         'put your unique phrase here');
define('SECURE_AUTH_KEY',  'put your unique phrase here');
define('LOGGED_IN_KEY',    'put your unique phrase here');
define('NONCE_KEY',        'put your unique phrase here');
define('AUTH_SALT',        'put your unique phrase here');
define('SECURE_AUTH_SALT', 'put your unique phrase here');
define('LOGGED_IN_SALT',   'put your unique phrase here');
define('NONCE_SALT',       'put your unique phrase here');


 * WordPress Database Table prefix.
 * You can have multiple installations in one database if you give each
 * a unique prefix. Only numbers, letters, and underscores please!
$table_prefix  = 'wp_';

 * See

/* Disable all file change, as RPM base installation are read-only */
define('DISALLOW_FILE_MODS', true);

/* Disable automatic updater, in case you want to allow
   above FILE_MODS for plugins, themes, ... */

/* Core update is always disabled, WP_AUTO_UPDATE_CORE value is ignore */

 * For developers: WordPress debugging mode.
 * Change this to true to enable the display of notices during development.
 * It is strongly recommended that plugin and theme developers use WP_DEBUG
 * in their development environments.
 * For information on other constants that can be used for debugging,
 * visit the Codex.
 * @link
define('WP_DEBUG', false);

/* That's all, stop editing! Happy blogging. */

/** Absolute path to the WordPress directory. */
if ( !defined('ABSPATH') )
    define('ABSPATH', '/usr/share/wordpress');

/** Sets up WordPress vars and included files. */
require_once(ABSPATH . 'wp-settings.php');
  • Configure Nginx

    WordPress has been installed. We configure Nginx to forward the request to PHP FPM for processing

    First, rename the default profile:

    cd /etc/nginx/conf.d/
    mv default.conf defaut.conf.bak

    In / etc/nginx/conf.dCreate wordpress.conf configuration , refer to the following:

  • wordpress.conf

server {
    listen 80;
    root /usr/share/wordpress;
    location / {
        index index.php index.html index.htm;
        try_files $uri $uri/ /index.php index.php;
    # pass the PHP scripts to FastCGI server listening on
    location ~ .php$ {
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        fastcgi_params;


  • After configuration, notify the Nginx process to reload:

    nginx -s reload

Prepare domain name and resolution

  • Domain name registration

    If you don't have a domain name, you canShop on Tencent cloud , the process can refer to the following video.

  • Domain name resolution

    After the domain name is purchased, the domain name needs to be resolved to the experimental virtual machine. The IP address of the experimental virtual machine is:

    The domain name purchased in Tencent cloud canAdd resolution record to console , the process can refer to the following video:

    It will take a while for the domain name settings to take effect after resolution. Check whether the domain name takes effect by ping command, such as:


    If the information returned by the ping command contains the IP address you set for resolution, the resolution is successful.

  • be accomplished!

    Congratulations, your WordPress blog has been deployed. You can visit the blog through the browser to see the effect.

    View via IP address:

    Blog address:




173 original articles published, praised by 135 and visited 30000+
Private letter follow

Tags: PHP Nginx MySQL Database

Posted on Sun, 09 Feb 2020 02:58:47 -0500 by python_q