Install Apache2 and MySQL on Ubuntu Server in Azure
Tags: azure, apache2, mysql, ubuntu
Published: 2023-02-20 18:22:58

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mugdjtr7o5975062fvg4.png)
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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9cyjt5ykpg2taoc0xg4h.png)

Now copy the Public IP address from overview tab of Virtual Machine /Server and paste it in [PuTTY](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html).  

*[Go to Google and download **PuTTY**. (If not installed in your local system). [Click here to download](https://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html). (64-bit x86 recommended)]*

SSH the VM/Server using the Username and Password. 

- **Step 3:**


![SSH PuTTY](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/afrm7q5wvkchwt3owvqu.png)

 Run the command

```bash
sudo apt install apache2
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aayo9h105zhlopvx5xiz.png)

Copy the IP address and browse it over Internet.

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

```bash
sudo service apache2 start
```

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/](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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/39qgo1ekcsfkgdcgozf6.png)

Now run the command

```bash
 cd /var/www/html/
```

```bash
ls
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3h7o5p6z6frt2uiinkqb.png)
Run the command

```bash
sudo vi test.html
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xn5g56ichvkpptzdvyzn.png)

```bash
<html>
       <h1> This is the fresh Page </h1>
</html>
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/78q8wvhrqemyac95pfig.png)

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

```bash
ls
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/nphowl7nw60i639b7au7.png)

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.

```bash
sudo mv index.html backup.html
```

"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. 

```bash
sudo mv test.html index.html
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/enhv1bhqvssdidolf2ih.png)

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mh76wzfkl94n8xftxf2k.png)

Run the command. 

```bash
sudo apt-get install mysql-server
```

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](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/62dlj7nq36bx1vyeh5o1.png)

Once the installation is completed successfully, check the version

```bash
mysql -V
```

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.

---