Skip to content

Instantly share code, notes, and snippets.

@gboddin
Last active May 17, 2016 14:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gboddin/20a900c2d3c65a3a6615 to your computer and use it in GitHub Desktop.
Save gboddin/20a900c2d3c65a3a6615 to your computer and use it in GitHub Desktop.
drupal_dev_lighttpd
#!/bin/bash
# will start a multithreaded instance of the local installation
# for ubuntu/debian users
# apt-get install lighttpd php5-cgi
echo "Locating php-cgi :"
if which php-cgi; then
php_cgi_path=$(readlink -f `which php-cgi`)
else
exit 1
fi
echo "Locating lighttpd :"
if which lighttpd ; then
lighttpd_path=$(readlink -f `which lighttpd`)
else
exit 1
fi
config_file=$(mktemp -t lighttpd.XXXXXX.conf)
session_dir=$(mktemp -t -d php-sessions.XXXXXX)
document_root=$(pwd)
http_port=$(netstat -atn | perl -0777 -ne '@ports = /tcp.*?\:(\d+)\s+/imsg ; for $port (8000..8888) {if(!grep(/^$port$/, @ports)) { print $port; last } }')
[ ! -z "$1" ] && document_root=$1
[ ! -d "$document_root" ] && echo "$document_root is not a directory" && exit 1
[ ! -z "$2" ] && http_port=$2
echo "Starting ligghttpd server at http://localhost:$http_port ..."
echo "(Hit CTRL+C to interupt)"
echo "Config : ${config_file} - Session dir : ${session_dir}"
document_root=$(readlink -f "$document_root")
cat > $config_file << EOL
server.modules = (
"mod_access",
"mod_alias",
"mod_redirect",
"mod_rewrite",
)
server.document-root = "$document_root"
server.port = $http_port
index-file.names = ( "index.php", "index.html", "index.lighttpd.html" )
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi" )
url.rewrite-if-not-file = ( "^/([^\?]+)(\?(.*))?" => "/index.php?q=\$1&\$3" )
server.modules += ("mod_fastcgi")
fastcgi.server = (
".php" => (
"localhost" => (
"bin-path" => "${php_cgi_path} -d session.save_path=${session_dir}",
"socket" => "$(mktemp -u)",
"broken-scriptfilename" => "enable",
"max-procs" => 5, # default value
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "1" # default value
)
)
)
)
mimetype.assign = (
".pdf" => "application/pdf",
".sig" => "application/pgp-signature",
".spl" => "application/futuresplash",
".class" => "application/octet-stream",
".ps" => "application/postscript",
".torrent" => "application/x-bittorrent",
".dvi" => "application/x-dvi",
".gz" => "application/x-gzip",
".pac" => "application/x-ns-proxy-autoconfig",
".swf" => "application/x-shockwave-flash",
".tar.gz" => "application/x-tgz",
".tgz" => "application/x-tgz",
".tar" => "application/x-tar",
".zip" => "application/zip",
".mp3" => "audio/mpeg",
".m3u" => "audio/x-mpegurl",
".wma" => "audio/x-ms-wma",
".wax" => "audio/x-ms-wax",
".ogg" => "application/ogg",
".wav" => "audio/x-wav",
".gif" => "image/gif",
".jpg" => "image/jpeg",
".jpeg" => "image/jpeg",
".png" => "image/png",
".xbm" => "image/x-xbitmap",
".xpm" => "image/x-xpixmap",
".xwd" => "image/x-xwindowdump",
".css" => "text/css",
".html" => "text/html",
".htm" => "text/html",
".js" => "text/javascript",
".asc" => "text/plain",
".c" => "text/plain",
".cpp" => "text/plain",
".log" => "text/plain",
".conf" => "text/plain",
".text" => "text/plain",
".txt" => "text/plain",
".spec" => "text/plain",
".dtd" => "text/xml",
".xml" => "text/xml",
".mpeg" => "video/mpeg",
".mpg" => "video/mpeg",
".mov" => "video/quicktime",
".qt" => "video/quicktime",
".avi" => "video/x-msvideo",
".asf" => "video/x-ms-asf",
".asx" => "video/x-ms-asf",
".wmv" => "video/x-ms-wmv",
".bz2" => "application/x-bzip",
".tbz" => "application/x-bzip-compressed-tar",
".tar.bz2" => "application/x-bzip-compressed-tar",
".odt" => "application/vnd.oasis.opendocument.text",
".ods" => "application/vnd.oasis.opendocument.spreadsheet",
".odp" => "application/vnd.oasis.opendocument.presentation",
".odg" => "application/vnd.oasis.opendocument.graphics",
".odc" => "application/vnd.oasis.opendocument.chart",
".odf" => "application/vnd.oasis.opendocument.formula",
".odi" => "application/vnd.oasis.opendocument.image",
".odm" => "application/vnd.oasis.opendocument.text-master",
".ott" => "application/vnd.oasis.opendocument.text-template",
".ots" => "application/vnd.oasis.opendocument.spreadsheet-template",
".otp" => "application/vnd.oasis.opendocument.presentation-template",
".otg" => "application/vnd.oasis.opendocument.graphics-template",
".otc" => "application/vnd.oasis.opendocument.chart-template",
".otf" => "application/vnd.oasis.opendocument.formula-template",
".oti" => "application/vnd.oasis.opendocument.image-template",
".oth" => "application/vnd.oasis.opendocument.text-web",
# make the default mime type application/octet-stream.
"" => "application/octet-stream",
)
EOL
${lighttpd_path} -Df $config_file
rm -f $config_file
rm -Rf $session_dir
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment