This article through Tencent cloud to provide documentation, Tencent cloud related information

Install Nginx

  1. Run the following command in/etc/yum.repos.d/createnginx.repoFile.
vi /etc/yum.repos.d/nginx.repo
Copy the code
  1. Press I to switch to edit mode and write the following.
[nginx] 
name = nginx repo 
baseurl = https://nginx.org/packages/mainline/centos/7/$basearch/ 
gpgcheck = 0 
enabled = 1
Copy the code
  1. Press Esc and enter :wq to save the file and return to the vi editor.
  2. Run the following command to install nginx.
yum install -y nginx
Copy the code
  1. Run the following command to enable thenginx.conffile
vim /etc/nginx/nginx.conf
Copy the code
  1. Conf file. Press I to switch to the editing mode and edit the nginx.conf file.

  2. Find a server {… }, and replace the corresponding configuration information in server braces with the following. This command is used to disable IPv6 address listening and configure Nginx to interwork 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
 #PHP ${fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME$document_root$fastcgi_script_name; include fastcgi_params; }}Copy the code
  1. Save the configuration, then run the following command to start Nginx.
systemctl start nginx
Copy the code
  1. Run the following command to set Nginx to boot automatically.
systemctl enable nginx
Copy the code
  1. Access the following address in your local browser to check whether the Nginx service is running properly.
http://public IP address of the cloud server instanceCopy the code

Installing the Database

  1. Run the following command to check whether MariaDB is installed in the system.
rpm -qa | grep -i mariadb
Copy the code

If the following information is displayed, MariaDB exists:

To avoid conflicts caused by different installation versions, run the following command to remove MariaDB that has been installed.

Yum -y remove The package nameCopy the code

If the command output is empty, the installation is not preinstalled. Go to the next step.

  1. Run the following command in/etc/yum.repos.d/createMariaDB.repoFile.
vi /etc/yum.repos.d/MariaDB.repo
Copy the code
  1. Press I to switch to edit mode and add the MariaDB software library by writing the following information.

Note: The MariaDB software library varies with operating systems. You can visit the Official website of MariaDB to obtain installation information about the MariaDB software library for other operating systems.

# MariaDB 10.4 CentOS repository list - created 2019-11-05 11:56 UTC
# http://downloads.mariadb.org/mariadb/repositories/
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Copy the code
  1. Press Esc and enter :wq to save the file and return to the vi editor.

  2. Run the following command to install MariaDB.

yum -y install MariaDB-client MariaDB-server
Copy the code
  1. Run the following command to start the MariaDB service.
systemctl start mariadb
Copy the code
  1. Run the following command to enable MariaDB to start automatically after startup.
systemctl enable mariadb
Copy the code
  1. Run the following command to verify that MariaDB is successfully installed.
mysql
Copy the code

Installing PHP

  1. Update the PHP software source in YUM by executing the following commands in sequence.
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
Copy the code
  1. Execute the following command to install the packages required for PHP 7.2.
yum -y install mod_php72w.x86_64 php72w-cli.x86_64 php72w-common.x86_64 php72w-mysqlnd php72w-fpm.x86_64
Copy the code
  1. Run the following command to start the php-fpm service.
systemctl start php-fpm
Copy the code
  1. Run the following command to enable the phP-fpm service to start automatically upon startup.
systemctl enable php-fpm
Copy the code

Verifying the Environment Configuration

After the environment is configured, you can perform the following steps to verify that the LNMP environment is successfully set up

  1. Run the following command to create a test file.
echo "
      " >> /usr/share/nginx/html/index.php
Copy the code
  1. Run the following command to restart the Nginx service.
systemctl restart nginx
Copy the code
  1. Access the following address in the local browser to check whether the environment configuration is successful.
http://public IP address of the cloud server instanceCopy the code