DEV Community

Cover image for Install Apache2 and MySQL on Ubuntu Server in Azure
Ritesh Agrawal
Ritesh Agrawal

Posted on • Originally published at riteshscloud.com

Install Apache2 and MySQL on Ubuntu Server in Azure

Here you will find the Knowledge base article on how to install apache2 and MySQL on the Ubuntu server of Azure Cloud using CLI in a few steps.


Prerequisites:

  1. Basic knowledge of Linux.
  2. Familiar with Azure portal.

Installing of Apache2.

Follow the below steps and parallelly start working on it.

(All Snips attached for Reference)

  • Step 1:

Ubuntu Virtual Machine in Azure
Firstly you should be having a running Ubuntu Virtual Machine / Server in Azure Cloud.

VM Image : Ubuntu Server18.04 LTS -x64 Gen2

  • Step 2:

SSH PuTTY

Now copy the Public IP address from overview tab of Virtual Machine /Server and paste it in PuTTY.

[Go to Google and download PuTTY. (If not installed in your local system). Click here to download. (64-bit x86 recommended)]

SSH the VM/Server using the Username and Password.

  • Step 3:

SSH PuTTY

Run the command

sudo apt install apache2
Enter fullscreen mode Exit fullscreen mode

This command will download and install the latest version of Apache2 available in the repository.

  • Step 4:

IP addressing routing over the Internet for Apache2

Copy the IP address and browse it over Internet.

After the installation is complete, you can start the Apache service using the command

sudo service apache2 start
Enter fullscreen mode Exit fullscreen mode

By default, Apache will serve web pages from the "/var/www/html" directory on the system.

You can test the installation by opening a web browser and navigating to http://localhost/
or http://your-server-ip-address, where you should see the default Apache web page.

In my case the your-server-ip-address is 20.106.210.31

  • Step 5:

SSH PuTTY Linux

Now run the command

 cd /var/www/html/
Enter fullscreen mode Exit fullscreen mode
ls
Enter fullscreen mode Exit fullscreen mode

The command "cd /var/www/html/" is used to change the current directory to the default document root directory of the Apache HTTP Server

Apache will serve files from this directory by default.

The "ls" command in Linux is used to list the files and directories in the current working directory or a specified directory.

You will find one index.html file present here which holds apache2 files.

  • Step 6:

SSH PuTTY Linux and Vi Editor for HTML
Run the command

sudo vi test.html
Enter fullscreen mode Exit fullscreen mode

The command "sudo vi test.html" is used to create or edit a file named "test.html" using the Vi text editor.

"vi" is a powerful text editor that is available on most Unix-based systems, including Linux. With Vi, you can create, edit, and manipulate text files using a variety of commands and keyboard shortcuts.

After running this command, Vi will open and display the contents of the "test.html" file (if it already exists) or create a new file with that name (if it doesn't exist yet). You can then use Vi's command mode and editing mode to make changes to the file.

SSH PuTTY Linux and Vi Editor for HTML

<html>
       <h1> This is the fresh Page </h1>
</html>
Enter fullscreen mode Exit fullscreen mode

Once you've finished making changes, you can save the file and exit Vi by pressing ‘esc’ button and typing ":wq" and pressing Enter.

  • Step 7:

SSH PuTTY Linux and Vi Editor for HTML

Again check the file you created is present or not using ls command

ls
Enter fullscreen mode Exit fullscreen mode

If you see test.html file. Kudos! If the file you created is not present, then again repeat the above steps to create one.

  • Step 8:

SSH PuTTY Linux and move command for renaming and moving files

Now move the main index.html file to backup.html for making a backup of it and also move the test.html file to main index.html file.

For doing this run the below commands.

sudo mv index.html backup.html
Enter fullscreen mode Exit fullscreen mode

"mv" is the command used to move files and directories in Linux. In this case, we are using it to move the file "index.html" to "backup.html". This command will essentially move the file from its current location to a new file name.

After running this command, the original "index.html" file will no longer exist in the current directory, and a new file named "backup.html" will take its place.

sudo mv test.html index.html
Enter fullscreen mode Exit fullscreen mode

We are using it to move the file "test.html" to "index.html". This command will essentially move the file from its current location to a new file name.

After running this command, the original "test.html" file will no longer exist in the current directory, and a new file named "index.html" will take its place.

  • Step 9:

searching over internet of apache2 installation

Refresh the page

Also add /index.html with IP address.

In my case it is : 20.206.210.31/index.html

The URL "20.206.210.31/index.html" is an example of a web address or URL that points to a specific file named "index.html" located on a web server with the IP address of 20.206.210.31.

Your apache2 is installed successfully on Ubuntu Server in Azure Cloud.


Moving towards installing of MySQL Server.

In continuation on same SSH.

  • Step:

SSH for installing MySQL on Ubuntu Server

Run the command.

sudo apt-get install mysql-server
Enter fullscreen mode Exit fullscreen mode

The command "sudo apt-get install mysql-server" is used to install the MySQL database server.

After running this command, APT will download and install the MySQL server package along with any necessary dependencies.

Press Y yes for giving permission of using additional disk.

SSH for installing MySQL on Ubuntu Server

Once the installation is completed successfully, check the version

mysql -V
Enter fullscreen mode Exit fullscreen mode

This command is used to check the version of the MySQL database server.

If MySQL is not present or installed, it will give the error.

MySQL Server is also installed successfully on your Ubuntu Server.


Top comments (0)