I want to setup Lighty with PHP to use 3 different domain names on my development environment:
I've installed PHP 5.4 and Lighty using Homebrew and my goal is to have a Rails-like solution for starting/stopping the web server while in development. Essentially, I want:
$ rails s
to behave like:
$ lighttpd -D -f lighttpd.conf
I've got the server running, and pointing to localhost:8000, but some assets don't load correctly due to the fact that some of the assets are prefixed with the above stated domains.
So to my question, how do I correctly configure Lighty with Virtual Hosting with the above stated domains?
Here is my current Lighty config:
server.bind = "0.0.0.0"
server.port = 8000
server.document-root = CWD + "/public"
server.errorlog = CWD + "/lighttpd.error.log"
accesslog.filename = CWD + "/lighttpd.access.log"
index-file.names = (
"index.php",
"index.html",
"index.htm",
"default.htm"
)
server.modules = (
"mod_fastcgi",
"mod_accesslog",
"mod_rewrite"
)
fastcgi.server = (
".php" => ((
"bin-path" => "/usr/local/bin/php-cgi",
"socket" => CWD + "/php5.socket"
))
)
mimetype.assign = (
".css" => "text/css",
".gif" => "image/gif",
".htm" => "text/html",
".html" => "text/html",
".jpeg" => "image/jpeg",
".jpg" => "image/jpeg",
".js" => "text/javascript",
".png" => "image/png",
".swf" => "application/x-shockwave-flash",
".txt" => "text/plain"
)
# Making sure file uploads above 64k always work when using IE or Safari
# For more information, see http://trac.lighttpd.net/trac/ticket/360
$HTTP["useragent"] =~ "^(.*MSIE.*)|(.*AppleWebKit.*)$" {
server.max-keep-alive-requests = 0
}
# Vhost settings
$HTTP["host"] =~ "example[0-9]+.domain.com" {
server.document-root = CWD + "/public"
server.errorlog = CWD + "/lighttpd.error.log"
accesslog.filename = CWD + "/lighttpd.access.log"
}
You don't need to configure any virtual hosts if they are all using the same settings as the primary server config. You should just be able to add the domains to your hosts file so they get directed to back to your computer instead of out to the real domain.com. In /etc/hosts on mac and linux or C:\Windows\System32\drivers\etc\hosts on windows add:
127.0.0.1 example1.domain.com
127.0.0.1 example2.domain.com
127.0.0.1 example3.domain.com
I have 2 ideas, you could use something like mod_simple_vhost
or set root document directory in the main config.
So, something like:
$HTTP["host"] =~ "^example([0-9])\.domain\.com$" {
server.document-root = CWD + "/example%1/"
}
or use mod_simple_vhost
, here's an example config:
server.modules += ( "mod_simple_vhost" )
simple-vhost.server-root = CWD + "/"
simple-vhost.document-root = $HTTP["host"] + "/"
simple-vhost.default-host = "domain.com"
That will put the pages for, say, example1.domain.com
at /CWD/example1.domain.com/
. If that doesn't work, try simple-vhost.document-root = CWD + "/" + $HTTP["host"] + "/"
instead.
Although, if you're having DNS problems, either edit the hosts file and add the domains, or configure your nameserver.