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

3. Django 1.8 Server Build - CentOS 7 hosted on VPS - Apache Install

django.png




Bookmark and Share





bogotobogo.com site search:




Note

In previous two chapters (1. Django 1.8 Server Build - CentOS 7 hosted on VPS and 2. Django 1.8 Server Build - CentOS 7 hosted on VPS - ssh login and firewall):

  1. We installed CentOS 7 and boot up the machine.
  2. Then, we setup DNS for newly purchased domain name.
  3. We setup ssh login and firewall.

In this chapter, we'll install Apache server for a domain, sfvue.com.





Installing Apache

We need to have Apache installed in order to configure virtual hosts for it. We can use yum to install Apache through CentOS's default software repositories:

[sfvue@sf sf]$ sudo yum install httpd
...
---> Package httpd.x86_64 0:2.4.6-31.el7.centos will be installed
...
Running transaction
  Installing : apr-1.4.8-3.el7.x86_64                                                            1/5
  Installing : apr-util-1.5.2-6.el7.x86_64                                                       2/5
  Installing : httpd-tools-2.4.6-31.el7.centos.x86_64                                            3/5
  Installing : mailcap-2.1.41-2.el7.noarch                                                       4/5
  Installing : httpd-2.4.6-31.el7.centos.x86_64                                                  5/5
  Verifying  : httpd-tools-2.4.6-31.el7.centos.x86_64                                            1/5
  Verifying  : apr-1.4.8-3.el7.x86_64                                                            2/5
  Verifying  : mailcap-2.1.41-2.el7.noarch                                                       3/5
  Verifying  : httpd-2.4.6-31.el7.centos.x86_64                                                  4/5
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                                       5/5

Installed:
  httpd.x86_64 0:2.4.6-31.el7.centos

Dependency Installed:
  apr.x86_64 0:1.4.8-3.el7                               apr-util.x86_64 0:1.5.2-6.el7
  httpd-tools.x86_64 0:2.4.6-31.el7.centos               mailcap.noarch 0:2.1.41-2.el7

Complete!
[root@li1189-218 ~]#

The configuration for Apache is contained in the httpd.conf file, which is located at: /etc/httpd/conf/httpd.conf. Let's make a backup of this file into our home directory:

cp /etc/httpd/conf/httpd.conf ~/httpd.conf.backup




After installing Apache, we can issue the following commands to enable Apache to start on boot and run for the first time:

$ sudo /bin/systemctl enable httpd.service
$ sudo /bin/systemctl start httpd.service




Apache is working!

domain (sfvue.com):

sfvue-com.png

To check if Apache is running:

[sfvue@sf ~]$ sudo /bin/systemctl status httpd.service
httpd.service - The Apache HTTP Server
   Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled)
   Active: active (running) since Wed 2015-06-17 02:51:17 PDT; 14s ago
  Process: 5361 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS)
  Process: 5154 ExecReload=/usr/sbin/httpd $OPTIONS -k graceful (code=exited, status=0/SUCCESS)
 Main PID: 5365 (httpd)
   Status: "Total requests: 0; Current requests/sec: 0; Current traffic:   0 B/sec"
   CGroup: /system.slice/httpd.service
           ├─5365 /usr/sbin/httpd -DFOREGROUND
           ├─5367 /usr/sbin/httpd -DFOREGROUND
           ├─5368 /usr/sbin/httpd -DFOREGROUND
           ├─5369 /usr/sbin/httpd -DFOREGROUND
           ├─5370 /usr/sbin/httpd -DFOREGROUND
           └─5371 /usr/sbin/httpd -DFOREGROUND

Jun 17 02:51:17 sf httpd[5365]: AH00558: httpd: Could not reliably determine the server's fully qualified d...essage
Jun 17 02:51:17 sf systemd[1]: Started The Apache HTTP Server.
Hint: Some lines were ellipsized, use -l to show in full.

And the Apache version:

$ httpd -v
Server version: Apache/2.4.6 (CentOS)
Server built:   Mar 12 2015 15:07:19




Create the Directory Structure

First, we need to make a directory structure that will hold the site data to serve to visitors.

Our document root (the top-level directory that Apache looks at to find content to serve) will be set to individual directories in the /var/www directory. We will create a directory here for each of the virtual hosts that we plan on making.





Configuring Apache

Now we'll configure virtual hosting so that we can host multiple domains (or subdomains) with the server. These websites can be controlled by different users, or by a single user, as we prefer.

Before we get started, we need to combine all configuration on virtual hosting into a single file called vhost.conf located in the /etc/httpd/conf.d/ directory. Open this file, and we'll begin by setting up virtual hosting.





Configure Name-based Virtual Hosts

There are different ways to set up virtual hosts, however Name-based Virtual Hosts configuration is recommended. By default, Apache listens on all IP addresses available to it. Now we will create virtual host entries for each site that we need to host with this server. Here are two examples for sites at "sfvue.com".

Let's create a file, /etc/httpd/conf.d/vhost.conf:

[sfvue@sf ~]$ sudo vim /etc/httpd/conf.d/vhost.conf
<VirtualHost *:80>
    ServerAdmin webmaster@sfvue.com
    ServerName sfvue.com
    ServerAlias www.sfvue.com
    DocumentRoot /srv/www/sfvue.com/public_html/
    ErrorLog /srv/www/sfvue.com/logs/error.log
    CustomLog /srv/www/sfvue.com/logs/access.log combined
</VirtualHost>

Note : for Ubuntu, we may want to create a fine /etc/apache2/conf.d/vhost.conf.

Also, we need to comment all lines of /etc/httpd/conf.d/welcome.conf.

All of the files for the sites that we host will be located in directories that exist underneath /srv/www. We can symbolically link these directories into other locations if we need them to exist elsewhere.

Before we can use the above configuration we'll need to create the specified directories. For the above configuration, you can do this by issuing the following commands:

$ sudo mkdir -p /srv/www/sfvue.com/public_html
$ sudo mkdir /srv/www/sfvue.com/logs

tree.png

The /srv/www/sfvue.com/public_html/index.html looks like this:

<html>
<head>Head</head>
<body>Body - sfvue.com</body>
</html>

After we've set up our virtual hosts, we can issue the following commands to enable Apache to start on boot and run for the first time:

$ sudo /bin/systemctl enable httpd.service
$ sudo /bin/systemctl start httpd.service

For Ubuntu 14:

$ sudo sysv-rc-conf apache2 on
$ sudo service apache2 restart

Assuming that we have configured the DNS for our domain to point to our Linode's IP address, virtual hosting for our domain should now work. Remember that we can create as many virtual hosts as we want.

Any time we change an option in our vhost.conf file, or any other Apache configuration file, remember to reload the configuration with the following command:

$ sudo /bin/systemctl reload httpd.service
$ sudo /bin/systemctl restart httpd.service

We may get the following error saying:
Forbidden
You don't have permission to access / on this server.:

Forbidden-sfvue-com.png

So, we need to set permission in /etc/httpd/conf.d/vhost.conf:

<VirtualHost *:80>
    ServerAdmin webmaster@sfvue.com
    ServerName sfvue.com
    ServerAlias www.sfvue.com
    DocumentRoot /srv/www/sfvue.com/public_html/
    ErrorLog /srv/www/sfvue.com/logs/error.log
    CustomLog /srv/www/sfvue.com/logs/access.log combined
    <Directory "/srv/www/sfvue.com/">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

Here is we've got only after adding the permission:

index-html.png



Subdomain - pics.sfvue.com

Now that master domain has been setup, we want to do more: subdomain (pics.sfvue.com).

First, we need to login to Linode and select the server that's hosting sfvue.com website. Click on the DNS Manager tab. We've already set up the parent domain web site, we should have an entry for our website which we are creating a new subdomain for. Click Edit for that domain entry. We should now see lists all DNS records. Find the section that lists A/AAA Records and click Add a new A record.

We should now see a form with 2 text fields (Hostname and IP Address) and 1 select input. For the hostname, enter pics.sfvue.com and, for the IP address, enter the server's IP address. Leave the select input alone. Click Save Changes and we're good to go.

A-Records.png

Then, we need to create another file structure:

$ sudo mkdir -p pics.sfvue.com/logs
$ sudo mkdir -p pics.sfvue.com/public_html

It looks like this:

tree-subdomain.png

Also, here is the updated /etc/httpd/conf.d/vhost.conf:

<VirtualHost *:80>
    ServerAdmin webmaster@sfvue.com
    ServerName sfvue.com
    ServerAlias www.sfvue.com
    DocumentRoot /srv/www/sfvue.com/public_html/
    ErrorLog /srv/www/sfvue.com/logs/error.log
    CustomLog /srv/www/sfvue.com/logs/access.log combined
    <Directory "/srv/www/sfvue.com/">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>
<VirtualHost *:80>
    ServerAdmin webmaster@sfvue.com
    ServerName pics.sfvue.com
    ServerAlias www.pics.sfvue.com
    DocumentRoot /srv/www/pics.sfvue.com/public_html/
    ErrorLog /srv/www/pics.sfvue.com/logs/error.log
    CustomLog /srv/www/pics.sfvue.com/logs/access.log combined
    <Directory "/srv/www/pics.sfvue.com/">
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
    </Directory>
</VirtualHost>

$ sudo /bin/systemctl reload httpd.service
$ sudo /bin/systemctl restart httpd.service

Then, we may get the properly rendered subdomain as shown below:

pics-index-html.png

Continue : 4. Install and Configure MariaDB Database server & PHP











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







Django 1.8



Introduction - Install Django and Project Setup

Creating and Activating Models

Hello World A - urls & views

Hello World B - templates

Hello World C - url dispatcher

Hello World D - Models and SQLite Database

MVC - Hello World

Hello World on a Shared Host A

Hello World on a Shared Host B

Hello World - Admin Site Setup

virtualenv

Creating test project on virtualenv

Test project's settings.py

Creating Blog app and setting up models

Blog app - syncdb A

Blog app - syncdb B

Blog app - views and urls

Blog app - templates

Blog app - class based templates

Image upload sample code - local host

Authentication on Shared Host using FastCGI

User Registration on Shared Host A

User Registration with a Customized Form on Shared Host B

Blogs on Shared Host

Serving Django app with uWSGI and Nginx

Image upload sample code - shared host

Managing (Deploying) Static files (CSS, Images, Javascript) on Shared Host

Forum application on a Shared Host

Django Python Social Auth : Getting App ID (OAuth2) - Facebook, Twitter, and Google

Django: Python social auth, Facebook, Twitter, and Google Auth

Django: Python social auth, Facebook, Twitter, and Google Auth with Static files

...

Django 1.8 hosted on Linode VPS ==>

1. Setup CentOS 7 hosted on VPS

1B. Setup CentOS 7 hosted on VPS (multi-domain hosting setup) - Name server and Zone File settings (from GoDaddy to Linode)

2. ssh login and firewall

3. Apache Install

4. Install and Configure MariaDB Database server & PHP

5. Install and Configure Django

6. Model

7. Model 2 : populate tables, list_display, and search_fields

8. Model 3 (using shell)

9. Views (templates and css)

10. Views 2 (home page and more templates)

11. TinyMCE

12. TinyMCE 2

13. ImageField/FileField : Serving image/video files uploaded by a user

14. User Authentication 1 (register & forms)

15. User Authentication 2 (login / logout)

16. User Authentication 3 (password reset) - Sent from Email (gmail) setup etc.

17. User Authentication 4 (User profile & @login_required decorator)

18. User Authentication 5 (Facebook login)

19. User Authentication 6 (Google login)

20. User Authentication 7 (Twitter login)

21. User Authentication 8 (Facebook/Google/Twitter login buttons)

22. Facebook open graph API timeline fan page custom tab 1

23. Facebook Open Graph API Timeline Fan Page Custom Tab 2 (SSL certificate setup)

24. Facebook open graph API timeline fan page custom tab 3 (Django side - urls.py, settings.py, and views.py)

...

A sample production site Django 1.8.7: sfvue.com / einsteinish.com ==>

A sample production app (sfvue.com) with virtualenv and Apache

2. Upgrading to Django 1.8.7 sfvue.com site sample with virtualenv and Apache

(*) Django 1.8.7 einsteinish.com site - errors and fixes

Django 1.8.12 pytune.com site - local with Apache mod_wsgi

Django 1.8.12 pytune.com site - local with Nginx and uWSGI

Django 1.8.12 pytune.com site - deploy to AWS with Nginx and uWSGI

Django Haystack with Elasticsearch and Postgres

Django Compatibility Cheat Sheet

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