[Azure] 創建支持Apache,PHP以及MySQL的CentOS Web Virtual Machine Server


創建Linux虛機

1. 打開 https://manage.windowsazure.com/ 並使用您的賬戶登錄Windows Azure Portal。

2. 在下方菜單中選擇New | Compute | Virtual Machine | From Gallery 開始創建一個新的虛機。

image

3. 在VM OS Selection頁面左側的Platform Images 選擇OpenLogic CentOS 6.2 操作系統並點擊繼續。

4. 在Virtual machine configuration 中輸入虛機名稱(比如:"centosvm1")以及用戶名和密碼,密碼要求復雜格式但確保您能記住,完成后點擊右側向右按鈕。

image

5. 在Virtual machine mode 頁面中選擇Standalone Virtual Machine, 輸入該虛機的DNS Name,並選擇Storage Account 或選擇默認的Use Automatically Generated Storage Account,然后Region/Affinity Group/Virtual Network.點擊向右按鈕繼續。

image

6. 在Virtual machine options選擇默認值並點擊 Finish 按鈕完成虛機的創建。

image

7. 在左側的 Virtual Machines 節點中,你會看到你創建的VM狀態為 Starting (provisioning),等到它變成Running 繼續下面的步驟。

image

Note: 這個操作也許會花費8-10分鍾,請耐心等待.

8. 獲得Putty.exe工具,該工具用戶遠程連接您的虛機

image

image

9. 在Virtual Machines 節點中找到虛機,點擊進入虛機控制面板,查看虛機詳細信息:

image

image

10. 將DNS輸入到Putty工具的Host Name欄,選擇默認SSH,點擊Open:

image

11. 安全確認點擊Yes:

image

12. 輸入您剛才設置的用戶名和密碼進行登陸:

image

13. 登陸成功后執行如下命令,進行高級權限激活,並要求在此輸入登錄密碼,待您看到root@centosvm1即可:

sudo –s

image

14. 開始安裝MySQL5,首先我們應該先用下面的命令安裝MySQL:

yum install mysql mysql-server

image

image

15. 選擇Y進行安裝:

image

image

16. 然后我們需要啟動MySQL服務器,運行如下命令:

/etc/init.d/mysqld start

image

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

image

19. 輸入Y進行確認安裝:

image

20. 執行如下命令啟動Apache:

/etc/init.d/httpd start

image

Note: Apache的默認文檔根目錄是在CentOS上的/var/www/html 目錄 ,配置文件是/etc/httpd/conf/httpd.conf。配置存儲在的/etc/httpd/conf.d/目錄。

21. 回到Windows Azure Portal中,選擇當前虛機的Endpoint:

image

22. 打開后選擇下方菜單中Add Endpoint:

image

23. 選擇Add endpoint,點擊右下方向右按鈕:

image

24. 在Name中輸入Web,Protocol選擇TCP,Public Port輸入80,Private Port輸入80,完成后點擊右下對號按鈕:

image

25. 等待端口添加完成再進行后續步驟:

image

26. 在瀏覽器中輸入http://youdnsname.cloudapp.net,如網頁是否顯示如下則正確:

image

27. 安裝PHP 5,我們可以用下面的命令來安裝PHP5

yum install php

image

28. 輸入Y確認安裝:

image

29. 安裝完成后使用如下命令重啟Apache:

/etc/init.d/httpd restart

image

30. 接下來我們要在/srv/www/html中創建一個Info.php頁面來測試PHP環境是否正常,運行如下命令:

vi /var/www/html/info.php

31. 進入編輯狀態后輸入以下內容:

<?php

Phpinfo();

?>

image

32. 輸入完成偶按Esc退出編輯狀態,按:鍵,輸入wq保存並退出編輯狀態:

image

33. 訪問http://youdnsname.cloudapp.net/info.php,查看頁面是否如下:

image

34. 讓PHP 5獲得MySOL的支持,運行如下命令:

yum search php

image

35. 再運行如下命令安裝必要組件:

yum install php-mysql php-gd php-imap php-ldap php-mbstring php-odbc php-pear php-xml php-xmlrpc

image

36. 輸入Y進行安裝:

image

37. 運行如下命令重新啟動Apache:

/etc/init.d/httpd restart

image

38. 訪問http://youdnsname.cloudapp.net/info.php,並查看MySQL模塊支持:

image

39. 接下來測試MySQL數據庫工作情況,首先使用如下命令創建測試頁面:

vi /var/www/html/mysql.php

40. 進入編輯狀態輸入:

<?php

$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…….";

?>

image

41. 完成后按Esc,輸入:后輸入wq進行保存並退出編輯狀態,訪問http://youdnsname.cloudapp.net/mysql.php,如果看到如下信息證明成功:

image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM