# lighttpd cannot start



## Beeblebrox (Mar 14, 2011)

I have lighttpd installed instead of Apache, and lighttpd fails to start with message:

```
can't bind to port: 0.0.0.0 80 Address already in use
```
Nothing else is running on :80 and changing the port in lighttpd.conf to something else gives the same message for the changed port.

I tried changing (again in lighttpd.conf) the 0.0.0.0:80 to 127.0.0.1:80.  The service started, but no page shows up in the browser.  Searching for this problem comes up with "enable ipv6"; meaning must use ipv6 to get it to work but that is just ridiculous IMHO, since the config file has ipv6 enable / disable option (disabled for mine), and it was not built with ipv6 anyway.

Another poster suggests that the culprit is a Perl(?) script looking for IPv6 compatibility and that this must be disabled/modified!  My knowledge in these type of applications is very limited at the moment.

And so there you have it...


----------



## anomie (Mar 14, 2011)

Not familiar with lighttpd, but surely you can tell him to listen on a specific, "real" IP (rather than using the loopback, or glomming on to all IPs). Have you tried that?


----------



## DutchDaemon (Mar 15, 2011)

*lighttpd* really does not need IPv6 for anything, and I have it running on loopback addresses and public IPs alike without a problem, also with variations like:


```
server.port                = 81
server.bind                = "192.168.0.1"
```


```
server.port                = 81
server.bind                = "127.0.0.1"
```


```
server.port                = 80
server.bind                = "xxx.xxx.141.204"
```

Make absolutely sure [cmd=]sockstat -l4p80[/cmd] shows nothing before starting *lighttpd*, and/or run the start script with *sh -x* or *sh -xv* to get more verbose results.


----------



## Beeblebrox (Mar 20, 2011)

OK - solved thanks.   I had this line at the very end of lighttpd.conf uncommented, which was unnecessary:

```
# IPv4 listening socket
#$SERVER["socket"] == "127.0.0.1:80" { }
```

FAST-CGI: At startup fast-cgi gives a fail message, but it's looking in the wrong place. For my fastcgi.conf I have:

```
"socket" => socket_dir + "/php-fastcgi-1.socket",
"bin-path" => server_root + "/cgi-bin/php52"
```

EDIT:  Solved fastcgi start:
In lighttpd.conf:

```
var.server_root = "/usr/local"
```
In fastcgi.conf:

```
"bin-path" => server_root + "/bin/php-cgi"
```


----------



## Lonney (May 1, 2013)

Lighttpd still has this issue when installed on FBSD9.1 FreeBSD 9.1 via (up-to-date as of today) ports.

/usr/local/www/data doesn't exist.
I deselected IPv6, yet it was set to enable in the config.
Had to comment out 
	
	



```
$SERVER["socket"] == "0.0.0.0:80" { }
```
 - as mentioned above.
Now lighttpd will start.


----------



## Lonney (May 1, 2013)

Correction 3 _should_ read: Had to comment out 
	
	



```
$SERVER["socket"] == "[color="Red"]0.0.0.0[/color]:80" { }
```
 - as mentioned above.


----------



## paulbeard (Nov 22, 2013)

Lonney said:
			
		

> Lighttpd still has this issue when installed on FBSD9.1 FreeBSD 9.1 via (up-to-date as of today) ports.
> 
> /usr/local/www/data doesn't exist.
> I deselected IPv6, yet it was set to enable in the config.
> ...



I am seeing much the same problem as is just about everyone who tries to use lighttpd. This is a very common problem and the solution seems to be "fix permissions." But to what? 


```
2013-11-21 22:25:40: (log.c.118) opening errorlog '/var/log/lighttpd/lighttpd.error.log' failed: Permission denied
```



```
ls -l /var/log/lighttpd/lighttpd.error.log
-rw-r--r--  1 www  www  0 Nov 21 22:31 /var/log/lighttpd/lighttpd.error.log
ls -l /var/log/
drwx------  2 www     www         512 Nov 21 22:22 lighttpd
```
This is the full configuration file, as simple as I can make it. 

```
server.document-root = "/usr/www"

server.port = 8888

server.username = "www" 
server.groupname = "www" 

mimetype.assign = (
  ".html" => "text/html", 
  ".txt" => "text/plain",
  ".jpg" => "image/jpeg",
  ".png" => "image/png" 
)
static-file.exclude-extensions = ( ".fcgi", ".php", ".rb", "~", ".inc" )
index-file.names = ( "index.html" )

server.errorlog             = "/var/log/lighttpd/lighttpd.error.log"
```

This is pretty frustrating as everything points to lighttpd being easy to use and quick to set up ("just 5-10 minutes!") but it's been quite a bit longer than that. It runs and serves pages but won't log/won't run if I enable logging.


----------



## DutchDaemon (Nov 22, 2013)

Maybe try a less minimal lighttpd.conf. Work with the sample configuration file and adjust for your local setup. If that works, start weeding. For example, you don't have any server.modules loaded, whereas the sample configuration states:


```
## modules to load
# at least mod_access and mod_accesslog should be loaded
# all other module should only be loaded if really neccesary
# - saves some time
# - saves memory
server.modules              = (
#                               "mod_rewrite",
#                               "mod_redirect",
#                               "mod_alias",
                                "mod_access",
#                               "mod_cml",
#                               "mod_trigger_b4_dl",
#                               "mod_auth",
#                               "mod_status",
#                               "mod_setenv",
#                               "mod_fastcgi",
#                               "mod_proxy",
#                               "mod_simple_vhost",
#                               "mod_evhost",
#                               "mod_userdir",
#                               "mod_cgi",
#                               "mod_compress",
#                               "mod_ssi",
#                               "mod_usertrack",
#                               "mod_expire",
#                               "mod_secdownload",
#                               "mod_rrdtool",
                                "mod_accesslog" )
```

That may just be one of the missing directives that cause weird errors elsewhere.


----------



## paulbeard (Nov 22, 2013)

I would expect an error from a missing module to be noted as such, not as a permissions error. And it seems permissions are the problem but I have no idea what they should be. They are the same as used by Apache but lighttpd won't write to a log file in that directory. I can log to /tmp so that works. But that's a special filesystem and also impractical.

I have tried the sample configuration file that is installed as part of the port which does load modules. I don't think modules are the problem. If they are, it seems pretty unclear.



> For example, you don't have any server.modules loaded, whereas the sample configuration states:



But that is for access logging. I'm not there yet. I can't even get error logging to work, as with so many others who try to use lighttpd.

I decided to use the sample config file that comes with the port since it was suggested my skeletal config file might be a problem. This is it, stripped of comments. 


```
var.log_root    = "/var/log/lighttpd"
var.server_root = "/usr/local/www"
var.state_dir   = "/var/run"
var.home_dir    = "/var/spool/lighttpd"
var.conf_dir    = "/usr/local/etc/lighttpd"
var.vhosts_dir  = server_root + "/vhosts"
var.cache_dir   = "/var/cache/lighttpd"
var.socket_dir  = home_dir + "/sockets"
include "modules.conf"
server.port = 8888
server.username  = "www"
server.groupname = "www"
server.document-root = "/usr/local/www/"
server.pid-file = state_dir + "/lighttpd.pid"
server.errorlog             = log_root + "/error.log"
include "conf.d/access_log.conf"
include "conf.d/debug.conf"
server.event-handler = "freebsd-kqueue"
server.network-backend = "writev"
server.max-fds = 2048
server.stat-cache-engine = "simple"
server.max-connections = 1024
index-file.names += (
  "index.xhtml", "index.html", "index.htm", "default.htm", "index.php"
)
url.access-deny             = ( "~", ".inc" )
$HTTP["url"] =~ "\.pdf$" {
  server.range-requests = "disable"
}
static-file.exclude-extensions = ( ".php", ".pl", ".fcgi", ".scgi" )
include "conf.d/mime.conf"
include "conf.d/dirlisting.conf"
server.follow-symlink = "enable"
server.upload-dirs = ( "/var/tmp" )
```

It still gives this error: 

```
2013-11-22 16:09:52: (log.c.118) opening errorlog '/var/log/lighttpd/error.log' failed: Permission denied
```

This is the file it can't open: 

```
-rw-r--r--  1 www  www  508 Nov 22 15:54 /var/log/lighttpd/error.log
```
This is the directory where it is kept:

```
drw-r--r--  2 www     www         512 Nov 22 16:11 lighttpd
```

If anyone can see where the log directory and log file permissions are out of sync, I'd be glad to know about it.


----------



## drhowarddrfine (Nov 23, 2013)

FWIW, I found lighttpd to be extremely frustrating to get going years ago and I recognize the errors you're having. Their forum was also aggravating at best. I'm going to see if I can find my notes on this.


----------



## paulbeard (Nov 23, 2013)

Thank you, @drhowarddrfine. It really seems odd to have such a persistent problem and no documented fix.

I decided to see if I could get it working on OS X and even though I had to install a lot of stuff to _build_ it, I got it running and logging with very little trouble. And the permissions that work look just like the ones that don't on FreeBSD. 

Go figure.


----------



## Beeblebrox (Nov 24, 2013)

For a number of different reasons, I switched to www/nginx some time back. No insights here unfortunately.


----------



## fonz (Nov 24, 2013)

Beeblebrox said:
			
		

> For a number of different reasons, I switched to www/nginx some time back.


Likewise.


----------



## DutchDaemon (Nov 24, 2013)

I'm running about 12 lighttpd instances without problems. FWIW.


----------



## paulbeard (Nov 24, 2013)

Yes, lots of people are running it but a few of aren't _we are seeing the same problem_. The documentation omits any mention of permissions in the log_root directory at install or setup time. But this dates back years. It seems odd to me. The port maintainer says he has never seen an issue with lighttpd he couldn't resolve. So I hope he maintains that record. Next stop, www/nginx.

It might be useful to see what permissions/file ownership look like on a working installation. 

Based on a suggestion made by the maintainer, I commented out the user/group lines in the config and it now runs, serves pages, logs as expected. This does point to permissions but I don't know how it switches user, what happens there. And it runs as root so that's not exactly what we want. I note that apache 2.2 logs to files owned by root even though the process is owned by www. That seems confusing.


----------



## paulbeard (Nov 29, 2013)

I gave up on this. I never heard from the port maintainer and never found a definitive answer so I switched to Nginx. That offered its own challenges but it works.


----------



## michaelmichael (Apr 3, 2016)

Beeblebrox said:


> OK - solved thanks.   I had this line at the very end of lighttpd.conf uncommented, which was unnecessary:
> 
> ```
> # IPv4 listening socket
> ...



Thanks for posting this. This last line in the default lighthttpd.conf was responsible for the strange error message, regardless which IP I specified with 
	
	



```
server.bind = "x.y.z.a"
```


```
root@repo:~ # service lighttpd start
Starting lighttpd.
2016-04-03 17:11:35: (network.c.410) can't bind to port: 0.0.0.0 80 Address already in use
/usr/local/etc/rc.d/lighttpd: WARNING: failed to start lighttpd
```


----------

