home page Deploy LNMP environment (Alibaba Cloud Linux 3)

Deploy LNMP environment (Alibaba Cloud Linux 3)

Updated: 2024-08-20 16:47:48

ecs

Manual configuration

forty

Tutorial Introduction

This tutorial provides guidelines for building a LNMP environment on Alibaba Cloud ECS based on the Alibaba Cloud Linux 3 operating system. LNMP is a widely used website service system, which is composed of four free open source software Linux, Nginx, MySQL and PHP. After setting up the LNMP environment, you can set up a website, visit a website, set up a development environment, etc. on the ECS instance.

ECS is a secure, reliable, elastic and scalable cloud computing service that helps you reduce IT costs, improve operation and maintenance efficiency, and focus more on core business innovation. For more information, see Features and advantages

This tutorial takes the Alibaba Cloud Linux 3.2104 LTS 64 bit operating system as an example. If your ECS server uses another version of the operating system, the operation may be slightly different from this tutorial.

What can I learn

  • Be familiar with the ECS instance of remote login Linux operating system.

  • Learn to build a LNMP environment on ECS instances.

Operation difficulty

in

Time required

40 minutes

AliCloud products used

Required expenses

0 yuan

Prepare environment and resources

ten

Before starting the tutorial, prepare the environment and resources as follows:

  1. visit AliCloud free trial Click the Login/Registration Button, and complete account login (existing AliCloud account), account registration (no AliCloud account), or real name authentication (personal real name authentication or enterprise real name authentication according to the requirements of the trial product) according to the page prompts.

  2. After successful login Product category Lower Selection Computing>ECS , click in the right area Try it now, Select the specifications of the trial ECS as required in the pop-up box. The instance type used in this trial tutorial is Economical 2-core 4GB , free trial 1181 hours In actual operation, it is recommended to select according to your business volume and needs.

  3. stay Configure ECS instance information Panel to complete parameter configuration. The configuration of this tutorial is as follows (please configure as required according to the business requirements):

    • Region: East China 1 (Hangzhou), it is recommended to choose a region close to your customers

    • Operating system: Alibaba Cloud Linux 3.2104 LTS 64 bit

    • Other parameters: keep the default value or select as required

  4. Once you agree to the agreement, click try now , and complete the trial application according to the page prompts.

    It usually takes 3-5 minutes to create an instance. Please wait patiently. When the instance status changes to In operation The instance creation is completed.

     image

Log in to ECS

four

After opening the free trial ECS server, the system will create an ECS instance (corresponding to an ECS). Before deploying an application or setting up an environment using an ECS instance, you need to set an instance password before you can log in to the instance.

  1. Sign in ECS Console , on the left navigation bar, select Instance and Image>Instance

  2. In the upper left corner of the top menu bar, select the same region as the trial instance.

  3. Set the login password of this instance. Click in the Action column icon1 >Instance Properties>Reset Instance Password , set the login password of the ECS instance according to the interface prompts. After saving the password, on the pop-up page, click Restart Now Make the password effective.

    Resetting the instance password is supported about 3-5 minutes after the instance creation is completed. If it cannot be reset, please wait patiently and try again.

     image

  4. Click the ID of the trial instance and select Security Group Tab, click Security Group operation Column Configure Rules , add the port to be released in the incoming direction. In this tutorial, SSH default port 22, Nginx default port 80, and MySQL default port 3306 are released in the security group entry direction.

     image

  5. Connect ECS instances remotely.

    1. return example Page, click the Remote connection

    2. In the pop-up connection and command dialog box, click Connect remotely through Workbench Corresponding Sign in now

    3. In the pop-up login instance dialog box, enter the login information.

Install Nginx Service

five

  1. Run the following command to install Nginx.

     sudo yum -y install nginx
  2. Execute the command to start nginx and set the auto start.

    If Apache has been installed in your experience environment before, port 80 may be occupied. You can execute the command netstat -apn|grep 80 Check the port occupancy and execute the command systemctl stop httpd.service Stop the Apache service and finally execute the command sudo systemctl start nginx Restart Nginx.

     sudo systemctl start nginx sudo systemctl enable nginx
  3. Execute the command to view the running status of nginx. If the echo message shows active (running), nginx is started.

     sudo systemctl status nginx

Install MySQL database

