×
Community Blog Hands-on Labs | Build LNMP Environment Step by Step

Hands-on Labs | Build LNMP Environment Step by Step

This step-by-step tutorial introduces how to build LNMP environment on Alibaba Cloud ECS.

>> Get hands-on experience with this tutorial in a lab environment.


1. Configure Resources

This section is for reference. If you have already configured your resources, please skip this section and move to the next.

1.  On the basic configuration page, configure the ECS basic configuration according to the following instructions. The configuration that is not mentioned remains the default option, and then click Next: Network and security group.

1

Note: the following configurations are used in this experiment. The configurations not mentioned remain the default options.

Configuration description:

2

Configuration item Example Explain
Region and zone Region: Singapore
Zone: Singapore Zone B
After an instance is created, you cannot directly change the region and zone.
Instance type Type family: ecs.t5-c1m1.large (Standard) You can go to the ECS instance purchase region to view the instance purchase status in each region.
Image Type: Public image
Version: CentOS 7.9 64 bit
After the instance is started, the system disk will completely copy the operating system and application data of the image.

2.  On the network and security groups page, configure the ECS network and security group according to the following instructions. The configuration that is not mentioned remains the default option, and then click Next: Network and security group.

Configuration description:

Configuration item Example Explain
VPC Default VPC Select your VPC. To create a VPC, click create in the console.
VSwitch Default vSwitch Select your vSwitch. To create a vSwitch, click create in the console.
Assign public IPv4 addresses Select assign public IPv4 address When selected, a public IPv4 address is automatically assigned.
Bandwidth billing mode Pay-by-traffic You only need to pay for the Internet traffic consumed by using the traffic mode. For more information, see Internet bandwidth billing.
Peak bandwidth 5 Mbps None.
Security Group Default security group Select your security group. You must enable ports 80, 443, 22, 3389, and 3306. To create a security group, click Create Security Group.

3.  On the System configuration page, configure the ECS system configuration according to the following instructions. The configuration that is not mentioned remains the default option, and then click Next: Group settings.

Configuration description:

Configuration item Example Explain
login credentials Custom password In this tutorial, select a custom password and manually set a password for remote connection and sign in to the ECS instance.
Sign-in password Ecs123456 When you select a custom password for the Sign-in credential, you must set this option and confirm the password. When you connect to the ECS instance later, you must enter the username root and the password set here.
Instance name EcsQuickStart You can customize the instance name.

4.  On the Group settings page, all configurations remain the default option, confirm the order, and Create an instance.

2. Connect to ECS Server

After the resource is created, the Web Terminal server Terminal operation interface is opened by default. You can also click on the right side icon Button to switch to the Web Terminal operation interface.

3. Install and Configure MySQL

1.  Run the following command to download and install the official MySQL Yum Repository.

wget http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql57-community-release-el7-10.noarch.rpm
yum -y install mysql-community-server --nogpgcheck

3

2.  Run the following command to start the MySQL database.

systemctl start mysqld.service

3.  Run the following command to view the running status of MySQL.

systemctl status mysqld.service

4

4.  Run the following command to view the initial MySQL password.

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

5

5.  Run the following command to log in to the database.

mysql -uroot -p

6

6.  Run the following command to modify the MySQL default password.

set global validate_password_policy=0;  #Modify the password security policy to low (only verify the password length, at least 8 digits)。
ALTER USER 'root'@'localhost' IDENTIFIED BY '12345678';

7.  Run the following command to grant the root user the remote management permission.

GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '12345678';

8.  Enter exit to exit the database.

4. Install Nginx

1.  Install the plug-in required for Nginx.

• Install gcc. gcc is a Linux compiler that can compile languages such as C, C ++, Ada, Object C, and Java.

yum -y install gcc

• Install pcre. pcre is a perl library. The HTTP module of Nginx uses pcre to parse regular expressions.

yum install -y pcre pcre-devel

• Install zlib. zlib is a library for file compression and decompression. Nginx uses zlib to compress and decompress HTTP packets in gzip.

yum install -y zlib zlib-devel

2.  Download the Nginx installation package.

wget http://nginx.org/download/nginx-1.17.10.tar.gz

3.  Decompress the Nginx installation package.

tar -zxvf nginx-1.17.10.tar.gz

4.  Compile and install Nginx.

cd nginx-1.17.10
./configure
make && make install

5.  Start Nginx.

cd /usr/local/nginx/
sbin/nginx

6.  Test Nginx startup. Enter the public IP address of the ECS server in the address bar of the browser, for example, 123.123.123.123. The following interface appears to indicate that the installation is successful.

7

5. Install PHP

1.  Install PHP.

yum -y install php php-mysql php-fpm

2.  Add support for PHP to the nginx.conf file.

vim /usr/local/nginx/conf/nginx.conf

After entering the Vim editor, press the i to enter the edit mode, and add index.php to the root route configuration of the server.

location / {
      root   html;
      index  index.html index.htm index.php;
}

Add the following configurations under the root route.

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;
}

The following figure shows the modified nginx.conf file.

8

Press ESC and enter :wq save and exit Vim editor.

3.  Restart the php-fpm service.

systemctl restart php-fpm

4.  Restart the Nginx service.

/usr/local/nginx/sbin/nginx -s reload

5.  Check the PHP installation.

a) Create a PHP probe file phpinfo.php in the root directory of the Nginx website.

echo "<?php phpinfo(); ?>" > /usr/local/nginx/html/phpinfo.php

b) Visit the PHP probe page. Enter xx.xx.xx.xx/phpinfo.php in the address bar of your browser (replace xx.xx.xx.xx with the public IP address of the ECS server). The following page indicates that the PHP environment has been configured successfully.

9


>> Get hands-on experience with this tutorial in a lab environment.

0 1 0
Share on

Alibaba Cloud Community

943 posts | 219 followers

You may also like

Comments