Share
Embed
Transcript
46 slides
-
What you need Web Host A home for your website
Domain Name A url for your website -
Development Server vs Production Server ➡ Django provides a development
server ๏ Does not scale with multiple requests (high threading) ✓ We need to setup a production server -
Web Hosting Storage How much space do you need? Bandwidth
How much traffic do you expect? Money How much do you want to spend daily? -
Do you want/need to manage ... physical infrastructure? operating system?
physical server Virtual Private Server Shared Web Host Yes Yes No No -
Dedicated Physical Server ✓ Total Control ๏ Maintenance of the
physical infrastructure ๏ Administration of the operating system ๏ Flexibility -
Virtual Private Server (VPS) ๏ Administration of the operating system
✓ No maintenance of the physical infrastructure ✓ Flexibility (pay for what you need) -
Shared Web Host ✓ No administration of the operating system
๏ Cost ๏ Not adequate for specific needs -
Choosing the technology • The operating system • The web
server • The database http://w3techs.com/technologies -
Choosing a technology Choosing a technology depends on Specific needs
Specific applications that your web applications uses Security What you are comfortable to administer -
LAMP vs MEAN • Linux • Apache • MySQL •
PHP ( / Perl / Python) • MongoDB • Express • Angular • Node.js -
The big picture Client Side Web Browser Server Side Web
Server myServlet.java Database Server mod_wsgi -
Apache and Python - 3 solutions ➡ How Apache runs
Python code • mod_wsgi • FastCGI, SCGI, AJP (deprecated) • Mod_python (deprecated) -
Apache and mod_wsgi Apache http://www.apache.org/ Python WSGI adapter for Apache
(mod_wsgi) http://code.google.com/p/modwsgi/ Install mod_wsgi on MAC OS $ brew tap homebrew/apache $ brew install mod_wsgi -
File Permissions ➡ Modify the permissions for Apache $ sudo
chown -R :_www tsans ➡ Modify the permissions for Apache $ chmod g+w tsans/tsans $ chmod g+w tsans/tsans/tsans.db $ chmod g+w tsans/tsans/uploads $ find tsans/tsans/uploads -type d -exec chmod g+w {} \; _www for Mac OS www-data for Linux only for SQLite } -
Collect static files tsans/ static/ HelloYou/ static/ tsans/ static/ WebDirectory/
static/ STATIC_ROOT = os.path.join(PROJECT_PATH, '../static/') tsans/settings.py Configure the static root directory Collect the static file $ python manage.py collectstatic -
.... LoadModule wsgi_module libexec/apache2/mod_wsgi.so Alias /static/ /project_path/tsans/static/ <Directory /project_path/tsans/static> Order
deny,allow Allow from all </Directory> WSGIScriptAlias / /project_path/tsans/tsans/wsgi.py WSGIDaemonProcess example.com python-path=/project_path/tsans:/django_path/site-packages WSGIProcessGroup example.com <Directory /project_path/tsans/tsans> <Files wsgi.py> Order deny,allow Allow from all </Files> </Directory> .... /etc/apache2/httpd.conf Restart Apache $ sudo apachectl restart -
Reminder : Find your Django Path $ python >> import
django >> django.__file__ '/usr/local/lib/python2.7/site-packages/django/__init__.pyc' Find your Django installation path my django_path -
Debugging the configuration Server error $ cat /var/log/apache2/error_log HTTP error
$ cat /var/log/apache2/access_log -
Disable Django debug message (once it’s working) DEBUG = False
TEMPLATE_DEBUG = False tsans/settings.py -
Configure Apache # Virtual hosts Include /private/etc/apache2/extra/httpd-vhosts.conf /etc/apache2/http.conf Enable virtual
hosts <VirtualHost *:80> ServerAdmin [email protected] ServerName site1.example.com ServerAlias www.site1.example.com ErrorLog "/var/log/apache2/site1.example.com-error_log" CustomLog "/var/log/apache2/site1.example.com-access_log" common ****** insert Django apache configuration here ******* </VirtualHost> /etc/apache2/extra/httpd-vhosts.conf Configure a virtual host -
Spoof your IP address to the domain (for testing) 127.0.0.1
site1.example.com 127.0.0.1 www. site1.example.com /etc/hosts -
MySQL MySQL http://www.mysql.com/ Install MySQL on MAC OS https://github.com/SixArm/sixarm_mac_osx_installation_help/blob/master/mysql.md MySQL
driver for Python $ pip install MySQL-python Start MySQL $ mysql.server start -
Create a MySQL database for Django DROP DATABASE IF EXISTS
`mydb`; CREATE DATABASE `mydb` DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci; USE 'mysql'; GRANT ALL PRIVILEGES ON mydb.* TO 'mydb_user'@'localhost' IDENTIFIED BY 'pass4mydb' WITH GRANT OPTION; FLUSH PRIVILEGES; tsans/mysql/init.sql Initialize the MySQL database $ mysql -u root -p < script.sql -
Configure Django to use MySQL .... DATABASES = { 'default':
{ 'ENGINE': 'django.db.backends.mysql', 'OPTIONS': { 'read_default_file': os.path.join(BASE_DIR, ‘tsans/mysql/my.cf’), }, } } .... tsans/settings.py [client] database = mydb user = mydb_user password = pass4mydb default-character-set = utf8 tsans/mysql/my.cf -
Python Virtualenv ➡ Running multiple Django applications that have different
dependencies of different versions $ pip install virtualenv -
Prerequisite Collect all dependencies $ pip freeze > tsans/REQUIREMENTS.txt Cleanup
the file by removing unnecessary packages Django==1.5.2 PIL==1.1.7 pysqlite==2.6.3 wsgiref==0.1.2 tsans/virtualenv/REQUIREMENTS.txt -
Create a virtual environment 1. Create a directory my_app $
mkdir my_app $ cd my_app $ virtualenv my_app 2. Copy (or create) your django app in my_app 3. Activate the environment $ source bin/activate 4. Install the dependencies $ pip install -r tsans/tsans/virtualenv/REQUIREMENTS.txt 5. Configure Apache -
Github (static hosting) $ git checkout gh-pages $ git merge
master $ git push origin gh-pages $ git branch gh-pages Create the gh-pages branch (first time only) Synchronize gh-pages with master -
How to get a domain name? You need to buy
one from a Domain Name Registrar -
What about Qatar? ✓ A domain name in .qa ➡
See Qatar Domain Registry