OS: Ubuntu 18.04 x 64

1. Build LNMP environment

  • L: Linux is a general name for a class of Unix computer operating systems
  • N: Nginx is a high-performance HTTP and reverse proxy server, as well as an IMAP/POP3/SMTP proxy server.
  • M:mysql is a small relational database management system.
  • P:PHP is a scripting language embedded in HTML documents that executes on the server side.

1. Install nginx

sudo apt install nginx
Copy the code

If you open http://localhost and see the image below, nginx has been successfully installed

2. Installation of mysql

sudo apt install mysql-server
Copy the code

Enter Y and press enter

Confirm mysql installation

Verify the mysql installation

mysql -u root -p
Copy the code

Enter the password and enter the mysql command line

3. Install PHP

sudo apt install php
sudo apt install php-fpm
sudo apt install php-mysql
Copy the code

Executing the above three commands in turn may require some patience.

We have installed Nginx, PHP and MySQL, but this service is not available for the time being. We need to link Nginx and PHP through configuration. First, we need to go to the Nginx configuration directory.

CD /etc/nginx/sites-enabled sudo nano default # if you want to use this method to modify the default.conf file, CTRL + S to save, CTRL +x to launch; #sudo apt install nano; Install nano, or use the built-in VI editor.Copy the code

Then paste in the following code

server { listen 80; root /usr/share/nginx/html; PHP ${fastcgi_pass Unix :/run/ PHP /php7.2-fpm.sock; Php7.2-fpm. Sock is running in the /run/ PHP directory. You may need to check the sock file for different versions of php-fpm. fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }}Copy the code

Testing the PHP environment

cd /usr/share/nginx/html
sudo nano info.php
Copy the code

In the editor

<? php phpinfo(); ? >Copy the code

Open the http://localhost/info.php or http://. Your IP address/info PHP, see below content which PHP environment with success

2. Install wordpress

Run the following command to install wordpress

apt install wordpress
Copy the code

Create a database and user for WodPress

Accessing the database

Mysql -u root -p #Copy the code

Create a database called wordpress

CREATE DATABASE wordpress;
Copy the code

Create a mysql user named wordpress, password wordpressPS, and give full permission to operate the database wordpress;

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

Exiting the database

EXIT;
Copy the code

Synchronize the above DB configuration _ to the WordPress configuration _ file.

cd /etc/wordpress
sudo nano wp-config.php
Copy the code

See the code below for configuration

<? php /** * 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 * * ABSPATH * * @link https://codex.wordpress.org/Editing_wp-config.php * * @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', 'wordpress'); /** MySQL database password */ define('DB_PASSWORD', 'wordpressPS'); /** 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 https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret - key service} * You can change these at any point in time to invalidate all existing cookies. This will force all users to ** @since 2.6.0 */ /** * 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 http://make.wordpress.org/core/2013/10/25/the-definitive-guide-to-disabling-auto-updates-in-wordpress-3-7 */ /* 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, ... */ define('AUTOMATIC_UPDATER_DISABLED', true); 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'); ? >Copy the code

Modify the DB configuration of the wordpress content file

CD /usr/share/wordpress sudo nano wp-configCopy the code

To modify the nginx configuration file, see the following configuration

server { listen 80; root /usr/share/wordpress; location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php index.php; PHP ${fastcgi_pass Unix :/run/ PHP /php7.2-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; }}Copy the code

Restart the nginx

sudo service nginx restart
Copy the code

Open HTTP :localhost/wp-admin/install.php to install wordpress. Just enter the information as required

Successful installation

Third, summarize the existing problems

  • If you want to upload the wordpress version to the host by yourself, you need to change the corresponding folder (mine is /usr/share/wordpress) permission to the www-data user, otherwise you will enter the FTP server information in the installation theme or plug-in.
  • The configuration file in /etc/wordpress should have the same content as the wp-config.php configuration file. Otherwise, an error will be reported that the configuration file is not present.
  • The mysql database is root and the password is empty.