全国服务热线:13864198606

新闻中心 PRODUCT DISPLAY

罗定手工搭建LNMP环境(CentOS7.2 PHP7.0)

来源: 发布时间:2024-06-24 1639 次浏览

本文主要介绍了在华为云上如何使用弹性云服务器的Linux实例手工搭建LNMP平台的web环境。该指导

简介

云平台服务__<a href='http://huaweicloud.58g.com.cn' target='_blank' title='华为云'><strong>华为云</strong></a>服务登录__华为云服务网站

本文主要介绍了在华为云上如何使用弹性云服务器的Linux实例手工搭建LNMP平台的web环境。该指导具体操作以CentOS 7.2 64位操作系统为例。

Linux实例手工部署LNMP环境具体操作步骤如下:

安装nginx。

安装MySQL。

安装PHP。

浏览器访问测试。

前提条件

弹性云服务器已绑定弹性公网IP。

弹性云服务器所在安全组添加了如下表所示的安全组规则,具体步骤参见为安全组添加安全组规则。

表1 安全组规则

方向

协议/应用

端口/范围

源地址

入方向

HTTP(80)

80

0.0.0.0/0

为了更好的获取和更新系统和软件,建议您更新镜像源为华为云镜像源,详细操作,请参见如何使用自动化工具配置华为云镜像源(x86_64和ARM)?。

资源规划

本次实践所用的资源配置及软件版本如表2中所示。当您使用不同的硬件规格或软件版本时,本指导中的命令及参数可能会发生改变,需要您根据实际情况进行调整。

表2 资源和成本规划

资源

资源说明

成本说明

弹性云服务器

计费模式:按需计费

可用区:可用区1

规格:s6.large.2

镜像:CentOS 7.2 64bit

系统盘:40G

弹性公网IP:现在购买

线路:全动态BGP

公网带宽:按流量计费

带宽大小:5 Mbit/s

ECS涉及以下几项费用:

云服务器

云硬盘

弹性公网IP

具体的计费方式及标准请参考计费模式概述。

Nginx

是一个高性能的HTTP和反向代理web服务器。

获取方式:

http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

免费

MySQL

是一款开源的关系数据库软件。

获取方式:

http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm

免费

PHP

是一款开源软件,用于Web开发。

获取方式:

https://mirror.webtatic.com/yum/el7/epel-release.rpm

https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

免费

操作步骤

安装nginx。

登录弹性云服务器。

执行以下命令,下载对应当前系统版本的nginx包。

wget http://nginx.org/packages/centos/7/noarch/RPMS/nginx-release-centos-7-0.el7.ngx.noarch.rpm

执行以下命令,建立Nginx的yum仓库。

rpm -ivh nginx-release-centos-7-0.el7.ngx.noarch.rpm

执行以下命令,安装Nginx。

yum -y install nginx

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

systemctl start nginx

systemctl enable nginx

查看启动状态。

systemctl status nginx.service

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

图1 测试访问nginx

安装MySQL。

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

wget -i -c 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

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

systemctl start mysqld

systemctl enable mysqld

查看MySQL运行状态。

systemctl status mysqld.service

[root@ecs-adc3 ~]# systemctl status mysqld.service

● mysqld.service - MySQL Server

   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)

   Active: active (running) since Mon 2021-08-16 19:33:40 CST; 36s ago

     Docs: man:mysqld(8)

           http://dev.mysql.com/doc/refman/en/using-systemd.html

 Main PID: 7916 (mysqld)

   CGroup: /system.slice/mysqld.service

           └─7916 /usr/sbin/mysqld --daemonize --pid-file=/var/run/mysqld/mysqld.pid

Aug 16 19:33:35 ecs-adc3 systemd[1]: Starting MySQL Server...

Aug 16 19:33:40 ecs-adc3 systemd[1]: Started MySQL Server.

执行以下命令,获取安装MySQL时自动设置的root用户密码。

grep 'temporary password' /var/log/mysqld.log

回显如下类似信息。

2018-08-29T07:27:37.541944Z 1 [Note] A temporary password is generated for root@localhost: 2YY?3uHUA?Ys

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

mysql_secure_installation

Securing the MySQL server deployment.

Enter password for user root:    #输入上一步骤中获取的安装MySQL时自动设置的root用户密码

The existing password for the user account root has expired. Please set a new password.

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

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

The 'validate_password' plugin is installed on the server.

The subsequent steps will run with the existing configuration of the plugin.

Using existing password for root.

Estimated strength of the password: 100

Change the password for root ? ((Press y|Y for Yes, any other key for No) : N   #是否更改root用户密码,输入N

 ... skipping.

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!

安装PHP。

依次执行以下命令,安装PHP 7和一些所需的PHP扩展。

rpm -Uvh https://mirror.webtatic.com/yum/el7/epel-release.rpm

rpm -Uvh https://mirror.webtatic.com/yum/el7/webtatic-release.rpm

yum -y install php70w-tidy php70w-common php70w-devel php70w-pdo php70w-mysql php70w-gd php70w-ldap php70w-mbstring php70w-mcrypt php70w-fpm

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

php -v

回显如下类似信息:

PHP 7.0.31 (cli) (built: Jul 20 2018 08:55:22) ( NTS )

Copyright (c) 1997-2017 The PHP Group

Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies

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

systemctl start php-fpm

systemctl enable php-fpm

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

执行以下命令打开配置文件/etc/nginx/nginx.conf。

vim /etc/nginx/nginx.conf

图2 nginx.conf

从nginx.conf可以看出,配置文件定向至/etc/nginx/conf.d/*.conf。

输入:quit退出nginx.conf。

执行以下命令打开配置文件/etc/nginx/conf.d/default.conf。

vim /etc/nginx/conf.d/default.conf

按i键进入编辑模式。

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

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

    server {

        listen       80;

        server_name  localhost;

        #access_log /var/log/nginx/host.access.log  main;

    location / {

        root   /usr/share/nginx/html;

        index  index.php index.html index.htm;    }

    location ~ \.php$ {

        root           html;

        fastcgi_pass   127.0.0.1:9000;

        fastcgi_index  index.php;

        fastcgi_param  SCRIPT_FILENAME /usr/share/nginx/html$fastcgi_script_name;

        include        fastcgi_params;

    }

  }

如图3所示:

图3 修改后截图

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

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

service nginx reload

浏览器访问测试。

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

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

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

按i键进入编辑模式。

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

<?php

 phpinfo();

?>

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

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



华为云共建智能世界云底座[52] 华为公有云专属云主机DeH服务[51] 华为云场景化解决方案[49] 华为公有云产品[44] 华为云云主机[43] 华为云产品服务[43] 华为云服务器应用[43] 华为弹性云服务器[39] 华为公有云架构解决方案[38] 华为云提供的服务[37] 华为虚拟私有云vpc[37] 华为公有云介绍[32] 华为公有云提供哪些计算服务[30] 华为云漏洞扫描[27] 华为云软件开发服务[27] 华为公有云和私有云区别[27] 华为云域名注册[26] 华为云官网登陆[26] 华为公有云解决方案[26] 华为私有云产品有哪些[26] 华为私有云服务[25] 华为云数据库[23] 华为云安全[22] 华为公有云官网[22] 华为私有云的搭建方案[22] 华为云弹性云服务器应用[21] 华为公有云平台[20] 华为公有云行业解决方案[20] 华为私有云解决方案服务定制领导者[20] [19] 华为私有云服务器[19] 华为私有云网格结构[19] 华为公有云视讯解决方案[18] 华为云官网[17] 华为云速建站[17] 华为私有云架构[17] 华为云优势[16] 华为云服务器[16] 华为私有云部署架构[16] 华为云企业邮箱服务 (SAAS[15] 华为云邮箱[15] 华为公有云是什么[15] 华为公有云架构[15] 华为云迁移解决方案[14] 华为公有云解决方案服务定制领导者[14] 华为私有云解决方案[14] 云邮箱)[13] 华为云园区解决方案[13] 华为云服务总代理[13] 华为云速智能客服[13] 华为公有云服务[13] 华为私有云搭建方案[13] 云与计算咨询服务[12] 云与计算培训服务[11] 华为云备份[11] 华为云服务器配置[11] 华为云服务服务中心[11] 华为云服务核心分销商[11] 华为公有云[11] 华为私有云搭建[11] 云迁移与运营支撑服务[10] 公有云私有云混合云[10] 华为云服务器ECS[10] 华为云服务器成功案例[10] 华为云解决方案[10] 华为公有云通用解决方案[9] 华为智慧云课堂解决方案[9] 华为云数据解决方案[8] 华为云是什么[8] 华为私有云平台[8] 云与计算客户支持与运维使能服务[7] 华为云官网网站[7] 华为云智慧教育解决方案[7] 华为云智慧校园解决方案[7] 华为云桌面系统集成商[7] 华为云经销商[7] 华为代理公司有哪些[7] 华为私有云方案[7] 智慧教育云平台解决方案[7] 华为云服务器试用[6] 华为云网站建设服务器[6] 华为手机代理加盟[6] 华为私有云[6] 大数据使能服务[6] 智慧教育云计算解决方案[6] 华为云云主机 [5] 华为云智慧***解决方案[5] 华为云桌面总代理商[5] 云与计算客户支持服务[4] 华为云产品介绍[4] 华为云智慧制造解决方案[4] 华为云场景化解决方案[3] 华为公有云官网[3] 华为公有云通用解决方案[3] 华为弹性云服务器[3] 华为公有云产品 [3] 华为云产品服务[2] 华为云域名注册[2] 华为云数据库[2] 华为云智慧校园解决方案[2] 华为云服务器应用[2] 华为云服务器成功案例[2] 华为云软件开发服务[2] 华为公有云产品[2] 华为公有云介绍[2] 华为公有云和私有云区别[2] 华为公有云服务[2] 华为公有云架构[2] 华为公有云架构解决方案[2] 华为公有云视讯解决方案[2] 华为公有云解决方案[2] 华为私有云产品有哪些[2] 华为私有云服务[2] 华为私有云架构[2] 智慧教育云计算解决方案[2] 云规划设计与实施服务[2] 云邮箱[2] 华为云产品报价[2] 华为公有云通用解决方案 [2] 华为云服务器成功案例[1] 华为云桌面系统集成商[1] 云与计算客户支持与运维使能服务[1] 云迁移与运营支撑服务[1] 云迁移与运营支撑服务 [1] 华为云共建智能世界云底座[1] 华为云备份[1] 华为云安全[1] 华为云官网登陆[1] 华为云弹性云服务器应用[1] 华为云提供的服务[1] 华为云数据解决方案[1] 华为云智慧制造解决方案[1] 华为云服务器[1] 华为云服务核心分销商 [1] 华为云漏洞扫描[1] 华为云迁移解决方案 [1] 华为云速智能客服[1] 华为云邮箱[1] 华为公有云专属云主机DeH服务[1] 华为公有云是什么[1] 华为公有云行业解决方案[1] 华为私有云搭建[1] 华为私有云方案[1] 华为私有云服务.华为公有云专属云主机DeH服务.华为云产品报价[1] 华为私有云的搭建方案[1] 华为私有云网格结构[1] 华为私有云解决方案[1] 华为私有云部署架构[1] 为云产品服务[1] 云与计算咨询服务 [1] 云与计算客户支持与运维使能服务 [1] 云与计算客户支持与运维使能服务 云与计算客户支持服务[1] 华为云是什么 [1] 华为云软件开发服[1] 华为云速智能客服 [1] 华为代理加盟[1] 华为公有云架构解决方案 [1] 华为公有云解决方案服务定制领导者 [1] 华为弹性云[1] 华为弹性云服务器 华为云域名注册 华为云服务器应用[1] 华为私有云搭建 [1] 华为私有云搭建方案 [1] 华为私有云部署架构 [1] 大数据使能服务 [1] 撒[1]