Coder Social home page Coder Social logo

app-notifier's Introduction

PHP app with RDS and SNS

Sample PHP WebApp to store contact info.

The app uses AWS RDS to store all contact info and it uses AWS SNS to send SMS notifications.


Target architecture

Notifier


Step-by-step


Create Network

  1. Login into AWS Console.

  2. On Services type VPC and select the service.

  3. Select Create VPC and complete with below parameters.

    • Resources to create : VPC and more
    • Auto-generate : db
    • IPv4 CIDR block : 30.0.0.0/16
    • Number of Availability Zones (AZs) : 2
    • Customize AZs
      • First availability zone : us-east-1a
      • Second availability zone : us-east-1b
    • Number of public subnets : 2
    • Number of private subnets : 2
    • Customize subnets CIDR blocks
      • Public subnet CIDR block in us-east-1a : 30.0.1.0/24
      • Public subnet CIDR block in us-east-1b : 30.0.3.0/24
      • Private subnet CIDR block in us-east-1a : 30.0.2.0/24
      • Private subnet CIDR block in us-east-1b : 30.0.4.0/24
    • NAT gateways : None
    • VPC endpoints : None

    Note Remain standard values for all other options.

  4. Click Create VPC.

  5. Validate if all VPC resources were created.

    Note Check carefully this step prior to proceed. This step is a requirement for all following steps. In case of questions/issues, don´t proceed, stop and ask for help.


    Warning Discard message Failed to load rule groups, in case it appears.


Create Firewall


Public Firewall

  1. On Services type VPC and select the service.

  2. In the left side menu click Security Groups.

  3. Click Create security group and complete with below parameters.

    • Security group name : db-sg-pub
    • Description : DB Security Group public
    • VPC : db-vpc
    • Inbound rules (Click Add rule for each rule below)
      • Rule 1
        • Type : All traffic
        • Source : 30.0.0.0/16
      • Rule 2
        • Type : HTTP
        • Source : 0.0.0.0/0
      • Rule 3
        • Type : SSH
        • Source : 0.0.0.0/0

    Note Remain standard values for all other options.

  4. Click Create security group.


Private Firewall

  1. On Services type VPC and select the service.

  2. In the left side menu click Security Groups.

  3. Click Create security group and complete with below parameters.

    • Security group name : db-sg-priv
    • Description : DB Security Group private
    • VPC : db-vpc
    • Inbound rules (Click Add rule)
      • Rule 1
        • Type : All traffic
        • Source : 30.0.0.0/16

    Note Remain standard values for all other options.

  4. Click Create security group.


Create Database

  1. On Services type RDS and select the service.

Create Subnet Group

  1. In the left panel menu click Subnet groups.

  2. Click Create DB subnet group and complete with below parameters.

    • Name : db-sn-group
    • Description: DB Subnet Group
    • VPC : db-vpc
    • Availability Zones : us-east-1a and us-east-1b
    • Subnets: 30.0.2.0/24 and 30.0.4.0/24

    Note Remain standard values for all other options.

  3. Click Create.


Create and Config Parameter Group

  1. In the left panel menu click Parameter groups.

  2. Click Create parameter group and complete with below parameters.

    • Parameter group family : mysql8.0
    • Group name : db-param-group
    • Description: DB Parameter Group

    Note Remain standard values for all other options.

  3. Click Create.

  4. Check the line with the new Parameter Group db-param-group and click Parameter group actions, Edit.

  5. In the Parameters search field type character_set_server.

  6. Check the line with parameter character_set_server and select utf8 in the Values combo box.

  7. Click Save changes.

  8. In the Parameters search field type character_set_database.

  9. Check the line with parameter character_set_database and select utf8 in the Values combo box.

  10. Click Save changes.


Create database

  1. In the left panel menu click Databases.

  2. Click Create database and complete with below parameters.

    • Engine options
      • Engine type: MySQL
    • Availability and durability
      • Deployment options: Multi-AZ DB instance
    • Settings
      • DB instance identifier : db-instance-id
      • Master username : dbadmin
      • Master password : dbpassword
      • Confirm master password : dbpassword
    • Instance configuration
      • DB instance class : Burstable classes (includes t classes)
    • Storage
      • Storage type : gp2
      • Enable storage autoscaling: disabled
    • Connectivity
      • Virtual private cloud (VPC) : db-vpc
      • Existing VPC security groups : db-sg-priv

        Note Remove the default security group if selected.

    • Monitoring
      • Enable Enhanced monitoring : disabled
    • Additional configuration
      • Initial database name : dbname
      • DB parameter group : db-param-group
      • Enable automated backups : disabled
      • Enable encryption : disabled
      • Enable auto minor version upgrade : disabled
      • Enable deletion protection : disabled

    Note Remain standard values for all other options.

  3. Click Create database.

  4. Close screen Suggested add-ons for database-1 in case it appears.

  5. Validate database creation.

    Note Process should take 10-15 minutes. Wait until status is Available.

  6. Click on db-instance-id and capture the Endpoint value. It will be used on later steps.


