|
| 1 | +--- |
| 2 | +title:How to quickly deploy a test web server on an Azure VM |
| 3 | +date:2025-06-16 10:00 |
| 4 | +tags:[Azure, Virtual Machine, Portal, web server, custom script extension] |
| 5 | +--- |
| 6 | + |
| 7 | +For my**Labs**, I often need to create and build virtual machines.**Many virtual machines** :-). One of the most "popular" machine recently is for me the web server. The requirement for my needs is often very simple:**create a web server that responds on port 80, that is able to make me understand "what machine I’m interacting with"**, so, the ideal response message to the request*http://my-machine-ip* should be "*myMachineName*". |
| 8 | + |
| 9 | + |
| 10 | +#Windows machine |
| 11 | + |
| 12 | +From Azure portal is quick enough to create a virtual machines. In particular I use as the starting image "**windows 2019 datacenter gen1**". |
| 13 | + |
| 14 | +Once the machine is created, go tpo Azure Portal > virtual machines >`vmname` > run command > run powershell script |
| 15 | + |
| 16 | +type: |
| 17 | + |
| 18 | +```powershell |
| 19 | +Install-WindowsFeature -name Web-Server -IncludeManagementTools |
| 20 | +Remove-Item -Path 'C:\inetpub\wwwroot\iisstart.htm' |
| 21 | +Add-Content -Path 'C:\inetpub\wwwroot\iisstart.htm' -Value $($env:computername) |
| 22 | +``` |
| 23 | + |
| 24 | +click**Run** |
| 25 | + |
| 26 | +After a couple of minutes the script will be executed, and IIS will be provisioned and working. |
| 27 | + |
| 28 | + |
| 29 | + |
| 30 | +#Linux machine |
| 31 | +From Azure portal is quick enough to create a virtual machines. In particular I use as the starting image "**windows 2019 datacenter gen1**". |
| 32 | + |
| 33 | +Once the machine is created, go tpo Azure Portal > virtual machines >`vmname` > run command > run linux shell script |
| 34 | + |
| 35 | +type: |
| 36 | + |
| 37 | +```shell |
| 38 | +sudo apt-get update |
| 39 | +sudo apt-get install -y nginx |
| 40 | +sudo rm /var/www/html/index.html |
| 41 | +echo$HOSTNAME| sudo tee /var/www/html/index.html |
| 42 | +``` |
| 43 | + |
| 44 | +click**Run** |
| 45 | + |
| 46 | +After a couple of minutes the script will be executed, and IIS will be provisioned and working. |
| 47 | + |
| 48 | + |
| 49 | + |
| 50 | + |
| 51 | + |