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

Posted on 2020-03-12  2 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.