Create Load Balancer with Autoscaling


Create EC2 Launch template

  1. Login into AWS Console.

  2. On Services type EC2 and select the service.

  3. In the left panel menu, under Instances, click Launch Templates.

  4. Select Create launch template and complete with below parameters.

    • Launch template name : ec2-launch-template
    • Application and OS Images (Amazon Machine Image)
      • Quick start: Amazon Linux
      • Amazon Machine Image (AMI) : Amazon Linux 2 AMI (HVM)
    • Instance type : t2.micro
    • Key pair : vockey (or any from your choice)
    • Network Settings
      • Security groups : db-sg-pub
      • Add network interface
        • Auto-assign public IP : Enable
    • Advanced details
      • User data

      Note Replace [RDS_ENDPOINT] with the database endpoint captured in previous steps.

      #!/bin/bash
      
      echo "Update/Install required OS packages"
      yum update -y
      amazon-linux-extras install -y php7.2 epel
      yum install -y httpd mysql php-mtdowling-jmespath-php php-xml telnet tree git
      
      echo "Config PHP app Connection to Database"
      cat <<EOT >> /var/www/config.php
      <?php
      define('DB_SERVER', '[RDS_ENDPOINT]');
      define('DB_USERNAME', 'dbadmin');
      define('DB_PASSWORD', 'dbpassword');
      define('DB_DATABASE', 'dbname');
      ?>
      EOT
      
      echo "Deploy PHP app"
      cd /tmp
      git clone https://github.com/kledsonhugo/notifier
      cp /tmp/notifier/app/*.php /var/www/html/
      rm -rf /tmp/notifier
      
      echo "Config Apache WebServer"
      usermod -a -G apache ec2-user
      chown -R ec2-user:apache /var/www
      chmod 2775 /var/www
      find /var/www -type d -exec chmod 2775 {} \;
      find /var/www -type f -exec chmod 0664 {} \;
      
      echo "Start Apache WebServer"
      systemctl enable httpd
      service httpd restart
      

    Note Remain standard values for all other options.

  5. Click Create launch template.


Create EC2 Auto Scaling Group

  1. In the left panel menu, under Auto Scaling, click Auto Scaling Groups.

  2. Select Create Auto Scaling group and complete with below parameters.

    • Auto Scaling group name : ec2-auto-scaling-group
    • Launch template : ec2-launch-template

    Note Remain standard values for all other options.

  3. Click Next.

  4. Complete with below parameters.

    • VPC : db-vpc
    • Availability Zones and subnets : 30.0.1.0/24 and 30.0.3.0/24

    Note Remain standard values for all other options.

  5. Click Next.

  6. Complete with below parameters.

    • Load balancing
      • Attach to a new load balancer
    • Attach to a new load balancer
      • Load balancer name: ec2-load-balancer
      • Load balancer scheme : Internet-facing
      • Listeners and routing
        • Default routing (forward to) : Create a target group
        • New target group name : ec2-target-group

    Note Remain standard values for all other options.

  7. Click Next.

  8. Complete with below parameters.

    • Group size - optional
      • Desired capacity : 4
      • Minimum capacity : 2
      • Maximum capacity : 8

    Note Remain standard values for all other options.

  9. Click Next.

  10. Click Next again.

  11. Click Next last time.

  12. Click Create Auto Scaling group.


Config Load Balancer Security Group

  1. In the left panel menu, under Load Balancing, click Load Balancers.

  2. Click on ec2-load-balancer to open the Load Balancer page details.

  3. Click in the Security menu.

  4. Click Edit.

  5. Remove the default Security Group and add db-sg-pub.

  6. Click Save Changes.


Validate Target Group

  1. In the left panel menu, under Load Balancing, click Target Groups.

  2. Click on ec2-target-group and validate if 4 instances are Healthy.

    Note The instance registration process takes 5-10 minutes.


Validate Load Balancer

  1. In the left panel menu, under Load Balancing, click Load Balancers.

  2. Click on ec2-load-balancer and capture the value for field DNS name.

  3. Open a browser tab and navigate to the load balancer DNS name.


Congratulations

If you reach this step successfully, you completed the procedure.

Don´t forget to destroy all resources avoiding unnecessary costs.

app-notifier's People

Contributors

kledsonhugo avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.