Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

what is LEMP Stack ?

L → Linux (Operating System) E → Nginx (Web Server) M → MySQL (Database) P → PHP (Programming Language)

what we will Build

Internet ↓ Nginx (Port 80/443) ↓ PHP-FPM (Process Manager) ↓ MySQL (Database) ↓ Our Web Application

Full Project Structure

lemp_project/
├── ansible.cfg
├── inventory.ini
├── requirements.yml
├── site.yml
├── .vault_pass
├── .gitignore
├── group_vars/
│   ├── all.yml
│   └── webservers.yml
├── host_vars/
│   └── web1.yml
├── vars/
│   └── secrets.yml
└── roles/
    ├── common/
    ├── nginx/
    ├── mysql/
    └── php/

SetUp Project

create projet directory

mkdir lemp_project
cd lemp_project

# create all folders
mkdir -p {group_vars,host_vars,vars,roles}
ansible-galaxy init roles/common
ansible-galaxy init roles/nginx
ansible-galaxy init roles/mysql
ansible-galaxy init roles/php


# Create encrypted secrets file:ansible-playbook site.yml --check
ansible-vault create vars/secrets.yml

Run the project

#Install requirements first:
ansible-galaxy install -r requirements.yml -p ./roles

# Test connection to all
ansible all -m ping

# Check playbook with-out running
ansible-playbook main_play.yml --check

# Run full setup:
ansible-playbook main_play.yml

Run only specific tags

# Only install packages
ansible-playbook site.yml --tags install

# Only configure
ansible-playbook site.yml --tags configure

# Only on web servers
ansible-playbook site.yml --limit webservers

# Run common role only
ansible-playbook site.yml --tags update,packages

Very everything works

# Check Nginx
ansible webservers -m command -a "systemctl status nginx"

# Check PHP-FPM
ansible webservers -m command -a "systemctl status php8.1-fpm"

# Check MySQL
ansible dbservers -m command -a "systemctl status mysql"

# Check website responds
ansible webservers -m uri -a "url=http://192.168.1.10 status_code=200"

FUll P roject Summary

lemp_project/
├── ansible.cfg          → Ansible settings
├── inventory.ini        → Server list
├── site.yml             → Main playbook
├── .vault_pass          → Vault password
├── .gitignore           → Git ignore list
├── group_vars/
│   ├── all.yml          → Variables for all servers
│   └── webservers.yml   → Variables for web servers
├── host_vars/
│   └── web1.yml         → Variables for web1 only
├── vars/
│   └── secrets.yml      → Encrypted passwords
└── roles/
    ├── common/          → Base server setup
    │   └── tasks/main.yml
    ├── nginx/           → Web server setup
    │   ├── tasks/main.yml
    │   ├── handlers/main.yml
    │   └── templates/
    ├── mysql/           → Database setup
    │   └── tasks/main.yml
    └── php/             → PHP setup
        ├── tasks/main.yml
        ├── handlers/main.yml
        └── templates/

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages