如何在 Azure Linux 虚拟机上快速搭建单机版 LAMP 网站

chaobits 2017-09-05 12:23:23
LAMP 通常表示 Linux + Apache + MySQL/MariaDB + Perl/PHP/Python,LAMP 的各个组件不是一成不变的,并不局限于它最初的选择。作为一个解决方案套件,LAMP 非常适合构建动态网站和网站应用程序。另外使用类似 Zabbix 这样的组件做监控也是网站必不可少的。如果想获得更好的阅读体验,这里是传送门

安装 LAMP

本文档的 LAMP 代指 Linux + Apache2 + MySQL + php5 且各示例步骤基于 Azure 环境下的 LINUX 虚拟机。本文档介绍三种方式来安装LAMP:1. 使用 Azure PowerShell 脚本; 2. 使用 Azure CLI; 3. 使用 SHELL 脚本。 安装 LAMP 过程中会在虚拟机上自动安装 Zabbix agent。

说明:
目前 Azure PowerShell 脚本和 Azure CLI 方式仅支持 CentOS(6.5, 6.6, 6.7, 7.0, 7.1, 7.2)。而 SHELL 脚本则有 CentOS, Ubuntu以及 SLES 三个版本。
参数使用注意事项:
DNSNamePrefix:必须小写,需保证唯一性,该参数将作为 DNS 前缀。
ZabbixServerIPAddress:可选项,指定 Zabbix 服务器地址。

Azure PowerShell 方式
PowerShell 脚本运行注意事项:
需要以管理员权限运行 PowerShell,使用之前需运行如下命令:
Set-ExecutionPolicy -ExecutionPolicy Unrestricted

如果您选择 Azure PowerShell 方式安装 LAMP,那么请按如何安装和配置 Azure PowerShell 中的说明在本地计算机上安装 Azure PowerShell。然后打开 Azure PowerShell 命令提示符,通过运行以下命令并遵循提示进行 Azure 帐户的交互式登录体验,来使用工作或学校 ID 登录:
Login-AzureRmAccount -EnvironmentName AzureChinaCloud

然后您需要创建一个 Azure 资源组 (Resource Group),创建 Azure 虚拟机和安装LAMP都在该资源组中进行,运行以下命令创建 Azure 资源组:
New-AzureRmResourceGroup -Name "YOUR-RESOURCE-GROUP-NAME" -Location "China East"

您需要下载 PowerShell 脚本 single-lamp-deploy.ps1,按照以下示例运行 single-lamp-deploy.ps1 脚本,即可在资源组 rg1 中生成一台 CentOS 虚拟机,接着会在该虚机上安装 LAMP。其中 rg1 是在之前步骤中创建的资源组名字。
PS C:\> .\single-lamp-deploy.ps1 -ResourceGroupName rg1 -CentOSVersion 7.0 -AdminUserName azureuser -AdminPassword “YOUR-PASSWORD”  -MySqlPassword “YOUR-MYSQL-PASSWORD” -DNSNamePrefix “YOUR-DNS-PREFIX”

创建过程大概需要 20 分钟,运行成功后会出现如下提示, 这里我们直接去到下面访问网站的步骤去进行验证。
Deploy LAMP Server successfully.
To veriy the lamp server deployment, following below steps:
Open the URL http://<YOUR-DNS-PREFIX>.chinaeast.cloudapp.chinacloudapi.cn/mysql.php to check if php can connect to MySQL, if can do some insert operation, and finally it will return the result on the web page.
If you refresh the webpage, will insert another record into mysql db table.
We strongly recommend you to delete /var/www/html/mysql.php after you access the URL and see the successful result because mysql.php stores your mysql root password.
You can delete the inserted data by executing below commands:
mysql -uroot -p
drop database testdb;


更多的搭建方式,可以通过这里继续阅读
...全文
524 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

750

社区成员

发帖
与我相关
我的任务
社区描述
虚拟化相关技术讨论专区
社区管理员
  • 虚拟化社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