Skip to content

Instantly share code, notes, and snippets.

@jbhannah
Created May 23, 2011 04:04
Show Gist options
  • Save jbhannah/986210 to your computer and use it in GitHub Desktop.
Save jbhannah/986210 to your computer and use it in GitHub Desktop.
Drupal multisite, clean URLs, and lighttpd (http://wp.me/pnbL6-2o)
# The following redirects all non-existing subdomains and the "www." prefix to
# the top domain. Change 'sub' below to a vertical-bar (|)-delimited list of
# subdomains.
$HTTP["host"] !~ "^((sub)\.)?example1\.com" {
$HTTP["host"] =~ "^(.+\.)example1\.com" {
url.redirect = ( "^/(.*)" => "http://example1.com/$1" )
}
}
# If you don't have any subdomains you want to be web-accessible, comment out
# the above and uncomment the following:
#$HTTP["host"] =~ "^(.+\.)example1\.com" {
# url.redirect = ( "^/(.*)" => "http://example1.com/$1" )
#}
$HTTP["host"] == "example1.com" {
index-file.names = ( "index.php" )
url.rewrite += ( "^/frontpage$" => "/" )
# A couple examples of rewrite rules
# url.rewrite += ( "^/story/[0-9]{4}/[0-9]{2}/[0-9]{2}/(.*)$" => "/blog/$1" )
# url.rewrite += ( "^/archive/([0-9]{4})([0-9]{2})$" => "/archive/$1/$2" )
# Change /etc/lighttpd to the path of the drupal.lua file
magnet.attract-physical-path-to = ( "/etc/lighttpd/drupal.lua" )
}
#!/bin/sh
# /usr/local/bin/drupal-install-mod.sh
# Downloads and extracts a Drupal module to the Drupal sites/all/modules
# directory.
# Copyright (C) 2008 Jesse B. Hannah (http://jbhannah.net) <[email protected]>
# Available under the GNU General Public License
# http://www.gnu.org/licenses/gpl.html
# Must run as root or sudo!
if [ "$(id -u)" != "0" ]; then
echo "Must be run as root!"
exit 1
fi
if [ "$1" == "" ]; then
echo "Usage: drupal-install-mod NAME-N.n-VERSION"
exit 1
fi
cd /var/www/drupal-sites/all/modules
wget http://ftp.drupal.org/files/projects/$1.tar.gz
tar xzf *.gz
rm *.gz
#!/bin/sh
# /usr/local/bin/drupal-upgrade.sh
# Upgrades from one Drupal version to a newer one.
# Copyright (C) 2008 Jesse B. Hannah (http://jbhannah.net) <[email protected]>
# Available under the GNU General Public License version 3 or later
# http://www.gnu.org/licenses/gpl.html
# Must run as root or sudo!
if [ "$(id -u)" != "0" ]; then
echo "Must be run as root!"
exit 1
fi
# SAFETY! BACK UP /var/www BEFORE BEGINNING!
cd /var
tar cjf www-`date +%Y%m%d`-`date +%H%M`.tar.bz2 www
# First argument: old version; second argument: new version (both X.x)
OLD=$1
NEW=$2
# Get and unpackage the new version and get rid of the package
cd /var/www
wget http://ftp.osuosl.org/pub/drupal/files/projects/drupal-${NEW}.tar.gz
tar xzf drupal-${NEW}.tar.gz
rm drupal-${NEW}.tar.gz
# symlink to sites directory
cd drupal-${NEW}
rm -rf sites
ln -s /var/www/drupal-sites sites
# symlink to ImageMagick
cd includes
ln -s /var/www/drupal-sites/all/modules/image/image.imagemagick.inc
# Update /var/www/drupal symlink and remove old folder
cd /var/www
rm drupal
ln -s drupal-${NEW} drupal
rm -rf drupal-${OLD}
-- /etc/lighttpd/drupal.lua
-- Based on http://www.morphir.com/Lighttpd-Install-and-configuration-for-Drupal-with-clean-url
-- little helper function
function file_exists(path)
local attr = lighty.stat(path)
if (attr) then
return true
else
return false
end
end
function removePrefix(str, prefix)
return str:sub(1,#prefix+1) == prefix.."/" and str:sub(#prefix+2)
end
-- prefix without the trailing slash
local prefix = ''
-- the magic
if (not file_exists(lighty.env["physical.path"])) then
-- file still missing. pass it to the fastcgi backend
request_uri = removePrefix(lighty.env["uri.path"], prefix)
if request_uri then
lighty.env["uri.path"] = prefix .. "/index.php"
local uriquery = lighty.env["uri.query"] or ""
lighty.env["uri.query"] = uriquery .. (uriquery ~= "" and "&" or "") .. "q=" .. request_uri
lighty.env["physical.rel-path"] = lighty.env["uri.path"]
lighty.env["request.orig-uri"] = lighty.env["request.uri"]
lighty.env["physical.path"] = lighty.env["physical.doc-root"] .. lighty.env["physical.rel-path"]
end
end
-- fallthrough will put it back into the lighty request loop
-- that means we get the 304 handling for free. ;)
/var
|- www
|- drupal -> drupal-6.3
|- drupal-6.3
| ...
|- includes
| ...
|- image.imagemagick.inc -> /var/www/drupal-sites/all/modules/image/image.imagemagick.inc
| ...
| ...
|- sites -> /var/www/drupal-sites
| ...
|- drupal-sites
|- all
|- modules
|- themes
|- default
|- example1.com -> /var/www/example1.com/drupal
|- example2.com -> /var/www/example2.com/drupal
|- example1.com
|- drupal
|- files
|- htdocs -> /var/www/drupal
|- sub
|- htdocs
|- example2.com
|- drupal
|- files
|- htdocs -> /var/www/drupal
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment