Loading...

Ansible to setup LAMP application on VMs hosted in Azure

Ansible to setup LAMP application on VMs hosted in Azure

Automating IT tasks is crucial to systems administration as we move towards a more digital working realm. The use of software to execute job tasks is called task automation. Task automation enhances workflow accuracy and consistency while also enabling more efficient operations. Above all, task automation automates manual procedures and reduces the effort necessary to achieve a specific outcome.

Here, let us consider configuration management tools such as Ansible.

What is Ansible?

If you are in IT, you have probably often come across Ansible.

Ansible is a comprehensive automation tool or platform used for IT activities, including configuration management, intra service orchestration, application deployment, and provisioning. Automation is critical these days, with complex IT infrastructures that need to expand frequently. This is tedious for system administrators and developers to keep up if everything is done manually. Automation simplifies complicated tasks, making developers’ jobs easier and allowing them to focus their attention on other functions that offer more value to the organization.

These tools enable faster execution when configuring infrastructure and aim to provide visibility to help other teams across the enterprise work quickly and more efficiently.

This article explains how to use Ansible to deploy a LAMP (Linux, Apache, MySQL, and PHP) stack application on the Virtual Machines runs in Azure.

Prerequisites

To execute the Ansible playbook, you’ll need:

  • Ansible control node with Ansible installed and configured to connect to web and database Ansible hosts using SSH keys
  • One Ansible host to deploy web stack
  • One Ansible host to deploy database stack

ansible-lamp-flowdiagram.png

What does this Playbook do?

Ansible Playbooks allow you to direct the Ansible control node to configure your Ansible hosts. Playbooks are expressed in YAML format with a minimum of syntax and are human-readable. Jinja2 templates are used to enable dynamic expressions and access to variables from inventory.

Running this Playbook will perform the following actions on your Ansible hosts:

  • Install the required packages on the respective hosts
  • Install MariaDB on the database host
  • Configure firewall rules for web and database host
  • Configure database, setup user and privilege on the database host
  • Load sample data to database
  • Configure and start httpd on the web host
  • Move the index.php file to the web host
  • Update the index.php file to connect to the database host

Once the Playbook has finished running, you will have a web PHP web page running on top of httpd, based on the options you defined within your inventory file.

How to use this Playbook?

The first thing you need to do is clone this repository to a local folder inside the Ansible Control Node and edit the Playbook’s inventory file to update the configurations. Once you update the inventory file, save and close this file. You are now ready to run this Playbook on one or more servers.

To execute the Playbook, you can use the following command:

ansible-playbook playbook-centos.yml -i inventory (OR) ansible-playbook playbook-redhat.yml -i inventory

When the Playbook is finished running, go to your web browser and access the website with the IP address of the web host, as configured in the inventory file, followed by index.php

http://web_host_or_ip/index.php

You will see a page like this:

ansible-lamp-output.png

Conclusion

In this article, we used Ansible to automate installing and setting up a LAMP stack web application on virtual machines hosted on Azure. Feel free to modify these to suit your individual needs within your workflow.

Published on:

Learn more
Home | Joseph Velliah
Home | Joseph Velliah

Fulfilling God’s purpose for my life

Share post:

Related posts

Azure Developer CLI (azd): Run and test AI agents locally with azd

New azd ai agent run and invoke commands let you start and test AI agents from your terminal—locally or in the cloud. The post Azure Developer...

10 hours ago

Microsoft Purview compliance portal: Endpoint DLP classification support for Azure RMS–protected Office documents

Microsoft Purview Endpoint DLP will soon classify Azure RMS–protected Office documents, enabling consistent DLP policy enforcement on encrypte...

17 hours ago

Introducing the Azure Cosmos DB Plugin for Cursor

We’re excited to announce the Cursor plugin for Azure Cosmos DB bringing AI-powered database expertise, best practices guidance, and liv...

1 day ago

Azure DevOps Remote MCP Server (public preview)

When we released the local Azure DevOps MCP Server, it gave customers a way to connect Azure DevOps data with tools like Visual Studio and Vis...

1 day ago

Azure Cosmos DB at FOSSASIA Summit 2026: Sessions, Conversations, and Community

The FOSSASIA Summit 2026 was an incredible gathering of developers, open-source contributors, startups, and technology enthusiasts from across...

2 days ago

Dataverse: Avoid Concurrency issues by using Azure Service Bus Queue and Azure Functions

Another blog post to handle the concurrency issue. Previously, I shared how to do concurrency via a plugin in this blog post and also how to f...

3 days ago

March Patches for Azure DevOps Server

We are releasing patches for our self‑hosted product, Azure DevOps Server. We strongly recommend that all customers stay on the latest, most s...

5 days ago

Azure Developer CLI (azd): Debug hosted AI agents from your terminal

New azd ai agent show and monitor commands help you diagnose hosted AI agent failures directly from the CLI. The post Azure Developer CLI (azd...

5 days ago

A Look Ahead at Azure Cosmos DB Conf 2026: From AI Agents to Global Scale

Join us for Azure Cosmos DB Conf 2026, a free global, virtual developer event focused on building modern applications with Azure Cosmos DB. Da...

7 days ago
Stay up to date with latest Microsoft Dynamics 365 and Power Platform news!
* Yes, I agree to the privacy policy