BogoToBogo
  • Home
  • About
  • Big Data
  • Machine Learning
  • AngularJS
  • Python
  • C++
  • go
  • DevOps
  • Kubernetes
  • Algorithms
  • More...
    • Qt 5
    • Linux
    • FFmpeg
    • Matlab
    • Django 1.8
    • Ruby On Rails
    • HTML5 & CSS

Flask blog app with MongoDB via Apache WSGI : Part 3 (Production on CentOS 7)

Python-Flask.png




Bookmark and Share





bogotobogo.com site search:

Note

Continued from Flask blog app with MongoDB via Apache WSGI on Ubuntu 14.

In this page, we'll deploy our Flask blog app (memonimo.com) using Apache on CentOS 7 VPS.

Git : FlaskBlog





VPS Setup - MongoDB

So far, we've worked on our local Ubuntu 14 machine.

Now, it's time to play with CentOS 7 VPS.

We need to install MongoDB since our blog is using it.

First, let's configure the package management system (yum). Create a file ,/etc/yum.repos.d/mongodb-org-2.6.repo, and put in the following configuration information for the MongoDB 2.6 repository:

[mongodb-org-2.6]
name=MongoDB 2.6 Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1

Next, we need to install the MongoDB packages and associated tools.

$ sudo yum install -y mongodb-org

We can start the mongod process by issuing the following command:

$ sudo service mongod start
Starting mongod (via systemctl):                           [  OK  ]

We can verify that the mongod process has started successfully by checking the contents of the log file at /var/log/mongodb/mongod.log for a line reading:

MongoDB starting : pid=16297 port=27017 dbpath=/var/lib/mongo 64-bit host=sf
... [initandlisten] db version v2.6.12

Note that <port> is the port configured in /etc/mongod.conf, 27017 by default.

We can optionally ensure that MongoDB will start following a system reboot by issuing the following command:

$ sudo chkconfig mongod on

We can restat/stop the service:

$ sudo service mongod restart
$ sudo service mongod stop




Clone repository

Clone repository : FlaskBlog.

memonimo-tree.png



Production setup - config/wsgi

Modify config.py:

DEBUG = False 

/var/www/flask/memonimo/flaskapp.wsgi:

#!/usr/bin/python
import sys
import logging
logging.basicConfig(stream=sys.stderr)

# Dev
# sys.path.insert(0,"/var/www/FlaskApp/")
# from Blog import app as application

# Production
sys.path.insert(0,"/var/www/flask")
from memonimo import app as application

application.secret_key = 'memonimo secret key'

Modify /var/www/flask/memonimo/config.py:

...
app = Flask('memonimo')
...




Virtualenv

Let's setup Virtualenv:

$ sudo virtualenv venv
$ source venv/bin/activate
(venv)$ sudo pip install -r requirements.txt
...
Installing collected packages: Werkzeug, MarkupSafe, Jinja2, itsdangerous, flask, markdown, flask-markdown, pymongo, gunicorn
  Running setup.py install for MarkupSafe
  Running setup.py install for itsdangerous
  Running setup.py install for flask
  Running setup.py install for markdown
  Running setup.py install for flask-markdown
  Running setup.py install for pymongo

Check with Flask server (Werkzeug):

(venv)$ sudo python __init__.py
 * Running on http://0.0.0.0:8000/ (Press CTRL+C to quit)
 * Restarting with stat
 * Debugger is active!
 * Debugger pin code: 100-555-666




Apache config

Create a log directory:

$ sudo mkdir -p /var/www/memonimo.com/logs/

The following is the Apache configuration (/etc/httpd/sites-available/memonimo.com.conf):

<VirtualHost *:80>
                ServerAlias memonimo.com
                ServerName www.memonimo.com
                ServerAdmin admin@memonimo.com
                WSGIDaemonProcess memonimo user=apache group=apache threads=5 python-path=/var/www/flask/memonimo:/var/www/flask/memonimo/venv/lib/python2.7/site-packages
                WSGIScriptAlias / /var/www/flask/memonimo/flaskapp.wsgi
                <Directory /var/www/flask/memonimo/>
                        WSGIProcessGroup memonimo
                        WSGIApplicationGroup %{GLOBAL}
                        Order allow,deny
                        Allow from all
                </Directory>
                Alias /static /var/www/flask/memonimo/static
                <Directory /var/www/flask/memonimo/static/>
                        Order allow,deny
                        Allow from all
                </Directory>
                ErrorLog /var/www/memonimo.com/logs/error.log
                LogLevel warn
                CustomLog /var/www/memonimo.com/logs/access.log combined
</VirtualHost>

Let's create a symlink:

$ sudo ln -s /etc/httpd/sites-available/memonimo.com.conf /etc/httpd/sites-enabled/memonimo.com.conf
$ ls -la /etc/httpd/sites-enabled
...
lrwxrwxrwx 1 root root   44 May  5 12:00 memonimo.com.conf -> /etc/httpd/sites-available/memonimo.com.conf
...

Restart the server:

$ sudo apachectl restart




Errors and Fixes

At memonimo.com on the browser:

 IOError: [Errno 13] Permission denied: '/usr/share/httpd/app.log'

This can be fixed by modifying the permission for /usr/share/httpd:

$ sudo chown -R apache:apache httpd




Site running on CentOS 7 VPS

At the first run we get the following install page for setting up our blog:

memonimo-install-page.png

Hit "Sumit":

PostPageAfterSubmit.png

At "Add New":

NewPost.png







Ph.D. / Golden Gate Ave, San Francisco / Seoul National Univ / Carnegie Mellon / UC Berkeley / DevOps / Deep Learning / Visualization

YouTubeMy YouTube channel

Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong








Flask



Deploying Flask Hello World App with Apache WSGI on Ubuntu 14

Flask Micro blog "Admin App" with Postgresql

Flask "Blog App" with MongoDB - Part 1 (Local via Flask server)

Flask "Blog App" with MongoDB on Ubuntu 14 - Part 2 (Local Apache WSGI)

Flask "Blog App" with MongoDB on CentOS 7 - Part 3 (Production Apache WSGI )

Flask word count app 1 with PostgreSQL and Flask-SQLAlchemy

Flask word count app 2 via BeautifulSoup, and Natural Language Toolkit (NLTK) with Gunicorn/PM2/Apache

Flask word count app 3 with Redis task queue

Flask word count app 4 with AngularJS polling the back-end

Flask word count app 5 with AngularJS front-end updates and submit error handling

Flask word count app 0 - Errors and Fixes

Flask with Embedded Machine Learning I : Serializing with pickle and DB setup

Flask with Embedded Machine Learning II : Basic Flask App

Flask with Embedded Machine Learning III : Embedding Classifier

Flask with Embedded Machine Learning IV : Deploy

Flask with Embedded Machine Learning V : Updating the classifier

Flask AJAX with jQuery

Flask blog app with Dashboard 1 - SignUp page

Flask blog app with Dashboard 2 - Sign-In / Sign-Out

Flask blog app with Dashboard 3 - Adding blog post item

Flask blog app with Dashboard 4 - Update / Delete

Flask blog app with Dashboard 5 - Uploading an image

Flask blog app with Dashboard 6 - Dash board

Flask blog app with Dashboard 7 - Like button

Flask blog app with Dashboard 8 - Deploy

