1. Manually build the 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.
Step 1: Log in to the Linux instance
Use the platform where you purchased the server to log in to the Linux instance
Use the remote login software winscp and putty to log in to the Linux instance
Use SSH to log in to the Linux instance
Step 2: Install Nginx
Execute the following command to install nginx.
yum install -y nginx
Edit the /etc/nginx/nginx.conf
file.
Find server{...}
and replace the corresponding configuration information in the server curly brackets with the following. It is used to cancel the monitoring of IPv6 addresses, and configure Nginx to realize linkage with PHP.
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;
}
}
Execute the following command to start Nginx.
systemctl start nginx
Execute the following command to set Nginx to start automatically at boot.
systemctl enable nginx
Visit your website address (ip address or domain name) in the browser to check whether the Nginx service is running normally.
Step 3: Install the database
Execute the following command to check whether MariaDB is installed in the system.
rpm -qa | grep -i mariadb
It should be there by default. Maybe the version is older. I have more than 5. So I uninstalled it first and then installed it.
sudo yum -y remove 包名
sudo yum install mariadb-server
Execute the following command to start the MariaDB service.
systemctl start mariadb
Execute the following command to set MariaDB to auto-start at boot.
systemctl enable mariadb
Execute the following command to verify that MariaDB is installed successfully.
mysql
It shows that the installation is successful!
Step 4: Install and configure PHP
Execute the following commands one by one to update the software source of PHP in yum.
rpm -Uvh https://mirrors.cloud.tencent.com/epel/epel-release-latest-7.noarch.rpm
rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm
Execute the following command to install the packages required by PHP 7.2.
yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64
Execute the following command to start the PHP-FPM service.
systemctl start php-fpm
Execute the following command to set the PHP-FPM service to start automatically at boot.
systemctl enable php-fpm
Verify environment configuration
After you complete the environment configuration, you can verify whether the LNMP environment is successfully set up by the following steps.
Execute the following command to create a test file.
echo "<?php phpinfo(); ?>" >> /usr/share/nginx/html/index.php
Execute the following command to restart the Nginx service.
systemctl restart nginx
Visit the following address in a local browser to check whether the environment configuration is successful.
http://云服务器实例的公网 IP
2. Configure the database
Execute the following command to enter MariaDB.
mysql
Execute 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", the login password is 123456.
CREATE USER 'user'@'localhost' IDENTIFIED BY '123456';
Execute the following command to give the user full rights to the "wordpress" database.
GRANT ALL PRIVILEGES ON wordpress.* TO 'user'@'localhost' IDENTIFIED BY '123456';
Execute the following commands to make all configurations take effect.
FLUSH PRIVILEGES;
3. Install and configure WordPress
WordPress download and unzip
Execute the following command to delete the index.php file in the root directory of the website for testing the PHP-Nginx configuration.
rm -rf /usr/share/nginx/html/index.php
Execute the following commands one by one, enter the /usr/share/nginx/html/ directory, and download and decompress WordPress.
cd /usr/share/nginx/html
The following download will give an error
wget https://cn.wordpress.org/latest-zh_CN.tar.gz
[root@VM-12-7-centos html]# wget https://cn.wordpress.org/latest-zh_CN.tar.gz
--2021-07-10 22:00:10-- https://cn.wordpress.org/latest-zh_CN.tar.gz
Resolving cn.wordpress.org (cn.wordpress.org)... 198.143.164.252
Connecting to cn.wordpress.org (cn.wordpress.org)|198.143.164.252|:443... connected.
Unable to establish SSL connection.
Unable to establish SSL connection.
The reason for the error is that some websites do not allow non-browser access to files, and parameters need to be added:--no-check-certificate
download command
wget https://cn.wordpress.org/latest-zh_CN.tar.gz --no-check-certificate
unzip command
tar zxvf latest-zh_CN.tar.gz
WordPress configuration
Execute the following commands in sequence to 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
Edit the newly created configuration file wp-config.php.
Find the MySQL section in the file and modify the relevant configuration information to configure the content in the WordPress 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', '123456');
/** MySQL hostname */
define('DB_HOST', 'localhost');
4. Verify WordPress Installation
Enter it in the browser address bar http://域名或云服务器实例的公网IP/wordpress
, because it is extracted under the wordpress folder.
This is basically configured, and then you can modify the theme and so on.
From:
Manually build LNMP environment (CentOS7)
Manually build WordPress personal site (Linux)