1. Build the environment

The server used by the author of this article is Tencent cloud server.

Linux: Linux (Ubuntu18.04 in this article);


Nginx: Web server program, used to parse Web programs;


MySQL: a database management system;


PHP: a program used by a Web server to generate Web pages.

(1) Install and configure Nginx

sudo apt-get install nginxCopy the code

Start the Nginx

service nginx startCopy the code

To test whether the Nginx service is running properly, open a browser, access the public IP address of the cloud host, and check whether the Nginx service is running properly. If the Welcome to Nginx page is displayed, the installation and configuration is successful.

(2) the MySQL installation

sudo apt-get install mysql-serverCopy the code

Change the password

use mysql;

update mysql.user set authentication_string=password('root') 
where user='root' and Host ='localhost';

update user set plugin="mysql_native_password"; 

flush privileges;

quit;Copy the code

Restart mysql

Sudo service mysql restart mysql -u root -p // After the system starts, enter the new password rootCopy the code

(3) installing PHP

sudo apt-get install php-fpm php-mysqlCopy the code

Open the PHP configuration file

Sudo vim/etc/PHP / 7.0 / FPM/PHP iniCopy the code

In the CLI, enter/and enter cgi.fix_pathinfo=1 to search for the keyword

cgi.fix_pathinfo=1
Copy the code

Modified to

cgi.fix_pathinfo=0
Copy the code

Restart PHP

Sudo systemctl restart php7.2 - FPMCopy the code

2. Configure nginx

sudo vim /etc/nginx/sites-available/defaultCopy the code

Include the following

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name server_domain_or_IP;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ = 404; }# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        # include snippets/fastcgi-php.conf;
        #
        # # With php7.0-cgi alone:
        # fastcgi_pass 127.0.0.1:9000;
        # # With php7.0 - FPM:
        # fastcgi_pass Unix: / run/PHP/php7.0 - FPM. The sock.
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        # deny all;
        #}
}
Copy the code

Modified to

server {
        listen 80 default_server;
        listen [::]:80 default_server;

        # SSL configuration
        #
        # listen 443 ssl default_server;
        # listen [::]:443 ssl default_server;
        #
        # Note: You should disable gzip for SSL traffic.
        # See: https://bugs.debian.org/773332
        #
        # Read up on ssl_ciphers to ensure a secure configuration.
        # See: https://bugs.debian.org/765782
        #
        # Self signed certs generated by the ssl-cert package
        # Don't use them in a production server!
        #
        # include snippets/snakeoil.conf;

        root /var/www/html;

        # Add index.php to the list if you are using PHP
        index index.php index.html index.htm index.nginx-debian.html;

        server_name server_domain_or_IP;

        location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ = 404; }# pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        location ~ \.php$ {
                include snippets/fastcgi-php.conf;
        #
        # # With php7.0-cgi alone:
        # fastcgi_pass 127.0.0.1:9000;
        # # With php7.0 - FPM:Fastcgi_pass Unix: / run/PHP/php7.0 - FPM. The sock. }# deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #location ~ /\.ht { deny all; }}Copy the code

Conf file, disable the listening on IPv6 addresses, and configure Nginx to interwork with PHP.

sudo vim /etc/nginx/conf.d/default.conf
Copy the code

Type the following information into the default.conf file, save the configuration and exit

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
#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 the code

Test the configuration file for syntax errors by running the following command:

sudo nginx -t
Copy the code

There will be no errors after reloading Nginx

sudo systemctl reload nginxCopy the code

3. Test environment

Create the info.php file in the Web directory:

sudo vim /var/www/html/info.php
Copy the code

Enter the following:

<? phpecho "<title>Test Page</title>";
echo "Hello World!"; ? >Copy the code

In the browser, access the info.php file and check whether the environment configuration is successful: Hello World! The environment is set up successfully.

4. Install WordPress

Download WordPress

cd /tmp
curl -O https://wordpress.org/latest.tar.gzCopy the code

The author USES the address is https://cn.wordpress.org/latest-zh_CN.zip

Unpack the

tar xzvf latest.tar.gzCopy the code

The author encountered the problem that tar could not be decompressed when decompressing, so he downloaded wordpress locally and then used Transmit to upload the files to the cloud server directory. If the files are not macOS, Xftp can be used to upload the files.

Copy WordPress to site root:

Backup configuration files
cp /tmp/wordpress/wp-config-sample.php /tmp/wordpress/wp-config.php

# create the upgrade directory so that WordPress does not encounter permissions when performing automatic updates:
mkdir /tmp/wordpress/wp-content/upgrade

Copy the entire contents of the directory to the site root directory. Use the -a flag to ensure that our permissions are maintained.A dot is used at the end of the directory to indicate that everything in the directory should be copied, including any hidden files sudo cp-a /tmp/wordpress/. /var/www/htmlCopy the code

Adjust WordPress ownership and permissions

Set proper file permissions and ownership. We need to be able to write certain files as normal users, and we need the Web server to be able to access and adjust certain files and directories as well.

First, assign ownership of all files in the document root to the user name we set. The username here is your sudo username:

sudo chown -R sudouser:sudouser /var/www/html
Copy the code

Next, we will set the setgid bit on each directory under the document root.

This causes new files created in these directories to inherit the group of the parent directory (which we set to sudouser only) rather than the primary group that created the user.

This just ensures that when we create a file in the directory from the command line, the Web server still has ownership of the group.

We can set the setgid bit on each directory of our WordPress installation by typing:

sudo find /var/www/html -type d -exec chmod g+s {} \;
# Change the permissions of wp-content, Themes, plugins folder
sudo chmod g+w /var/www/html/wp-content
sudo chmod -R g+w /var/www/html/wp-content/themes
sudo chmod -R g+w /var/www/html/wp-content/pluginsCopy the code

Configuring the Database

Log in to the MySQL server as user root.

mysql -uroot -p
Copy the code

Create MySQL database WordPress for WordPress.

CREATE DATABASE wordpress;
Copy the code

Create a new user “user@localhost” for the MySQL database you have created.

CREATE USER user@localhost IDENTIFIED BY '123456';
Copy the code

Grant the created user full access to the wordpress database.

GRANT ALL PRIVILEGES ON wordpress.* TO user@localhost IDENTIFIED BY 'wordpresspassword';
Copy the code

Use the following command to make all configurations take effect.

FLUSH PRIVILEGES;
Copy the code

After the configuration is complete, exit MySQL.

exitCopy the code

Write database information

After configuring the database, add the database information to the WordPress configuration file.

Open and edit the newly created configuration file.

sudo vim /var/www/html/wp-config.php
Copy the code

MySQL > select * from MySQL;

// ** 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 the code

After the modification is complete, press Esc and enter :wq to save the configuration and return to the vi editor.

The installation of WordPress

Enter the IP address of the WordPress site (the public IP address of the cloud host, or the address followed by WordPress folder) in the address bar of the Web browser. You can see the WordPress installation screen and start to configure WordPress.


The wordpress site is now set up.


Personal site: the subsequent binding domain name will be issued.


Reference:

1. www.jianshu.com/p/a1ede27ad…

2. blog.csdn.net/qq_38737992…