Showing posts with label Apache. Show all posts
Showing posts with label Apache. Show all posts

Wednesday, February 21, 2024

Ansible Role for LAMP Installation on Ubuntu | Install LAMP stack using Ansible Role on Ubuntu 22.0.4

 LAMP Stack comprises the following open-source software applications.

    • Linux – This is the operating system hosting the Applications.
    • Apache – Apache HTTP is a free and open-source cross-platform web server.
    • MySQL– Open Source relational database management system.
    • PHP – Programming/Scripting Language used for developing Web applications.


    Pre-requisites:
    Steps to setup SSH keys:
    1. Login to Ansible management server/machine. Create SSH keys in Ansible host machine by executing the below command: (if you already have keys created, please skip this step)
    ssh-keygen 

    enter three times..now you will see keys successfully created.
    2.  Execute the below command on Ansible management node and copy the public key content:
    sudo cat ~/.ssh/id_rsa.pub

    copy the above output.
    3. Now login into target node where you want to install LAMP stack, execute the below command to open the file
    sudo vi /home/ubuntu/.ssh/authorized_keys
    type shift A and then enter now 
        and paste the key in the above file. please do not delete any existing values in this file.

    4. Now go back to Ansible mgmt node, do changes in /etc/ansible/hosts file to include the node you will be installing software. Make sure you add public or private IP address of target node as highlighted below in red color:
    sudo vi /etc/ansible/hosts
    [My_Group]  
    xx.xx.xx.xx ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa  ansible_python_interpreter=/usr/bin/python3

    Ansible playbook for installing LAMP(Linux Apache MySQL PHP) stack on Ubuntu

    sudo vi aws-infra-role/tasks/installLAMP.yml
    ---
        - name: Task # 1 - Update APT package manager repositories cache
          become: true
          apt:
            update_cache: yes
        - name: Task # 2 - Install LAMP stack using Ansible
          become: yes
          apt:
            name: "{{ packages }}"
            state: present
          vars:
            packages:
               - apache2
               - mysql-server
               - php


    Create Ansible main playbook

    sudo vi aws-infra-role/setup-lamp.yml
    ---
    # This Playbook installs LAMP stack

    - hosts: My_Group
      gather_facts: False
      tags: LAMP creation

      tasks:
      - include: tasks/installLAMP.yml

    Execute Ansible Role

    ansible-playbook aws-infra-role/setup-lamp.yml


    This is the execution result of the playbook.

    Now go to browser and use target node DNS to confirm if Apache is installed. make sure port 80 is opened in security firewall rules.


    Now login to target EC2 instance, type below commands to verify PHP and MySql versions:

    php --version

    mysql --version

    Tuesday, December 27, 2022

    Ansible playbook for LAMP Installation on Ubuntu | How to Install LAMP stack using Ansible on Ubuntu 22.0.4

    LAMP Stack comprises the following open-source software applications.

      • Linux – This is the operating system hosting the Applications.
      • Apache – Apache HTTP is a free and open-source cross-platform web server.
      • MySQL– Open Source relational database management system.
      • PHP – Programming/Scripting Language used for developing Web applications.
      Watch the steps in YouTube Channel:

      Pre-requisites:
      Steps to setup SSH keys:
      1. Login to Ansible management server/machine. Create SSH keys in Ansible host machine by executing the below command: (if you already have keys created, please skip this step)
      ssh-keygen 

      enter three times..now you will see keys successfully created.
      2.  Execute the below command on Ansible management node and copy the public key content:
      sudo cat ~/.ssh/id_rsa.pub

      copy the above output.
      3. Now login into target node where you want to install LAMP stack, execute the below command to open the file
      sudo vi /home/ubuntu/.ssh/authorized_keys
      type shift A and then enter now 
          and paste the key in the above file. please do not delete any existing values in this file.

      4. Now go back to Ansible mgmt node, do changes in /etc/ansible/hosts file to include the node you will be installing software. Make sure you add public or private IP address of target node as highlighted below in red color:
      sudo vi /etc/ansible/hosts
      [LAMP_Group]  
      xx.xx.xx.xx ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa  ansible_python_interpreter=/usr/bin/python3

      Ansible playbook for installing LAMP(Linux Apache MySQL PHP) stack on Ubuntu

      sudo vi installLAMP.yml
      ---
      - hosts: LAMP_Group
        tasks:
          - name: Task # 1 - Update APT package manager repositories cache
            become: true
            apt:
              update_cache: yes
          - name: Task # 2 - Install LAMP stack using Ansible
            become: yes
            apt:
              name: "{{ packages }}"
              state: present
            vars:
              packages:
                 - apache2
                 - mysql-server
                 - php

      ansible-playbook installLAMP.yml


      This is the execution result of the playbook.

      Now go to browser and use target node DNS to confirm if Apache is installed. make sure port 80 is opened in security firewall rules.


      Now login to target EC2 instance, type below commands to verify PHP and MySql versions:

      php --version

      mysql --version

      Friday, August 6, 2021

      Ansible playbook to install Apache on Ubuntu | How to install Apache Using Ansible on Ubuntu 22.0.4

      Find the playbook for installing Apache on Ubuntu using Ansible:

      Click here if you would like learn how to create a new Ubuntu EC2 instance using Ansible Playbook.

      Pre-requisites:

      Setup Ansible on EC2 instance with Boto.

      Install Apache using Ansible Playbook

      1. Login to Ansible machine. Create SSH keys in Ansible host machine by executing the below command:

      ssh-keygen
      2. Copy the public keys(id_rsa.pub) from ansible node each node in /home/ubuntu/.ssh/authorized_keys file. Execute the below command on Ansible and copy the content:
       sudo cat ~/.ssh/id_rsa.pub

      3. Now login to target node, execute the below command to open the file
      sudo vi /home/ubuntu/.ssh/authorized_keys
      type shift A and then enter. now 
          and paste the key in the above file. please do not delete any existing keys.

      4. go back to ansible mgmt node, make sure you are able to ssh from ansible mgmt node after copying the keys above:
      ssh private_ip_of_target_node
      now type exit to come out of the target node.

      5. Now in ansible mgmt node, now make changes in /etc/ansible/hosts file to include the node you will be installing software. Make sure you add public IP address as highlighted below in green color:
      sudo vi /etc/ansible/hosts
      [Apache_Group]  
      XX.XX.XX.XX ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa  ansible_python_interpreter=/usr/bin/python3

      6. make changes in playbooks as given below,
      cd ~/playbooks

      sudo vi installApache.xml
      Copy the below content

      ---
      - hosts: Apache_Group
        become: true
        tasks:
          - name: Install apcahe
            apt: name=apache2 state=present update_cache=yes

          - name: ensure apache started
            service: name=apache2 state=started enabled=yes


      7. now execute the playbook by running the below command:
      sudo ansible-playbook installApache.xml
      8. This should install Apache on the nodes and should bring the apache up and running.
      9. Now enter public ip address or public dns name of target server by in the browser to see home page of Apache running.


      Please watch this step on YouTube channel:

      Thursday, January 3, 2019

      Ansible playbook install Apache Ubuntu - How To Configure Apache Using Ansible on Ubuntu 16.0.4

      Please find steps for installing Apache on Ubuntu using Ansible Playbook:

      1. Login to Ansible machine. Create SSH keys in Ansible host machine by executing the below command:
      ssh-keygen
      2. Copy the public keys(id_rsa.pub) from ansible node each node in /home/ubuntu/.ssh/authorized_keys file. Execute the below command on Ansible and copy the content:
       sudo cat ~/.ssh/id_rsa.pub

      3. Now login to target node, execute the below command to open the file
      sudo vi /home/ubuntu/.ssh/authorized_keys
      type shift A and then enter. now 
          and paste the key in the above file. please do not delete any existing keys.

      4. go back to ansible mgmt node, make sure you are able to ssh from ansible mgmt node after copying the keys above:
      ssh private_ip_of_target_node
      now type exit to come out of the target node.
      5. Now in ansible mgmt node, now make changes in /etc/ansible/hosts file to include the node you will be installing software. Make sure you add public IP address as highlighted below in green color:
         sudo vi /etc/ansible/hosts
      [Apache_Group]  
      34.216.41.94 ansible_ssh_user=ubuntu ansible_ssh_private_key_file=~/.ssh/id_rsa  ansible_python_interpreter=/usr/bin/python3

      6. make changes in playbooks as given below,
      cd ~/playbooks

      sudo vi installApache.xml
      Copy the below content

      ---
      - hosts: Apache_Group
        become: true
        tasks:
          - name: Install apcahe
            apt: name=apache2 state=present update_cache=yes

          - name: ensure apache started
            service: name=apache2 state=started enabled=yes


      7. now execute the playbook by running the below command:
      sudo ansible-playbook installApache.xml
      8. This should install Apache on the nodes and should bring the apache up and running.
      9. Now enter public ip address or public dns name of target server by in thr browser to see home page of Apache running.

      🚀 Live AI-Enabled DevSecOps & Cloud Engineering Bootcamp – Sep 2026

      Live AI-Enabled DevSecOps & Cloud Engineering Bootcamp from Coach AK - Sep 2026 Schedule