4. Hosting - adle29/cs373-idb GitHub Wiki

Hosting

Digital Ocean

Our website is hosted on Digital Ocean. Digital Ocean is a cloud infrastructure provider which provisions virtual servers, or droplets, for software developers. In this section of the wiki, I will demonstrate how to:

  1. run this website on a digital ocean droplet, and
  2. run this website on one's local machine.

Creating a Digital Ocean Droplet

  1. Digital Ocean is a paid service but if you are a student, as in you have a valid .edu email, you can obtain GitHub's Student Developer Pack which provides monatary credit for their service.

  2. Go to the Digital Ocean website and create an account.

  3. Create a Digital Ocean Droplet Create a Droplet

  4. Choose the Ubuntu Droplet option, as Ubuntu is the best. Because of the nature of the site, choosing the minimal faculties for your droplet is more than enough to handle the traffic and deployment of our website.Choose the Ubuntu Droplet Type

  5. Choose a Digital Ocean datacenter region that is closest to you physically. Because our team is based in the United States, we chose New York 3.

  6. Consider creating an SSH key for your new droplet. Digital Ocean's online console access is a bit crude. For Window's users, you can use Putty as an ssh client.Configure the Droplet

  7. Press Create!!!

Setting up Flask

  1. Now that you have your droplet, we can now start configuring our virtual server to allow for the execution of Flask applications. First, ensure that the apt-get command is not stale on your server. Run the following commands:

    sudo apt-get update
    sudo apt-get upgrade
    
  2. Ensure that your server has wsgi or (Web Server Gateway Interface) enabled as this is a prerequisite for running python frameworks. Run the following commands:

    sudo apt-get install libapache2-mod-wsgi
    sudo a2enmod wsgi 
    
  3. Now enter the /var/www directory and clone our repo by running the following commands:

    cd /var/www
    git clone https://github.com/adle29/cs373-idb.git
    cd cs373-idb
    
  4. Our website has 2 working states: stable and development.

    echo "stable" && git pull origin master
    
    echo "development" && git pull origin dev
    
  5. Now that our website is on your server, we just need to install all the dependencies and do a little housework to run this bad boy. First thing we need is pip. pip is a python package manager which will be used to install most of our dependencies. Run the following command:

    sudo apt-get install python-pip
    
  6. To avoid complicating your dependencies and depreciating other web projects, it is best to run the app in a virtual environment. virtualenv is needed to do so. Run the following commands:

    sudo pip install virtualenv 
    
  7. Create a virtual environment by running the following command:

    sudo virtualenv venv
    
  8. Activate the virtual server and install Flask. Run the following commands:

    source venv/bin/activate
    sudo pip install Flask
    
  9. Ta-da!! Check to see if everything works by running the following command:

    python apps/__init__.py
    
  10. It should display Running on http://localhost:5000/ or something to that nature. If you see this message, you have successfully configured the app.

  11. Whenever you are done, you can deactivate the virtual environment with the following command:

    deactivate
    

Setting up a Virtual Host

Right now the app can only run locally, so any attempt to find and load the site from the web will end in failure. You need to create a few more files to get it working.

  1. First, create the VirtualHost file with the following command:

    sudo nano /etc/apache2/sites-available/GolazoApp.conf
    

    This will open a text editor. Type to following into the file:

    <VirtualHost *:80>
    		ServerName [ip address] 
    		ServerAdmin [email protected]
    		WSGIScriptAlias / /var/www/cs373-idb/golazoapp.wsgi
    		<Directory /var/www/cs373-idb/apps/>
    			Order allow,deny
    			Allow from all
    		</Directory>
    		Alias /static /var/www/cs373-idb/apps/static
    		<Directory /var/www/cs373-idb/apps/static/>
    			Order allow,deny
    			Allow from all
    		</Directory>
    		ErrorLog ${APACHE_LOG_DIR}/error.log
    		LogLevel warn
    		CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    
  2. Finally, enable the virtual host by entering the following command:

    sudo a2ensite GolazoApp.conf
    
  3. Apache uses a specific type of file to serve Flask applications: .wsgi files. You will need to create one in your app directory.

    cd /var/www/cs373-idb
    sudo nano golazoapp.wsgi
    

    Write the following into the file:

    #!/usr/bin/python
    import sys
    import logging
    logging.basicConfig(stream=sys.stderr)
    sys.path.insert(0,"/var/www/cs373-idb/")
    
    from apps import app as application
    application.secret_key = 'Add your secret key'
    
  4. Your server needs a restart in order to reflect the changes. This can be done by entering the following command:

    sudo service apache2 restart 
    

Running on Local Machine

To run the site on your local machine, you still need to ensure that all dependency prerequisites are fulfilled. Follow the steps above in respect to installing the dependencies but on your local machine. After that, clone the repo:

```
git clone https://github.com/adle29/cs373-idb.git
cd cs373-idb
```

After you are sure that all your dependencies are working, you can immediately run the app by running the following command:

```
python apps/__init__.py
```

This will deploy the site in http://localhost:5000/

⚠️ **GitHub.com Fallback** ⚠️