ten

  1. Execute the command to download and install the MySQL database. Echo information display Complete! , indicating that the MySQL database is successfully installed.

     wget  http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm sudo yum install -y mysql57-community-release-el7-10.noarch.rpm sudo yum install -y mysql-community-server --nogpgcheck
  2. Execute the command to start the MySQL database.

     sudo systemctl start mysqld.service
    explain

    If the above command fails to execute and the MySQL database cannot be started, you can try to execute sudo /etc/init.d/mysqld start Command to start the MySQL database.

  3. Execute the command to view the running status of the MySQL database. If echo information displays active(running) Indicates that the MySQL database has been started.

     systemctl status mysqld.service
  4. Execute the command to view the initial password of the MySQL database.

     sudo grep "password" /var/log/mysqld.log

     image

  5. Execute the command to log in to the MySQL database. Enter the initial password of the MySQL database according to the echo information.

     mysql -uroot -p

     image

  6. Execute the command to modify the initial password of the MySQL database.

    • The password must contain three types of characters, including uppercase and lowercase English letters, numbers and special symbols.

    • Note that every complete SQL command has a semicolon (;) at the end. If there is no semicolon separation between multiple lines of commands, these commands will not be executed until a semicolon is encountered.

     ALTER USER 'root' @ 'localhost' IDENTIFIED BY '<new password>';
  7. Execute the command to create a database for storing blog site content, for example: wordpress

     create database wordpress;
  8. Execute the command to check whether the database is created successfully. If echo information displays wordpress , indicating that the database was created successfully.

     show databases;

     image

  9. input exit , exit the database.

Installing the PHP environment

five

  1. Execute the command to update the remi source.

    Execute the command to update the remi source.

     sudo rpm -ivh  https://rpms.remirepo.net/enterprise/remi-release-8.rpm  --nodeps
  2. Execute the command to install PHP and related libraries.

     sudo dnf update -y dnf libdnf sudo sed -i 's/PLATFORM_ID="platform:al8"/PLATFORM_ID="platform:el8"/g' /etc/os-release sudo yum -y module install php:remi-7.4 sudo sed -i 's/PLATFORM_ID="platform:el8"/PLATFORM_ID="platform:al8"/g' /etc/os-release
  3. Execute the command to add PHP support to the nginx. conf file.

     sudo vim /etc/nginx/nginx.conf
  4. After entering the Vim Editor, press i Key to enter edit mode.

  5. stay server In the braces, add the following configuration information.

    • add to location / Configuration information.

       location / { index index.php index.html index.htm; }
    • add to location ~ .php$ Configuration information.

       if (!- e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; } location ~ .*\.php(\/.*)*$ { fastcgi_pass   127.0.0.1:9000; include       fastcgi.conf; fastcgi_index  index.php; }

       image

  6. Press Ecs Key, entering :wq Press Enter Key, save and exit the Vim editor.

  7. Execute the command to restart the php fpm service.

     sudo systemctl start php-fpm
  8. Execute the command to restart the Nginx service.

     sudo systemctl start nginx
  9. Create a PHP test page phpinfo.php in the root directory of Nginx's website.

     sudo sh -c 'echo "<? php echo phpinfo(); ?> " > /usr/share/nginx/html/phpinfo.php'
  10. Enter in the browser address bar Http://<ECS instance public IP address>/phpinfo.php , a page similar to the following appears, indicating that the PHP environment was successfully installed.

     image

complete

one

After completing the above operations, you have successfully set up the LNMP environment, which represents Linux, Nginx, MySQL and PHP respectively.

Cleaning and follow-up

five

clear

This tutorial uses an enterprise ECS instance, which defaults to a monthly subscription instance. After completing this tutorial, please refer to the following rules for cleaning up:

  • When the subscription instance expires, it will be automatically released. When the instance is released, the data will be released at the same time.

  • If you need to continue using the instance, please renew it before the trial expires. Instances that have not been renewed upon expiration will be automatically shut down due to arrears. The instance will be retained within 15 days of downtime, and the instance and data will be automatically released after 15 days.

follow-up

After the LNMP is built, you can build a website, a development environment, bind and resolve the domain name on the ECS instance Use domain name to access website And so on. See Introduction to Zero Foundation of Station Construction and How Linux instances bind domain names in Web services

summary

Common Knowledge points

Question 1: After installing Nginx, you cannot access it through the public IP address of the ECS instance. Please ensure that which port Nginx uses by default has been released in the security group? (Single topic)

  • twenty-two

  • eighty

  • three thousand three hundred and sixty-nine

The correct answer is 80. Nginx is the Web Server. The default port number is 80. Therefore, port 80 needs to be released.

Question 2: How to view the initial password of the root user of the MySQL database after installing the MySQL database? (Single topic)

  • implement grep "password" /var/log/mysqld.log Command.

  • implement grep "password"|grep /etc/nginx/nginx.conf Command.

  • implement grep "password" /var/log/mysql.log Command.

The correct answer is to execute grep "password" /var/log/mysqld.log Command. When MySQL is initially installed, a temporary root password will be generated and recorded in/var/log/mysqld.log.

Extended Reading

One click configuration

twenty-five

Tutorial Introduction

This tutorial provides guidelines for building a LNMP environment on Alibaba Cloud ECS based on the Alibaba Cloud Linux 3 operating system. LNMP is a widely used website service system, which is composed of four free open source software Linux, Nginx, MySQL and PHP. After setting up the LNMP environment, you can set up a website, visit a website, set up a development environment, etc. on the ECS instance.

ECS is a secure, reliable, elastic and scalable cloud computing service that helps you reduce IT costs, improve operation and maintenance efficiency, and focus more on core business innovation. For more information, see Features and advantages

