Skip to content

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.
  • Labs icon Lab
  • A Cloud Guru
Google Cloud Platform icon
Labs

Configure a Back End for a Web Application

In this lab, we set up a back end for the existing front end of a web application. We do this by creating a proper folder that will hold the code of our back end. Then we proceed to create a systemd file which will be used to start, stop, and get the status of this process at any given time. In addition to this, we will daemonize the process in this manner. In general, we might ask ourselves what does this have to do with Apache web server? If we have a front-end web application served to us via the Apache web server, there likely exists a back end that will fetch the content to be presented by the front end. In addition to this, Apache web server doesn't necessarily need to be configured to serve websites. It can also serve as a reverse proxy for various API's and serve pretty much any content imaginable. Therefore, it stands to reason we should know how to configure Apache web server to interact not only with the user, website, or front end, but the back end as well.

Google Cloud Platform icon
Labs

Path Info

Level
Clock icon Intermediate
Duration
Clock icon 1h 0m
Published
Clock icon Oct 18, 2019

Contact sales

By filling out this form and clicking submit, you acknowledge our privacy policy.

Table of Contents

  1. Challenge

    Create a New Directory for the Back End and Move `app.py` to the Newly-Created Directory

    mkdir /home/cloud_user/Backend
    
    sudo mv /home/cloud_user/HardeningApache-master/app.py /home/cloud_user/Backend/
    
    sudo chown cloud_user:cloud_user /home/cloud_user/Backend/app.py
    
  2. Challenge

    Install Dependencies: python36.x86_64, python36-devel.x86_64, "Development Tools", python36-pip, Flask, flask-cors, psutil, and tcpdump, then Open Port 65535 with `firewalld`

    sudo yum install epel-release
    
    sudo yum update
    
    sudo yum install python36
    
    sudo yum install python36-devel
    
    sudo yum groupinstall "Development Tools"
    
    sudo yum install python36-pip
    
    ln -s /usr/local/bin/pip3 /usr/bin/pip3
    
    sudo pip3 install Flask
    
    sudo pip3 install flask-cors
    
    sudo pip3 install psutil
    
    sudo yum install tcpdump
    
    sudo firewall-cmd --permanent --add-port=65535/tcp
    
    sudo firewall-cmd --reload
    
  3. Challenge

    Create a systemd File for Our Back End Called "flaskapp.service" in `/etc/systemd/system/`

    sudo vim /etc/systemd/system/flaskapp.service
    
    [Unit]
    Description=API_Backend
    After=network.target
    
    [Service]
    User=root
    Group=root
    WorkingDirectory=/home/cloud_user/Backend
    Environment=FLASK_ENV=development
    Environment=FLASK_APP=/home/cloud_user/Backend/app.py
    ExecStart=/usr/local/bin/flask run -h 0.0.0.0 -p 65535
    Restart=always
                
    [Install]
    WantedBy=multi-user.target
    

    Save and Close

    sudo systemctl daemon-reload
    
    sudo systemctl start flaskapp
    
    sudo systemctl enable flaskapp
    
  4. Challenge

    Configure the Front End to Be Able to Access the Back End and Test If the Back End Works

    vim /var/www/html/index.html
    

    Insert the Server Public IP address here

    var base_url = 'http://<Server_Public_IP>:65535';
    

    Save and close

    ESC
    :wq
    ENTER
    

    Test if it works

    curl http://<Server_Public_IP>:65535/log_messages
    

The Cloud Content team comprises subject matter experts hyper focused on services offered by the leading cloud vendors (AWS, GCP, and Azure), as well as cloud-related technologies such as Linux and DevOps. The team is thrilled to share their knowledge to help you build modern tech solutions from the ground up, secure and optimize your environments, and so much more!

What's a lab?

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Provided environment for hands-on practice

We will provide the credentials and environment necessary for you to practice right within your browser.

Guided walkthrough

Follow along with the author’s guided walkthrough and build something new in your provided environment!

Did you know?

On average, you retain 75% more of your learning if you get time for practice.

Start learning by doing today

View Plans