Flask blog app with Dashboard - Appendix (tables and mysql stored procedures/functions

Sponsor Open Source development activities and free contents for everyone.

Thank you.

- K Hong






Python tutorial



Python Home

Introduction

Running Python Programs (os, sys, import)

Modules and IDLE (Import, Reload, exec)

Object Types - Numbers, Strings, and None

Strings - Escape Sequence, Raw String, and Slicing

Strings - Methods

Formatting Strings - expressions and method calls

Files and os.path

Traversing directories recursively

Subprocess Module

Regular Expressions with Python

Regular Expressions Cheat Sheet

Object Types - Lists

Object Types - Dictionaries and Tuples

Functions def, *args, **kargs

Functions lambda

Built-in Functions

map, filter, and reduce

Decorators

List Comprehension

Sets (union/intersection) and itertools - Jaccard coefficient and shingling to check plagiarism

Hashing (Hash tables and hashlib)

Dictionary Comprehension with zip

The yield keyword

Generator Functions and Expressions

generator.send() method

Iterators

Classes and Instances (__init__, __call__, etc.)

if__name__ == '__main__'

argparse

Exceptions

@static method vs class method

Private attributes and private methods

bits, bytes, bitstring, and constBitStream

json.dump(s) and json.load(s)

Python Object Serialization - pickle and json

Python Object Serialization - yaml and json

Priority queue and heap queue data structure

Graph data structure

Dijkstra's shortest path algorithm

Prim's spanning tree algorithm

Closure

Functional programming in Python

Remote running a local file using ssh

SQLite 3 - A. Connecting to DB, create/drop table, and insert data into a table

SQLite 3 - B. Selecting, updating and deleting data

MongoDB with PyMongo I - Installing MongoDB ...

Python HTTP Web Services - urllib, httplib2

Web scraping with Selenium for checking domain availability

REST API : Http Requests for Humans with Flask

Blog app with Tornado

Multithreading ...

Python Network Programming I - Basic Server / Client : A Basics

Python Network Programming I - Basic Server / Client : B File Transfer

Python Network Programming II - Chat Server / Client

Python Network Programming III - Echo Server using socketserver network framework

Python Network Programming IV - Asynchronous Request Handling : ThreadingMixIn and ForkingMixIn

Python Coding Questions I

Python Coding Questions II

Python Coding Questions III

Python Coding Questions IV

Python Coding Questions V

Python Coding Questions VI

Python Coding Questions VII

Python Coding Questions VIII

Python Coding Questions IX

Python Coding Questions X

Image processing with Python image library Pillow

Python and C++ with SIP

PyDev with Eclipse

Matplotlib

Redis with Python

NumPy array basics A

NumPy Matrix and Linear Algebra

Pandas with NumPy and Matplotlib

Celluar Automata

Batch gradient descent algorithm

Longest Common Substring Algorithm

Python Unit Test - TDD using unittest.TestCase class

Simple tool - Google page ranking by keywords

Google App Hello World

Google App webapp2 and WSGI

Uploading Google App Hello World

Python 2 vs Python 3

virtualenv and virtualenvwrapper

Uploading a big file to AWS S3 using boto module

Scheduled stopping and starting an AWS instance

Cloudera CDH5 - Scheduled stopping and starting services

Removing Cloud Files - Rackspace API with curl and subprocess

Checking if a process is running/hanging and stop/run a scheduled task on Windows

Apache Spark 1.3 with PySpark (Spark Python API) Shell

Apache Spark 1.2 Streaming

bottle 0.12.7 - Fast and simple WSGI-micro framework for small web-applications ...

Flask app with Apache WSGI on Ubuntu14/CentOS7 ...

Selenium WebDriver

Fabric - streamlining the use of SSH for application deployment

Ansible Quick Preview - Setting up web servers with Nginx, configure enviroments, and deploy an App

Neural Networks with backpropagation for XOR using one hidden layer

NLP - NLTK (Natural Language Toolkit) ...

RabbitMQ(Message broker server) and Celery(Task queue) ...

OpenCV3 and Matplotlib ...

Simple tool - Concatenating slides using FFmpeg ...

iPython - Signal Processing with NumPy

iPython and Jupyter - Install Jupyter, iPython Notebook, drawing with Matplotlib, and publishing it to Github

iPython and Jupyter Notebook with Embedded D3.js

Downloading YouTube videos using youtube-dl embedded with Python

Machine Learning : scikit-learn ...

Django 1.6/1.8 Web Framework ...









Contact

BogoToBogo
contactus@bogotobogo.com

Follow Bogotobogo

About Us

contactus@bogotobogo.com

YouTubeMy YouTube channel
Pacific Ave, San Francisco, CA 94115

Pacific Ave, San Francisco, CA 94115

Copyright © 2024, bogotobogo
Design: Web Master