0% found this document useful (0 votes)
172 views

5CS022 Week 7 Azure Linux Server

Uploaded by

sarakhan20044
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
172 views

5CS022 Week 7 Azure Linux Server

Uploaded by

sarakhan20044
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

University of Wolverhampton

School of Mathematics and Computer Science

5CS022 Distribute and Cloud Systems Programming

Workshop 7 Linux server on Azure


Overview
In this tutorial, you will be setting up a Linux server on Microsoft Azure cloud service.

Part 1 – Creating a Virtual Machine for Linux


● Log into Azure via https://azureforeducation.microsoft.com/ and go the main Azure portal.
● In the Virtual machines page, create a new virtual machine.
● At the next page fill in the fields similar to below:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
● Make sure the Subscription is on "Azure for Students"
● Name the Virtual Machine name "lx"+ your student ID number, eg. "lx1234567"
● Make sure the Region is on (US) East US
● Set the Availability options to "No infrastructure redundancy required"
● Select the "Ubuntu Server 18.04 LTS – Gen 1" image
● Select the VM Size: "Standard_B1s – 1vcpu, 1GiB memory". This is an appropriate size and cost for the Linux
Server as it does not require as much as Windows.
● Create your administrator user account and password. Please note this information down somewhere. If you
forget, you will be locked out of your Virtual Machine and there will be nothing we can do.
● For the Inbound ports rules, select all available ones for now, and those are 80, 443,and 22.

Then click on "Review + create" to validate your Virtual Machine, and it should after a few moments say "Validation
passed"

● Then click on "Create" to create the actual Virtual Machine.


● Go to your Virtual Machines to get to:

● Please make a note of your server's Public IP address.( eg. 40.71.183.26), as you will need this to connect to it.

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 2 – Connect to virtual machine
● Start a command prompt on your Windows PC.
● Connect to your Ubuntu Linux server using SSH, by enter into the command prompt :

ssh jeffrey@40.71.183.26

Obviously use your own server's public IP address, and username, rather than mine.
● You can also use ssh program Putty to connect to your server.
● The first time you connect, you will be asked to accept the authentication key fingerprint:

Enter "yes" to accept the key.

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
● When you have successfully logged in, you should see:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 3 – Setting up Webmin on the Linux Server
● As the Linux server does not a graphical user interface, having a web-based control dashboard to help set up the
services on the server make it much easier to manage.
● We will install Webmin, a popular web-based control dashboard on this server.
● Issue the following command in terminal session to import the Webmin repository key:

wget http://www.webmin.com/jcameron-key.asc

● Next, issue the following command in Terminal to install the key:

sudo apt-key add jcameron-key.asc

● You will also add the Webmin repository into the /etc/apt/sources.list file. In this way, you will be able to install
Webmin. Issue the following 3 commands in Terminal to do this:
o sudo bash
o echo "deb http://download.webmin.com/download/repository sarge contrib" >> /etc/apt/sources.list
o exit

● Next, issue the following command in Terminal to update the repository index with that of the newly added
Webmin repository:

sudo apt update

● Install the Webmin package as sudo via the following command:

sudo apt install webmin

● The system might prompt you for confirmation by providing you with a y/n option. Hit y to continue the
installation process. Once installation is complete, you will see a message explaining how to access Webmin.

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 4 – Configuring network firewall settings to allow access to the Webmin control
panel
● In the web browser, switch back to the Overview panel for the virtual machine. You can find the VM under All
Resources.
● In the Settings section, select the Networking item.
● You should see the NSG rules for the subnet in the top section and the NSG rules for the network interface in the
bottom section of the same tab. In the bottom section, for the NSG rules for the network interface, select Add
inbound port rule.

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
● Then add the following rule:

● You should then end up with these rules for your VM:

● Use your web browser and then go to the URL: https:// 35.86.108.54:10000. Substitute 35.86.108.54 with your
Linux server’s Public IP address. Also please note it’s https, not http.
● The web browser may complain about the website's security certificate:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
● Click on "Continue to this webpage (not recommended)."
● Login to Webmin with your Linux username and password.
● You should see a page similar to the following:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 5 – Installing Apache web server
● The Apache web server is currently the most popular web server in the world, which makes it a great default
choice for hosting a website. Type this in your Windows Command window:

sudo apt install apache2

● Verify if apache was installed as planned by visiting your server's IP address in your web browser, for example
http://35.204.55.123 (it’s http this time, not https)
● You will see the default Apache web page, which is there for informational and testing purposes. It should look
something like this:

● Go back to Webmin. On the left hand side of Webmin, click on Servers. Apache server should figure on the list. If
not click on “Refresh Modules” at the bottom of the list to refresh these modules. Then reload webmin. Click on
Apache Webserver. You will see the following screen:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 6 – Installing MySQL Database Server
● Now that you have a web server up and running, you need to install the database system to be able to store and
manage data for your site. MySQL is a popular database management system used within PHP environments.
● Again, use apt to acquire and install this software:

sudo apt install mysql-server

● When prompted, confirm installation by typing Y, and then ENTER.


● Next, start MySQL:

sudo mysql

Enter quit to exit mysql

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 7 – Installing PHP
● PHP is the component of our setup that will process code to display dynamic content. It can run scripts, connect
to our MySQL databases to get information, and hand the processed content over to our web server to display:

sudo apt install php libapache2-mod-php php-mysql

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 8 - Manipulating files on the Linux Server via Webmin
● In Webmin, click Tools and then File Manager.

● Navigate the File Manager by double-clicking the folders, to the directory "/var/www/html".

● Click on the "File” and Create new file. Name the file testpage.html

● Right click the testpage.html file you have just created, and select Edit

● "Hello yourstudentnumber" or similar text into the editor box

● Save your file, and close it.

● Select the testpage.html file that you have just created, click on “Tools” then “Change permissions”. Change the
permissions to 0755.

● Now verify that your new website is working. Start a web browser and go to:

http://40.71.183.26/testpage.html

Use your own IP address, of course!


Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 9 - Setting up a PHP info page.
1) PHP is one of the most common web application programming languages in use today. We are now going to
create a PHP web page.

2) Using Webmin’s File Manager, create a file in the “/var/www/html” directory, called “info.php”.

3) Insert the following code into the “info.php” file:

4) The change the “info.php” file permissions to 0755.

5) Now with your web browser, go to http://35.204.55.123//info.php . Make sure you use your own server’s IP
address! You show see your version of the following page:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 10 - Setting up the MySQL Database Server

1) On the left hand side of Webmin, under Servers and then click on “MySQL Database Server”.
2) Then in the right hand pane, click “Start MySQL Server” if it’s not running.

3) When the MySQL Database Server has started, you should see the right hand pane of Webmin change to
display “MySQL Databases” containing the “information_schema”, ”mysql” and ”performance_schema”
databases , as well as the “Global Options”.
4) Click on the “mysql” database and Webmin will display the database tables within the “mysql” database.
5) Then click “Return to database list” to return to the previous screen.

Creating a new MySQL database and table

1) On the left hand side of Webmin, under Servers and then click on “MySQL Database Server”.
2) Click “Create a new database”
3) Give your new database the name of your student ID prefixed with the letters “db”. Thus if your student ID is
1234567, creating a new database with the name of “db1234567”. Make sure you use your student ID.
Name the initial table “Contacts” and populate it with the information shown below

4) Click “Create” to create the table.


5) On the next screen, click on your new database and your Contacts table, to display its fields or columns.

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 11 - Entering data into the Contacts table

1) Go on “MySQL Database Server” and install the missing PERL modules as shown below (at the bottom)

2) Click "Return to table list" to go back to the "Edit Database" view.

3) Click on the "Execute SQL" button.

4) Enter the following SQL statement into the box and then click the "Execute" button. Make sure you get the
spaces, commas, and single-quotes correct:

INSERT INTO Contacts VALUES ('Firstname Surname', 'Your address', 'Yourphone number',
'email@wlv.ac.uk');

5) Then click "Return to table list"

6) Double Click on the Contacts table and then "View Data".

7) You should see the data that you have just entered into the "Contacts" table.
8) Repeat the procedure to create 4 more different contacts, using different values, and then capture the
screen show all the contacts data, and paste it below:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Part 12 - Connecting Apache/PHP to MySQL

● Go to the MySQL main screen showing all databases.

● Click on "User Permissions"

● Click on "Create new user"

● Create a new database user called "phpuser" with a password of "Password123!", set the Hosts to
"localhost", and select all the permissions:

● Click "Create".

● Click "Return to database list"

● Click on “Database Permissions”, and then click on “Create new database permissions”

● Select the Database of “db1234567” (make sure you select your own database), and set the rest of the
details as shown below:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
● Click "Create".

● Click "Return to database list"

● Stop and then re-start the MySQL Database server.

● Go back to the Webmin Filemanager, and browse to the /var/www/html/ directory.

● Create a new file called "contacts.php".

● Enter the following code into the PHP file. Make sure you use your own database name:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
Find the code in the drive.

Or use the code from this example: https://www.w3schools.com/php/php_mysql_select.asp

● Make sure you don't get the curly brackets {} mixed up with the round ones ()!
● Save the file and then set its permissions to 0755 and both ownership fields to “phpuser”

● Now with your web browser, go to http://35.204.55.123/contacts.php . Make sure you use your own
server’s IP address! You show see your version of the following page:

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana
This is the end of this workshop.

Note: Significant parts of this document were sourced from Dr Consolee Mbarushimana

You might also like