Django PostgreSQL Apache
xxdxxd
|
1#
xxdxxd 发表于 2008-10-16 17:58
Django PostgreSQL Apache
1.准备:
$ sudo apt-get install python-psycopg2 python-psycopg postgresql-8.2 postgresql-client-8.2 apache2 libapache2-mod-python subversion pgadmin3 pgadmin3-data [color="#990000"]Django: —————— $ mkdir Web;cd WebWeb$ svn co http://code.djangoproject.com/svn/django/trunk/ django_src 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 [color="#990000"]Apache: —————— $ 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 osmrc-test-suite /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 vern $sudo gedit /etc/postgresql/8.2/main/postgresql.conf CHANGE #listen_addresses = ‘localhost’ to listen_addresses = ‘*’ AND #password_encryption = on to password_encryption = on $ sudo gedit /etc/postgresql/8.2/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 # (autovacuum, daily cronjob, replication, and similar tasks). # # Database administrative login by UNIX sockets 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.2 restart $ cd Web/django_projects/osmrc_test_suite/ /Web/django_projects/osmrc_test_suite$ gedit settings.py # Django settings for osmrc_test_suite project. DEBUG = True #turn this off for a production site TEMPLATE_DEBUG = DEBUG ADMINS = ( (’Ian Lawrence’, ‘root@ianlawrence.info’), ) 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/ian/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/ian/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’, ‘osmrc_test_suite.lkrt’ ) /Web/django_projects/osmrc_test_suite$ django-admin.py syncdb /Web/django_projects/osmrc_test_suite$ gedit urls.py # Uncomment this for admin: (r’^admin/’, include(’django.contrib.admin.urls’)), Configure Apache and mod_python: ——————————– /Web/django_projects/osmrc_test_suite$ sudo gedit /etc/apache2/httpd.conf MaxRequestsPerChild 1 SetHandler python-program PythonHandler django.core.handlers.modpython SetEnv DJANGO_SETTINGS_MODULE osmrc_test_suite.settings PythonPath “['/home/ian/Web/django_projects'] + sys.path” PythonDebug On SetHandler None SetHandler None SetHandler None Reference:http://ianlawrence.info/random-stuff/set-up-django-apache-and-postgresql-on-ubuntu-feisty |