侧边栏壁纸
博主头像
STONE

行动起来,活在当下

  • 累计撰写 70 篇文章
  • 累计创建 67 个标签
  • 累计收到 5 条评论

目 录CONTENT

文章目录

手工搭建LNMP环境(Huawei Cloud EulerOS 2.0)

STONE
2023-10-04 / 0 评论 / 0 点赞 / 84 阅读 / 0 字
温馨提示:
本文最后更新于2024-06-19,若内容或图片失效,请留言反馈。 部分素材来自网络,若不小心影响到您的利益,请联系我们删除。

手工搭建LNMP环境(Huawei Cloud EulerOS 2.0)

操作步骤

安装Nginx

登录弹性云服务器。

执行以下命令,安装Nginx。

sudo yum -y install nginx

执行以下命令,验证Nginx的安装版本。

nginx -v

回显如下类似信息:

nginx version: nginx/1.21.5

执行以下命令,启动Nginx并设置开机启动。

systemctl start nginx

systemctl enable nginx

查看启动状态。

systemctl status nginx.service

回显如下类似信息。

点击放大

使用浏览器访问 “http://服务器IP地址”,显示如下页面,说明Nginx安装成功。

图1 测试访问Nginx
点击放大

安装MySQL

依次执行以下命令,安装MySQL。

mkdir mysql-server

cd mysql-server

wget https://repo.huaweicloud.com/hce/2.0/os/x86_64/Packages/mysql-8.0.28-1.hce2.x86_64.rpm

yum install mysql-server

依次执行以下命令,启动MySQL服务并设置开机自启动。

systemctl start mysqld

systemctl enable mysqld

查看MySQL运行状态。

systemctl status mysqld.service

回显如下类似信息。

点击放大

执行以下命令,并按照回显提示信息进行操作,加固MySQL。

mysql_secure_installation

Securing the MySQL server deployment.

Connecting to MySQL using a blank password.

VALIDATE PASSWORD COMPONENT can be used to test passwords
and improve security. It checks the strength of password
and allows the users to set only those passwords which are
secure enough. Would you like to setup VALIDATE PASSWORD component?

Press y|Y for Yes, any other key for No : Y

There are three levels of password validation policy:

LOW    Length >= 8
MEDIUM Length >= 8, numeric, mixed case, and special characters
SERONG Length >= 8, numeric, mixed case, special characters and dictionary              file

Please enter 0 = LOW, 1 = MEDIUM and 2 = STRONG: 2
Please set the password for root here.

New password:  #设置新的root用户密码

Re-enter new password:   #再次输入密码

Estimated strength of the password: 100
Do you wish to continue with the password provided?(Press y|Y for Yes, any other key for No) : Y  #确认使用已设置的密码,输入Y
By default, a MySQL installation has an anonymous user,
allowing anyone to log into MySQL without having to have
a user account created for them. This is intended only for
testing, and to make the installation go a bit smoother.
You should remove them before moving into a production
environment.

Remove anonymous users? (Press y|Y for Yes, any other key for No) : Y   #是否删除匿名用户,输入Y
Success.

Normally, root should only be allowed to connect from 'localhost'. This ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? (Press y|Y for Yes, any other key for No) : Y   #禁止root远程登录,输入Y
Success.

By default, MySQL comes with a database named 'test' that anyone can access. This is also intended only for testing, and should be removed before moving into a production environment.

Remove test database and access to it? (Press y|Y for Yes, any other key for No) : Y   #是否删除test库和对它的访问权限,输入Y
 - Dropping test database...
Success.

 - Removing privileges on test database...
Success.

Reloading the privilege tables will ensure that all changes
made so far will take effect immediately.

Reload privilege tables now? (Press y|Y for Yes, any other key for No) : Y   #是否重新加载授权表,输入Y
Success.

All done!

执行以下命令,退出当前文件夹。

cd ~

安装PHP

依次执行以下命令,安装PHP 8。

wget https://repo.huaweicloud.com/hce/2.0/os/x86_64/Packages/php-8.0.0-10.hce2.x86_64.rpm

yum install php-8.0.0-10.hce2.x86_64.rpm

执行以下命令,验证PHP的安装版本。

php -v

回显如下类似信息:

img

执行以下命令,启动PHP服务并设置开机自启动。

systemctl start php-fpm

systemctl enable php-fpm

修改Nginx配置文件以支持PHP。

  1. 执行以下命令打开Nginx配置文件。

    vim /etc/nginx/nginx.conf

  2. i键进入编辑模式。

  3. 修改打开的“nginx.conf”文件。

    找到server段落,修改或添加下列配置信息。

        server {
            listen       80;
            listen       [::]:80;
            server_name  _;
            root         /usr/share/nginx/html;
            
            # Load configuration files for the default server block.
            include /etc/nginx/default.d/*.conf;
    
           location / {
               index  index.php index.html index.htm;    }
    
            location ~ .php$ {
                root /usr/share/nginx/html;    
                fastcgi_pass 127.0.0.1:9000;   
                fastcgi_index index.php;
                fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
                include fastcgi_params;   
            }
    

    图2所示:

    图2 修改后截图
    点击放大

  4. Esc键退出编辑模式,并输入**:wq**保存后退出。

执行以下命令,重新载入Nginx的配置文件。

service nginx reload

浏览器访问测试。

在/usr/share/nginx/html/目录下创建“info.php”的测试页面。

  1. 执行以下命令创建并打开“info.php”的测试文件。

    **vim /usr/share/nginx/html/**info.php

  2. i键进入编辑模式。

  3. 修改打开的“info.php”文件,将如下内容写入文件。

    <?php
     phpinfo();
    ?>
    
  4. Esc键退出编辑模式,并输入**:wq**保存后退出。

使用浏览器访问“http://服务器IP地址/info.php”,显示如下页面,说明环境搭建成功。

点击放大

0

评论区