zoukankan      html  css  js  c++  java
  • Django 1.0.x PostgreSQL 8.3 MySQL 5.0 Apache 2

    apt-get:
    ——————
    $ sudo apt-get install python-psycopg2 python-psycopg postgresql-8.2 postgresql-client-8.2 apache2 libapache2-mod-python subversion pgadmin3 pgadmin3-data openssh-server

    Django:
    ——————

    Final Version:
    mkdir web
    cd web

    tar xzvf Django-1.0.2-final.tar.gz
    cd Django-1.0.2-final
    sudo python setup.py install

    Dev Version:
    mkdir web
    cd web
    Web$ svn co http://code.djangoproject.com/svn/django/trunk/ django_src

    Same for both Version:
    Web$ sudo ln -s `pwd`/django_src/django /usr/lib/python2.5/site-packages/django

    Web$ sudo cp `pwd`/django_src/django/bin/django-admin.py /usr/local/bin

    Web$ mkdir django_projects

    Web$ mkdir django_templates

    Web$ mkdir media

    Web$ cd ..

    $ sudo gedit .bashrc
    export PYTHONPATH=”.:$HOME/web/django_projects”

    CLOSE SHELL, AND TO OPEN NEW ONE

    $ cd /var/www
    --this is the folder where Apache is installed
    /var/www$ sudo ln -s ~/web/media media
    /var/www$ sudo ln -s ~/web/django_src/django/contrib/admin/media admin_media

    $ cd ~/web/django_projects
    /web/django_projects$ django-admin.py startproject django_test


    MySQL:
    ————

    sudo apt-get mysql-server
    PostgreSQL:
    ——————

    /web/django_projects$ cd ~
    $ sudo su postgres -c psql template1
    template1=# ALTER USER postgres WITH PASSWORD ‘password’;
    template1=# \q

    $ sudo gedit /usr/share/applications/pgadmin.desktop
    --ADD BELOW INTO THE FILE:
    [Desktop Entry] Comment= PostgreSQL Administrator III
    Name=pgAdmin III
    Encoding=UTF-8
    Exec=pgadmin3
    Terminal=false
    Comment[en_GB]=PostgreSQL Administrator III
    Icon=/usr/share/pixmaps/pgadmin3.xpm
    Type=Application
    Categories=GNOME;Application;Database;System;
    Name[en_GB]=pgAdmin III

    $ sudo su postgres -c createuser xxd

    $ sudo gedit /etc/postgresql/8.3/main/postgresql.conf
    CHANGE #listen_addresses = ‘localhost’
    to listen_addresses = ‘*’
    AND #password_encryption = on
    to password_encryption = on

    $ sudo gedit /etc/postgresql/8.3_add/main/pg_hba.conf
    # DO NOT DISABLE!
    # If you change this first entry you will need to make sure
    # that the database super user can access the database using
    # some other method.
    # Noninteractive access to all databases is required during
    automatic maintenance
    # Database administrative login by UNIX sockets
    # (autovacuum, daily cronjob, replication, and similar tasks).
    # local all postgres ident sameuser

    # TYPE DATABASE USER CIDR-ADDRESS METHOD

    # “local” is for Unix domain socket connections only
    local all all md5
    # IPv4 local connections:
    host all all 127.0.0.1/32 md5
    # IPv6 local connections:
    host all all ::1/128 md5

    $ sudo /etc/init.d/postgresql-8.3 restart

    settings.py
    ————————————

    $ cd web/django_projects/django_test/
    /web/django_projects/django_test$ gedit settings.py

    # Django settings for osmrc_test_suite project.

    DEBUG = True #turn this off for a production site
    TEMPLATE_DEBUG = DEBUG

    ADMINS = (
    (’xxd’, ‘xxd@gmail.com’),
    )

    MANAGERS = ADMINS

    DATABASE_ENGINE = ‘postgresql’ # ‘postgresql_psycopg2′, ‘postgresql’, ‘mysql’, ’sqlite3′ or ‘oracle’.
    DATABASE_NAME = ’some_db_name’ # Or path to database file if using sqlite3.
    DATABASE_USER = ‘vern’ # Not used with sqlite3.
    DATABASE_PASSWORD = ’some_password’ # Not used with sqlite3.
    DATABASE_HOST = ” # Set to empty string for localhost. Not used with sqlite3.
    DATABASE_PORT = ” # Set to empty string for default. Not used with sqlite3.

    # Local time zone for this installation. Choices can be found here:
    # http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
    # although not all choices may be avilable on all operating systems.
    # If running in a Windows environment this must be set to the same as your
    # system time zone.
    TIME_ZONE = ‘America/Manaus’

    # Language code for this installation. All choices can be found here:
    # http://www.w3.org/TR/REC-html40/struct/dirlang.html#langcodes
    LANGUAGE_CODE = ‘en-us’

    SITE_ID = 1

    # If you set this to False, Django will make some optimizations so as not
    # to load the internationalization machinery.
    USE_I18N = True

    # Absolute path to the directory that holds media.
    # Example: “/home/media/media.lawrence.com/”
    # This is the folder we created
    MEDIA_ROOT = ‘/home/xxd/web/media’

    # URL that handles the media served from MEDIA_ROOT. Make sure to use a
    # trailing slash if there is a path component (optional in other cases).
    # Examples: “http://media.lawrence.com”, “http://example.com/media/”
    MEDIA_URL = ‘http://127.0.0.1/media/’

    # URL prefix for admin media — CSS, JavaScript and images. Make sure to use a
    # trailing slash.
    # Examples: “http://foo.com/media/”, “/media/”.
    # this is the apache synlink we created
    ADMIN_MEDIA_PREFIX = ‘/admin_media/’

    # Make this unique, and don’t share it with anybody.
    SECRET_KEY = ‘^1z1!!@@@@100ej*_fd8(md421j_vj9c)4r*=4i!+-phvtk5a7$’

    # List of callables that know how to import templates from various sources.
    TEMPLATE_LOADERS = (
    ‘django.template.loaders.filesystem.load_template_source’,
    ‘django.template.loaders.app_directories.load_template_source’,
    # ‘django.template.loaders.eggs.load_template_source’,
    )

    MIDDLEWARE_CLASSES = (
    ‘django.middleware.common.CommonMiddleware’,
    ‘django.contrib.sessions.middleware.SessionMiddleware’,
    ‘django.contrib.auth.middleware.AuthenticationMiddleware’,
    ‘django.middleware.doc.XViewMiddleware’,
    )

    #CACHE_BACKEND = ‘memcached://127.0.0.1:11211/’
    #CACHE_MIDDLEWARE_SECONDS = 300
    #CACHE_MIDDLEWARE_KEY_PREFIX = ‘osmrc_test_suite_’
    #CACHE_MIDDLEWARE_ANONYMOUS_ONLY = True

    ROOT_URLCONF = ‘osmrc_test_suite.urls’

    TEMPLATE_DIRS = (
    “/home/xxd/web/django_templates”
    # Put strings here, like “/home/html/django_templates” or “C:/www/django/templates”.
    # Always use forward slashes, even on Windows.
    # Don’t forget to use absolute paths, not relative paths.
    )

    INSTALLED_APPS = (
    ‘django.contrib.auth’,
    ‘django.contrib.contenttypes’,
    ‘django.contrib.sessions’,
    ‘django.contrib.sites’,
    ‘django.contrib.admin’,
    )

    /web/django_projects/django_test$ pyton manage.py syncdb

    /web/django_projects/django_test$ gedit urls.py

    # Uncomment this for admin:

    (r’^admin/’, include(’django.contrib.admin.urls’)),

    Configure Apache and mod_python:
    ——————————–——————————–——————————–
    参阅 `如何搭配 mod_python 运行 Django`_ 学习 mod_python 在安装之后如何配置
    Apache: http://httpd.apache.org/
    mod_python: http://www.modpython.org/
    WSGI: http://www.python.org/peps/pep-0333.html
    如何搭配 mod_python 运行 Django: http://www.djangoproject.com/documentation/modpython/
    server-arrangements wiki page: http://code.djangoproject.com/wiki/ServerArrangements

    $ python django-admin.py startproject myproject
    $ e settings.py
    按照你的不同情况设定不同的参数,然后你就可以执行
    $ python manage.py runserver [port]

    /web/django_projects/django_test$ sudo gedit /etc/apache2/httpd.conf

    MaxRequestsPerChild 1
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE django_test.settings
    PythonPath “['/home/xxd/web/django_projects'] + sys.path”
    PythonDebug On
    SetHandler None
    SetHandler None
    SetHandler None

    $ sudo apache2ctl -k restart
    the error below can be ignored:
    Could not reliably determine the server's fully qualified domain name
    , using 127.0.1.1 for ServerName


    In web brower:
    http://localhost/mysite/

    Reference:
    http://ianlawrence.info/random-stuff/set-up-django-apache-and-postgresql-on-ubuntu-feisty
    http://www.ibm.com/developerworks/cn/linux/l-django/

    作者:Buro#79xxd 出处:http://www.cnblogs.com/buro79xxd/ 文章版权归本人所有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
  • 相关阅读:
    SpringBoot------异步任务的使用
    SpringBoot------定时任务
    MySQL中文编码设置为utf-8
    MySQL 中文未正常显示
    使用postman测试接口时需要先登录怎么办
    python 查询数据库返回的数据类型
    数据库和数据仓库的关系
    distinct 用法
    Hbase学习
    顺序访问数据和随机访问数据
  • 原文地址:https://www.cnblogs.com/buro79xxd/p/1682574.html
Copyright © 2011-2022 走看看