[Azure] 创建支持Apache,PHP以及MySQL的CentOS Web Virtual Mac
创建 Linux虚机 1. 打开 https://manage.windowsazure.com/ 并使用您的账户登录Windows Azure Portal。 2. 在下方菜单中选择 New | Compute | Virtual Machine | From Gallery 开始 创建 一个新的虚机。 3. 在 VM OS Selection 页面左侧的 Platform Images
创建Linux虚机
1. 打开 https://manage.windowsazure.com/ 并使用您的账户登录Windows Azure Portal。
2. 在下方菜单中选择New | Compute | Virtual Machine | From Gallery 开始创建一个新的虚机。
3. 在VM OS Selection页面左侧的Platform Images 选择OpenLogic CentOS 6.2 操作系统并点击继续。
4. 在Virtual machine configuration 中输入虚机名称(比如:"centosvm1")以及用户名和密码,密码要求复杂格式但确保您能记住,完成后点击右侧向右按钮。
5. 在Virtual machine mode 页面中选择Standalone Virtual Machine, 输入该虚机的DNS Name,并选择Storage Account 或选择默认的Use Automatically Generated Storage Account,然后Region/Affinity Group/Virtual Network.点击向右按钮继续。
6. 在Virtual machine options选择默认值并点击 Finish 按钮完成虚机的创建。
7. 在左侧的 Virtual Machines 节点中,你会看到你创建的VM状态为 Starting (provisioning),等到它变成Running 继续下面的步骤。
Note: 这个操作也许会花费8-10分钟,请耐心等待.
8. 获得Putty.exe工具,该工具用户远程连接您的虚机
9. 在Virtual Machines 节点中找到虚机,点击进入虚机控制面板,查看虚机详细信息:
10. 将DNS输入到Putty工具的Host Name栏,选择默认SSH,点击Open:
11. 安全确认点击Yes:
12. 输入您刚才设置的用户名和密码进行登陆:
13. 登陆成功后执行如下命令,进行高级权限激活,并要求在此输入登录密码,待您看到root@centosvm1即可:
sudo –s
14. 开始安装MySQL5,首先我们应该先用下面的命令安装MySQL:
yum install mysql mysql-server
15. 选择Y进行安装:
16. 然后我们需要启动MySQL服务器,运行如下命令:
/etc/init.d/mysqld start
17. 为MySQL root帐户设置密码,运行如下命令:
mysql_secure_installation
会出现下面的一系列提示:
[root@centosvm1 yourusername] # mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, well need the current
password for the root user. If youve just installed MySQL, and
you havent set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):这里输入旧密码,由于旧密码为空直接回车即可
OK, successfully used password, moving on...
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] 回车表示Y
New password: 输入您的新密码
Re-enter new password: 在此输入您的新密码
Password updated successfully!
Reloading privilege tables..
... Success!
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? [Y/n] 回车表示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? [Y/n] 回车表示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? [Y/n] 回车表示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? [Y/n] 回车表示Y
... Success!
Cleaning up...
All done! If youve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!
[root@centosvm1 yourusername] #
至此MySQL用户设置完成。
18. 安装Apache2,执行如下命令:
yum install httpd
19. 输入Y进行确认安装:
20. 执行如下命令启动Apache:
/etc/init.d/httpd start
Note: Apache的默认文档根目录是在CentOS上的/var/www/html 目录 ,配置文件是/etc/httpd/conf/httpd.conf。配置存储在的/etc/httpd/conf.d/目录。
21. 回到Windows Azure Portal中,选择当前虚机的Endpoint:
22. 打开后选择下方菜单中Add Endpoint:
23. 选择Add endpoint,点击右下方向右按钮:
24. 在Name中输入Web,Protocol选择TCP,Public Port输入80,Private Port输入80,完成后点击右下对号按钮:
25. 等待端口添加完成再进行后续步骤:
26. 在浏览器中输入http://youdnsname.cloudapp.net,如网页是否显示如下则正确:
27. 安装PHP 5,我们可以用下面的命令来安装PHP5
yum install php
28. 输入Y确认安装:
29. 安装完成后使用如下命令重启Apache:
/etc/init.d/httpd restart
30. 接下来我们要在/srv/www/html中创建一个Info.php页面来测试PHP环境是否正常,运行如下命令:
vi /var/www/html/info.php
31. 进入编辑状态后输入以下内容:
Phpinfo();
?>
32. 输入完成偶按Esc退出编辑状态,按:键,输入wq保存并退出编辑状态:
33. 访问http://youdnsname.cloudapp.net/info.php,查看页面是否如下:
34. 让PHP 5获得MySOL的支持,运行如下命令:
yum search php
35. 再运行如下命令安装必要组件:
yum install php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc
36. 输入Y进行安装:
37. 运行如下命令重新启动Apache:
/etc/init.d/httpd restart
38. 访问http://youdnsname.cloudapp.net/info.php,并查看MySQL模块支持:
39. 接下来测试MySQL数据库工作情况,首先使用如下命令创建测试页面:
vi /var/www/html/mysql.php
40. 进入编辑状态输入:
$mysql_server_name='localhost';
$mysql_username='root';
$mysql_password='您之前设置的MySQL密码';
$mysql_database='mycounter';
$conn=mysql_connect($mysql_server_name,$mysql_username,$mysql_password,$mysql_database);
$sql='CREATE DATABASE mycounter DEFAULT CHARACTER SET gbk COLLATE gbk_chinese_ci;
';
mysql_query($sql);
$sql='CREATE TABLE `counter` (`id` INT(255) UNSIGNED NOT NULL AUTO_INCREMENT ,`count` INT(255) UNSIGNED NOT NULL DEFAULT 0,PRIMARY KEY ( `id` ) ) TYPE = innodb;';
mysql_select_db($mysql_database,$conn);
$result=mysql_query($sql);
//echo $sql;
mysql_close($conn);
echo "Hello!...mycounter…….";
?>
41. 完成后按Esc,输入:后输入wq进行保存并退出编辑状态,访问http://youdnsname.cloudapp.net/mysql.php,如果看到如下信息证明成功: