Starting from Scratch: Alibaba Cloud ECS Deployment LNMP+WordPress Transcript (1)

Posted on 2020-03-12  3 Views


Over the years, I have been learning through various technical materials on the Internet, from Github, CSDN, to Jianshu and so on... Slowly, the idea of building a personal blog came to mind, hoping to make a little record of my learning journey. If I can help others a little at the same time, it is my honor as an Internet person and my gratitude to the Internet. Coincidentally, I have an idle EcSn4 instance of Alibaba Cloud student discount (1 core 2G 40G) on hand, which is convenient for recently starting my first blog journey.

Instance: Alibaba Cloud ECS instance 1 core (100%) 2G RAM, 40G cloud disk, 1Mbps fixed bandwidth point Hangzhou. (Actually 1Mbps access is slightly slower, but it's completely within the acceptable range.) If conditions permit, you can try pay-as-you-go or other flex products. Operating
system: CentOS 8.1
configuration scheme: Nginx + Mysql 8.0 + PHP 7.3

1. Server settings

Modify the server name

For ease of administration, modify the default random server name.

hostnamectl set-hostname new_hostname


SSH port configuration

By default, ssh runs on port 22 listeners. To prevent malicious scanning and infiltration, it is recommended that the port be replaced. (Note: Ports below 1024 are not recommended.) This part of the port is a privileged port in Linux, which can only be used by root users, which may cause ssh to fail to connect. Before

operating on the server, first make sure to add an inbound rule on the firewall of the cloud server that allows the tcp protocol of the destination port.

At Port range, fill in the allowed port range. Select the rule direction and fill in the authorization object according to the IP address and mask specifications. The default 0.0.0.0/0 means all allowed.

Enter: on the server terminal

sudo vi /etc/ssh/sshd_config


Modify the port line To modify the default 22 to the destination port number.
After the modification, execute sudo systemctl restart sshd and restart the ssh service.

Modify the domestic source address

First back up the 3 original repos of the system:

cd /etc/yum.repos.d/
sudo cp CentOS-AppStream.repo CentOS-AppStream.repo.bak
sudo cp CentOS-Base.repo CentOS-Base.repo.bak
sudo cp CentOS-Extras.repo CentOS-Extras.repo.bak

Edit 3 .repo files, comment out the mirrorlist line, and remove the # before baseurl.
Change the mirror.centos.org/$contentdir in baseurl to mirrors.aliyun.com/centos. (The address may change, the latest shall prevail)
After the modification, the yum will be updated.

sudo yum clean all
sudo yum makecache
sudo yum update

2. Nginx deployment

Written on the front: the LNMP part has multiple installation methods, which can be selected according to actual needs. You can use the LNMP one-click installation package for installation, thanks to the little partner Tom's Amway. Specific move: LNMP one-click installation package. In addition, you can download the source files to compile them yourself, or you can directly use the package manager such as yum/dnf to install. This article uses the latter method.

Enter in the terminal

sudo yum install nginx

After waiting for the installation to complete, configure nginx:
there are two configuration methods: 1. Modify the main configuration file 2. Configure each site separately (suitable for multi-site servers)
For the sake of simplicity, this article directly modifies the main configuration file, the configuration principle is the same, and the configuration file can be stored in the /etc/nginx/conf.d/ directory.

Locate the server{} paragraph in the configuration file and modify its contents.
Parameter explanation:
listen: Listen port number, the default is HTTP port 80, modify according to the actual situation.
server_name:listenIf the match fails, the domain name entered in this line is used for the match. Non-multi-site servers can be left at default.
root: The root directory of the website, which can be set according to the actual situation. This article remains the default.
Locate the location {} paragraph and add:
index index.php index.html index .htm;
Controls which pages are accessed by default by the configured Web site.
Under the location {} paragraph, add the following code to make nginx support php access:

location ~ .php{
            root /usr/share/nginx/html;
            try_filesuri = 404;
            fastcgi_pass unix:/run/php-fpm/www.sock;
            fastcgi_index index.php;
            fastcgi_param SCRIPT_FILENAME document_rootfastcgi_script_name;
            include fastcgi_params;
}

Save exit, grant nginx permission to the root directory of the site.

sudo chown +R nginx:nginx /site root/

Enable nginx in the terminal:

sudo systemctl enable nginx # Sets Nginx to boot automatically
sudo systemctl start nginx # Start Nginx
systemctl status nginx # View Nginx status

If the green active flag appears, the startup is successful. If the red mailed appears, there may be a problem with the configuration file and it is recommended to check it.
Next, we can access the server IP: port number in the browser to check whether nginx is running normally (at this time, the root directory of the nginx configuration file is required to contain the default accessed page).
If a welcome page similar to the following image appears, nginx works fine. At this point, the nginx configuration is complete.

Third, Mysql deployment

Go to /home/, download the mysql yum source.

wget https://repo.mysql.com//mysql80-community-release-el8-1.noarch.rpm

Use rpm to install mysql and yum to install mysql services.

sudo rpm -ivh mysql80-community-release-el8-1.noarch.rpm
sudo yum install mysql-server

Start mysql and set boot auto-start. Check the mysql running status when you are done:

sudo systemctl start mysqld # Start mysql
sudo systemctl enable mysqld # Sets mysql boot-start-up
systemctl status mysqld # Checks the mysql health status

If the word active appears in green, it means that mysql is working normally. Next we configure mysql. The author encountered some trouble in the configuration, according to other tutorials on the Internet, to look at the temporary password in the log when myslq was first used, in order to log in. Here's how:

grep ‘temporary password’ /var/log/mysqld.log

However, after the author finished executing, there was no returned data, and there was no record of passwords for manual viewing of the log. Finally log in successfully using root and empty password. Please pay attention here. Here is the command to log in to mysql:

mysql -uroot -p[mysql password]

The occurrence of mysql > indicates that the login is successful. First reset the root user's password:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'password';    # Note the quotation marks

Postscript: Mysql 8.0 uses the caching_sha2_password authentication mechanism by default. It may not be supported in some client programs. Please use:

ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password';

Next, configure the database for WordPress:

CREATE DATABASE [WordPress database name];    # Create a database
CREATE USER [Access WordPress username] @localhost IDENTIFIED BY '[Password for WordPress database user]';    # Create a WordPress user and set a password
GRANT ALL ON [wp database].* TO [WP database user];
# This command differs from other versions on mysql 8.0, so please note that it is modified with version.
FLUSH PRIVILEGES;    # Refresh permissions

At this point, the mysql configuration is over. In the next blog, I'll do the final PHP configuration and install WordPress for the initial setup.