This tutorial takes the Alibaba Cloud Linux 3.2104 LTS 64 bit operating system as an example. If your ECS server uses another version of the operating system, the operation may be slightly different from this tutorial.

What can I learn

  • Be familiar with the ECS instance of remote login Linux operating system.

  • Learn to build a LNMP environment on ECS instances.

Operation difficulty

in

Time required

25 Minutes

AliCloud products used

Required expenses

0 yuan

Prepare environment and resources

ten

Before starting the tutorial, prepare the environment and resources as follows:

  1. visit AliCloud free trial Click the Login/Registration Button, and complete account login (existing AliCloud account), account registration (no AliCloud account), or real name authentication (personal real name authentication or enterprise real name authentication according to the requirements of the trial product) according to the page prompts.

  2. After successful login Product category Lower Selection Computing>ECS , click in the right area Try it now, Select the specifications of the trial ECS as required in the pop-up box. The instance type used in this trial tutorial is Economical 2-core 4GB , free trial 1181 hours In actual operation, it is recommended to select according to your business volume and needs.

  3. stay Configure ECS instance information Panel to complete parameter configuration. The configuration of this tutorial is as follows (please configure as required according to the business requirements):

    • Region: East China 1 (Hangzhou), it is recommended to choose a region close to your customers

    • Operating system: Alibaba Cloud Linux 3.2104 LTS 64 bit

    • Other parameters: keep the default value or select as required

  4. Once you agree to the agreement, click try now , and complete the trial application according to the page prompts.

    It usually takes 3-5 minutes to create an instance. Please wait patiently. When the instance status changes to In operation The instance creation is completed.

     image

One click configuration

five

After resources are ready, you can quickly complete resource configuration or application setup through one click configuration. One click configuration is based on AliCloud Resource Orchestration Service (ROS), which is designed to help developers experience the automated configuration of resources through IaC (Infrastructure as Code). To view the specific configuration information such as software version and installation command, you can view the Manual configuration version The completed contents of the template include:

  • Create security groups for ECS instances

  • Install Nginx Service

  • Install MySQL database and modify the default password of database root user

  • Installing the PHP environment

Operation steps

  1. open One click configuration template link Go to the ROS console, and the system will automatically open the panel to create a resource stack using new resources Template content The area shows the details of the YAML file.

  2. The ROS console is in the region you last accessed the console by default. Please modify the region according to the region of the resource you created. After confirming the region, keep all the options on the page unchanged and click next step get into Configure template parameters Page.

  3. stay Configure template parameters Modify the resource stack name on the page, select the ECS instance created when you applied for free trial, and modify the default password of the database root user by setting the MySQL database password. After filling in all required information and confirming, click establish Start one click configuration.

    • Installing Nginx, MySQL and PHP requires downloading applications over the Internet. The configuration time may vary due to network stability and other reasons. During the waiting period, you can refresh Resource stack information Page to see if the configuration is complete or by clicking event Tab to view the detailed configuration progress.

    • If you repeat the one click configuration template of this tutorial on the same ECS instance, make sure that the MySQL database password is exactly the same as the password set when you first executed the template. Otherwise, the one click configuration result is unavailable.

  4. When Resource stack information Of the page state Show as Created successfully Indicates that one click configuration is complete.

     image

complete

five

Click ROS Console output In the tab PhpUrl Http://<ECS public IP address>/phpinfo.php ), the PHP version information page appears, indicating that the LNMP environment was successfully installed.

If you need to use the root user to log in to the ECS instance remotely, set the password and log in to the ECS instance remotely. See Reset instance login password and Log in to the Linux instance through password or key authentication

 image

Cleaning and follow-up

five

clear

This tutorial uses an enterprise ECS instance, which defaults to a monthly subscription instance. After completing this tutorial, please refer to the following rules for cleaning up:

  • When the subscription instance expires, it will be automatically released. When the instance is released, the data will be released at the same time.

  • If you need to continue using the instance, please renew it before the trial expires. Instances that have not been renewed upon expiration will be automatically shut down due to arrears. The instance will be retained within 15 days of downtime, and the instance and data will be automatically released after 15 days.

follow-up

After the LNMP is built, you can build a website, a development environment, bind and resolve the domain name on the ECS instance Use domain name to access website And so on. See Introduction to Zero Foundation of Station Construction and How Linux instances bind domain names in Web services

summary

Common Knowledge points

Question 1: Which database is used to build the LNMP environment in this tutorial? (Single topic)

  • Mariadb

  • MySQL

The correct answer is MySQL.

Question 2: After setting up LNMP, how to verify whether Nginx is successfully installed in the output tab of the ROS console? (Single topic)

  • Click PhpUrl (http://<ECS public IP address>/phpinfo. php), and the PHP version information page appears.

  • Click PhpUrl (http://<ECS public IP address>/phpinfo. php), and the Welcome to nginx! Page.

  • Click NginxUrl (http://<ECS public IP address>), and the Welcome to nginx! Page.

The correct answer is to click NginxUrl (http://<ECS public IP address>) Welcome to nginx! Page.

Extended Reading