Showing posts with label apache. Show all posts
Showing posts with label apache. Show all posts

Apache: Syntax error on line 33 of <conf_file>: Name duplicates previous WSGI daemon definition.

It's likely in your vhost conf file that you've got the same daemon process already defined somewhere.

WSGIDaemonProcess  twig processes=10 threads=3 display-name=%{GROUP}

Ensure that "twig" part is UNIQUE by renaming it to something more project specific.

Source

Apache: Run a Django project using mod_wsgi and .htaccess

To get Django up and running under your Apache configuration, you'll need to install mod_wsgi first. This will let Apache run Python code.

Assuming your files are in the format of:

image

For this example, the "forum" folder is the subdomain (http://forum.example.com) and the "forum_project" should be your Django project folder (containing manage.py, settings.py, etc).

In your subdomain folder, create a file called "dispatch.wsgi". This file will tell Apache what to do with the incoming request. In that file, paste:

import os, sys

sys.path.append("/home/twig/public_html/forum/forum_project");

# This refers to the "settings.py" file in forum_project
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

#import django.core.handlers.wsgi
#application = django.core.handlers.wsgi.WSGIHandler()

def application(environ, start_response):
"""Simplest possible application object"""
output = "Hello World"
status = '200 OK'
response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))]
start_response(status, response_headers)
return [output]

Now to create a file called ".htaccess", which will funnel all the URLs into dispatch.wsgi.

RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteRule ^(dispatch\.wsgi/.*)$ - [L]
RewriteRule ^(.*)$ slowpoke/dispatch.wsgi/$1 [QSA,PT,L]

Lastly, add a few lines in your domain's vhost file so it knows to use Python and WSGI for requests.

<IfModule mod_wsgi.c>
WSGIScriptAlias / /home/twig/public_html/forum/dispatch.wsgi
WSGIDaemonProcess myapp processes=5 threads=1 display-name=%{GROUP}
WSGIProcessGroup myapp
WSGIApplicationGroup %{GLOBAL}
</IfModule>

Time to test the server. Open up the browser and point it to your domain. It should display "Hello world". If not, check your error logs. A useful guide to debugging WSGI errors is available on the mod_wsgi documentation pages.

Once its up and running, uncomment the Django wsgi code and delete the application() function from dispatch.wsgi. Your code should now look like this.

import os, sys

sys.path.append("/home/twig/public_html/forum/forum_project");

# This refers to the "settings.py" file in forum_project
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'

import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()

That should be enough to get your project up and running with Apache, Django and mod_wsgi.

See here to serve CSS/JS/image files out of Django. For anything else Django related see here.

Sources

Using Drupal API in your website

(If you're looking for a way to bootstrap your automated/scheduled scripts, then look here. This guide is for bootstrapping Drupal to pages loaded by your browser.)

As this is written for Drupal 6.8, instructions may vary for other versions (5.x, 7.x, etc).

Download Drupal and extract files into /path/to/website/drupal

1. Installation
Install Drupal by visiting http://domain/drupal/install.php in your browser.
Ensure no table name conflicts with existing site (ie. any tables named "users", "files" or "access")

2. Bootstrapping the Drupal API
[ source ]
This allows full access to Drupal API from without your website.

The following code is a modified version of ceejayoz's script bootstrap code.

/**
* Allows us access into Drupal's API.
*/
function initialise_drupal_bootstrap() {
// Determine Drupal's directory
$DRUPALINC = realpath('./drupal');

// Adjust PHP's include path so Drupal properly includes it's dependencies
$paths = explode(';', get_include_path());
$paths[] = realpath('./');
$paths[] = $DRUPALINC;
set_include_path(implode(';', $paths));

// Save current working directory
$cwd = getcwd();
chdir($DRUPALINC);

// Call Drupal's bootstrapping code
require_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);

// restore error reporting to its normal setting
error_reporting(E_ALL);
}

Whenever you need to enable the Drupal API on a page, simply call initialise_drupal_bootstrap().

3. Edit .htaccess
This step is optional for Linux users, as you can simply create a symlink to the paths required.

Copy "/path/to/website/drupal/.htaccess" to "/path/to/website/" and open it up in a text editor.
Uncomment the line with "RewriteBase" and set it to "RewriteBase /drupal"

4. Test
  • Open your main page, it should show your original site. (ie. http://www.domain.com)
  • Attempt to access a Drupal rendered page, such as your user profile page at "http://www.domain.com/user"
  • View the Drupal main page, at "http://www.domain.com/drupal"

5. Configure
Log in as the administrator and view the page "http://www.domain.com/admin/settings/site-information" to set up your default front page.

Getting Drupal 6 Clean URLs to work with Apache 2

1. Global configuration (httpd.conf)
Search for
#
# This should be changed to whatever you set DocumentRoot to.
#

and change "AllowOverride None" to "AllowOverride All".

You now have the option to load the "rewrite_module" globally (for all sites) or just a specific vhost.

2. a) Load module globally (httpd.conf)
Search for "#LoadModule rewrite_module modules/mod_rewrite.so" and uncomment it.

2. b) Per virtual host (conf/extra/httpd-vhosts.conf)
Search for your vhost and add "LoadModule rewrite_module modules/mod_rewrite.so".

3. Test settings (
http://server.url/admin/settings/clean-urls)
Restart your Apache server and test the settings.
 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog