Installing the LEMP Stack on Ubuntu using Ansible

In this post,we’ll learn that how we can install the latest LEMP (Nginx, MySQL & PHP) Stack and it’s initial configuration on Ubuntu 14.04 LTS using Ansible. If you don’t know about Ansible, please check this link.

If you want the manual procedure to install the LEMP stack, please refer this link.

First, download this Repository from the GitHub:

git clone

Note: If git is not installed then you can simply download the zip file.

To use this role, edit the site.yml file:

vi site.yml


Mentioned the LEMP role:

 - hosts: server
   sudo: True
   gather_facts: True
    - LEMP


After that, edit the hosts file and enter the ip of your remote server, on which you want to perform all these tasks:

vi hosts

In my case, it is


After that edit the LEMP/defaults/main.yml file:

– Change the mysql_port & mysql_bind_address if you are using non-standard/modified setting.
– Edit the mysql_root_pass for MySQL root password.
– Give the maximum nginx connections and server_name as well (default is 1024 connections and localhost as server_name). In my case, I have mentioned the as my server_name.

After Editing the file, it will look like this:

 mysql_port: 3306 
 mysql_bind_address: "" 
 mysql_root_pass: mypassword 
 connections: 1024 
 server_name: ""

Then run this command:

ansible-playbook -i hosts -u arbab site.yml

3Note: Please don’t forget to change arbab with your username

After successful completion of these tasks, it will show you the summary, something like this:


Navigate to the site in web browser using the IP address or fqdn, and verify that the LEMP stack is installed successfully: 


Enjoy :-)

Hope this will help you!

Please Remember me in your prayers!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: