This tutorial discusses installation of LAMP stack in an Azure virtual machine. The following topics are included :
- Launch a virtual machine on Azure, running Ubuntu 18.04
- Connect to Azure virtual machine from Windows / Mac / Linux
- Updating package list on virtual machine
- Install Apache 2.4
- Install MySQL 8.0
- Install PHP 7.4 & common PHP extensions
- Install phpMyAdmin 4.9
- Connect Virtual Machine via FTP
Step 1 - Launching a Virtual Machine
Log in to https://portal.azure.com/
Click on Virtual machines option.
Click on button Create virtual machines.
The next page would present a form where we need to enter details of the VM.
Select Subscription & Resource group (create new one if required).
Enter Virtual machine name
Choose Image as Ubuntu Server 18.04 LTS
Choose Size of the VM (alternately click Select size to see the list of all plans available).
Choose Authentication type as Password
For the sake of this tutorial, we recommend to leave the Username as default (AzureUser). Further steps in the tutorial will need this username.
Enter Password and confirm it. Further steps in the tutorial will need this password.
For Select inbound ports, add the HTTP rule also.
Selected options would look something like the below :
Click on Review + create button at the bottom of the page (we are going with default for rest of the other options).
In the next page after Azure validates the entered information, click on the Create button to start creating the VM.
In a couple of minutes, the VM should be created.
In the VM settings, its Public IP address can be seen. Further steps in the tutorial will need this public IP address.
Now that the virtual machine is created, we need to connect to it from our system.
Step 2.1 - Connecting to Azure Virtual Machine - From Windows
We can use PuTTY application to connect to the VM. PuTTY is included in Windows by default.
We will need the public IP address of the VM, Username & Password to connect via PuTTY.
Open PuTTY (Start > All Programs > PuTTY > PuTTY)
In the Category panel on the left, choose Session.
For the Host Name field, enter the public IP address of the VM.
Port is 22
For Connection type choose SSH
Click on the Open button, and login with the username & password.
Step 2.2 - Connecting to Azure Virtual Machine - From Linux / Mac
A secure remote connection with our virtual machine is established using SSH.
We will need the public IP address of the VM, Username & Password to connect via SSH.
The connection is initiated using the following command :
sudo ssh AzureUser@vm-ip-address
Default username is AzureUser.
Replace vm-ip-address with the public IP address of the virtual machine.
- If a warning is prompted, type yes.
Enter the VM password
When the connection has been successfully established, the terminal of the virtual machine will be shown.
Step 3 - Update Package List
The package list needs to be updated by running the following command. This will ensure the latest version of applications are fetched while installing.
sudo apt-get update
Step 4 - Install Apache
Apache is installed by executing the following command.
sudo apt-get install apache2
A successful installation of Apache can be tested by visiting the public IP Address of the virtual machine
The Apache welcome page will be shown if the installation is successful.
Step 5 - Install MySQL
MySQL is installed by executing the following command :
sudo apt-get install mysql-server
The database is then secured by executing the following command :
We would then be asked whether we need to setup VALIDATE PASSWORD plugin ? We selected no.
Set the password for the root MySQL account.
Remove anonymous users? We selected yes.
Disallow root login remotely? We selected no.
Remove test database and access to it? We chose yes.
Reload privilege tables now? We again chose yes.
A successful MySQL installation can be checked by executing the following command:
sudo mysql -u root -p
To login into MySQL, enter the password and we will be greeted by the mysql prompt.
Type exit to get out of MySQL, back to installing the next application.
Step 6 - Install PHP with Common Extensions
PHP is installed along with some of the commonly used extensions by executing the following command :
sudo apt-get install php libapache2-mod-php php-mysql php-curl php-gd php-json php-zip
The Apache service needs to be restarted after installing PHP using the following command:
sudo service apache2 restart
Step 7 - Install phpMyAdmin
phpMyAdmin is installed using the following command:
sudo apt-get install phpmyadmin
In the next screen, apache2 is selected as the webserver.
IMPORTANT : Note that, space-bar needs to be pressed to select the option and tab key is used to move to the Ok button.
Correctly selected Apache will look like :
In the next screen for dbconfig-common option, choose Yes.
The password for phpmyadmin is set and confirmed in the next prompt and after.
(This password is set for the phpmyadmin MySQL user. This is different from the root user that came up while installing MySQL)
Successful installation of phpMyAdmin can be checked by visiting the /phpmyadmin URL path in the public IP address of the virtual machine.
Enter phpmyadmin as username, and the earlier created password to log in to phpMyAdmin.
Step 8 - Connect Virtual Machine via FTP
In this step we are going to set up FileZilla to connect to our Azure virtual machine.
Open Filezilla. Under File > Site Manager setup the credentials needed to upload files.
Protocol is SFTP.
Host is public IP Address of virtual machine.
Logon Type is Normal.
User is the virtual machine username (by default it is AzureUser unless it was changed while creating the VM).
Password is the same as the one that was set while creating the VM.
If FileZilla prompts about the server's unknown host key, click Yes.
FileZilla will then connect to Azure virtual machine.
We will be taken to default directory - /home/ubuntu. We can enter /var/www/html to go to the web server directory.
To be able to upload files using FileZilla we need to change the ownership and access modes of the server directory.
This is done by SSHing into Azure virtual machine and typing the following commands.
sudo chown -R AzureUser /var/www/html sudo chmod -R 755 /var/www/html
The installation can be tested by creating a file using FileZilla and entering the following simple code:
<?php echo phpinfo(); ?>
Navigate to the created file from the browser to get output like the one shown below.
This implies that the setup is working perfectly.
Setup is Finished
Congratulations! We have a working Azure Virtual Machine instance with LAMP stack. In case of any issues, delete the VM and create a new one.