

喜讯:国内、香港、海外云服务器租用特惠活动,2核/4G/10M仅需31元每月,点击抢购>>>
点击这里进入阿里云ECS官方页面,立即免费体验云服务器ECS>>>
阿里云服务器ECS使用教程-部署LAMP环境(CentOS 7)
本文介绍如何使用云服务器ECS实例搭建LAMP平台,其中LAMP分别代表Linux、Apache、MySQL和PHP。
前提条件
已创建ECS实例并为实例分配公网IP地址。具体操作,请参见创建方式导航。
本文示例步骤中,使用以下配置的ECS实例。实际操作时,建议您保持操作系统版本一致,避免因操作系统版本问题导致的命令执行报错。
实例规格:ecs.c6.large
操作系统:公共镜像CentOS 7.8 64位
网络类型:专有网络VPC
IP地址:公网IP
已在实例安全组的入方向添加安全组规则并放行22、80端口。具体操作请参见添加安全组规则。
本文适用于熟悉Linux操作系统,初次使用阿里云进行建站的个人用户。在示例步骤中使用了以下版本的软件。操作时,请您以实际软件版本为准。 Apache:2.4.6 MySQL:5.7.31 PHP:7.0.33 phpMyAdmin:4.0.10.20 本文主要说明手动安装LAMP平台的操作步骤,您也可以在云市场购买LAMP镜像直接启动ECS,以便快速建站。 点我去体验 使用向导创建实例。 通过密码或密钥认证登录Linux实例。 运行命令cat /etc/redhat-release查看系统版本。 关闭防火墙。 如果您想临时关闭防火墙,运行命令systemctl stop firewalld。 说明 这只是暂时关闭防火墙,下次重启Linux后,防火墙还会开启。 如果您想永久关闭防火墙,运行命令systemctl disable firewalld。 说明 如果您想重新开启防火墙,请参见firewalld官网信息。 如果防火墙的状态参数是inactive,则防火墙为关闭状态。 如果防火墙的状态参数是active,则防火墙为开启状态。本示例中防火墙为开启状态,因此需要关闭防火墙。 运行systemctl status firewalld命令查看当前防火墙的状态。 关闭防火墙。如果防火墙为关闭状态,请忽略此步骤。 关闭SELinux。 如果您想临时关闭SELinux,运行命令 说明 这只是暂时关闭SELinux,下次重启Linux后,SELinux还会开启。 如果您想永久关闭SELinux,运行命令vi /etc/selinux/config编辑SELinux配置文件。回车后,把光标移动到 说明 如果您想重新开启SELinux,请参见SELinux的官方文档。 如果SELinux状态参数是Disabled, 则SELinux为关闭状态。 如果SELinux状态参数是Enforcing,则SELinux为开启状态。本示例中SELinux为开启状态,因此需要关闭SELinux。 运行getenforce命令查看SELinux的当前状态。 关闭SELinux。如果SELinux为关闭状态,请忽略此步骤。 运行以下命令安装Apache服务及扩展包。 运行httpd -v命令可查看Apache的版本号。 依次运行以下命令启动Apache服务并设置服务开机自启动。 查看安装结果。 登录ECS管理控制台。 在左侧导航栏,单击。 在实例列表中找到正在部署环境的实例,从该实例的IP地址中复制公网IP。 在本地机器的浏览器地址栏中,输入 若返回页面如下图所示,说明Apache服务启动成功。 运行以下命令更新YUM源。 运行以下命令安装MySQL。 说明 如果您使用的操作系统内核版本为el8,可能会提示报错信息No match for argument。您需要先运行命令yum module disable mysql禁用默认的MySQL模块,再安装MySQL。 运行以下命令查看MySQL版本号。 返回结果如下所示,表示MySQL安装成功。 运行以下命令启动MySQL。 依次运行以下命令设置开机启动MySQL。 运行以下命令查看MySQL的初始密码。 返回结果示例如下,本示例中初始密码为 运行以下命令配置MySQL的安全性。 安全性的配置包含以下五个方面: 重置root账号的密码。 说明 请您安全保管root账号的密码信息。 输入Y删除匿名用户账号。 输入Y禁止root账号远程登录。 输入Y删除test库以及对test库的访问权限。 输入Y重新加载授权表。背景信息
步骤一:准备工作


setenforce 0。SELINUX=enforcing这一行,按i键,将其修改为SELINUX=disabled, 按Esc键,然后输入:wq并回车以保存并关闭SELinux配置文件。 最后重启系统使设置生效。
步骤二:安装Apache
yum -y install httpd httpd-manual mod_ssl mod_perl

systemctl start httpd
systemctl enable httpd
http://实例公网IP并按Enter键。
步骤三:安装并配置MySQL
rpm -Uvh http://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
yum -y install mysql-community-server --nogpgcheck
mysql -V
mysql Ver 14.14 Distrib 5.7.31, for Linux (x86_64) using EditLine wrapper
systemctl start mysqld
systemctl enable mysqldsystemctl daemon-reload
grep "password" /var/log/mysqld.log
+47,uijcojcU。2020-08-28T03:01:49.848762Z 1 [Note] A temporary password is generated for root@localhost: +47,uijcojcU
mysql_secure_installation
Enter password for user root: #输入上一步获取的root用户初始密码。
The existing password for the user account root has expired. Please set a new password.New password: #输入新密码,长度为8至30个字符,必须同时包含大小写英文字母、数字和特殊符号。特殊符号可以是()` ~!@#$%^&*-+=|{}[]:;‘<>,.?/
Re-enter new password: #重复输入新密码。
The 'validate_password' plugin is installed on the server.
The subsequent steps will run with the existing configurationof the plugin.Using existing password for root.
Estimated strength of the password: 100Change the password for root ? ((Press y|Y for Yes, any other key for No) :Y #按Y,并再次输入上步已设置的密码。New password: #再次输入新密码。
Re-enter new password: #重复输入新密码。
Estimated strength of the password: 100Do 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 fortesting, 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 t
推荐:TOP云智能建站优惠活动,仅880元即可搭建一个后台管理五端合一的智能网站(PC网站、手机网站、百度智能小程序、微信小程序、支付宝小程序),独享百度搜索SEO优势资源,让你的网站不仅有颜值有排面,更有排名,可以实实在在为您带来效益,请点击进入TOP云智能建站>>>,或咨询在线客服了解详情。


湘公网安备43019002001857号
备案号:
客服1