MyRaspberryAndMe

Tinkering with Raspberry (and other things)

Owncloud 6 + lighttpd 1.4.31 + Raspberry Pi (Wheezy)

5 Comments

This workaround patches lighttpd to “understand” the HTTP_PATCH method so Owncloud 6 can be used on a Raspberry Pi running Wheezy.

I am using a dedicated Raspberry Pi with Owncloud and lighttpd for my contatcs and calendar entries. This works fine with Android (with the cardDAVSync and calDAVSync apps) and out of the box with any iOS devices using caldav and carddav.

Recently I upgraded from Owncloud 5 to version 6, mostly because I wanted the new automatic birthday calendar feature. Then I realized that I was not able to change any entries. Creating and deleting entries worked fine, only updating/changing was affected. After some digging around I found an entry in the owncloud forums and a short remark in the installation instructions (for version 5. Not in the version 6 instructions…) reading:

Note for Lighttpd users on Debian stable (wheezy):
Recent versions of Owncloud make use of the HTTP PATCH feature, which was 
added to Lighttpd at version 1.4.32 while Debian stable only ships 1.4.31.
The patch is simple, however, and easy to integrate if you’re willing to 
build your own package.

There are instructions for patching lighttpd on Debian so I thought that this should work on the Raspberry Pi also. Well, it did not. I ended up with a completely screwed system and (even worse) an incompatible libc-version which made some more fiddling necessary. I cannot guarantee that I didn’t something wrong, but I found a workaround that is working flawlessly on my system.

This workaround involves some modifications to source files and building a debian install package. It also assumes that you have a working and properly configured lighttpd and Owncloud installation on your system! If you have never compiled/built software on a linux machine please be warned. I can not be held responsible if anything goes wrong and you end up with a non-working Raspberry Pi. That said, here’s what we are going to do:

  • make backups of all lighttpd configuration files
  • get the lighttpd 1.4.31 sources and patch them
  • build a .deb-package from the source
  • install patched lighttpd package over existing installation using dpkg
  • copy some missing files from saved backup to new locations

If you are still with me at this point, keep on reading…

Preparing the system

I strongly recommend testing this on a spare Raspberry Pi and not the “productive system” you may use with Owncloud. The .deb-Package we are creating can be installed on any Raspberry Pi, so if everything works there is no time lost. And, of course, I assume you are using a terminal, not the x-window system.

We need some tools and source files to build a package. Therefore check that in your /etc/apt/sources.list file you have the following entries:

deb http://mirrordirector.raspbian.org/raspbian/ wheezy main contrib non-free rpi
deb-src http://archive.raspbian.org/raspbian wheezy main contrib non-free rpi

If you need to add the second line you need to run sudo apt-get update afterwards and it may be a good idea to do a sudo apt-get upgrade as well. Now it’s time to get the packages needed for building our own version of lighttpd. Type in

sudo apt-get build-dep lighttpd
sudo apt-get install checkinstall

The first command will install all things needed to build lighttpd from source and the second one will install checkinstall, a neat little helper that creates debian-packages from source files.

Backing up files

As I said in the beginning, this guide assumes you have a working and thoroughly tested lighttpd installation running. So the files we are backing up should exist.

Change to your home directory and create a new directory where you will be working in:

cd
mkdir Working
mkdir Working/Backups
cd Working/Backups

The configuration of your lighttpd installation is located at /etc/lighttpd/, so we copy the whole directory into Backups and then rename the directory to indicate where the files came from:

cp -r /etc/lighttpd/ ./
mv lighttpd/ etc_lighttpd/

The next step is to locate some perl scripts that lighttpd uses. The patched version will complain about these files missing, even if called with the correct lighttpd.conf file. I have no idea why they got lost during installation of the patched version, but again, this workaround is definitely not the cleanest way to handle things… To locate these files we use the “find” command. If you know where these files are located skip the find command:

cd /
sudo find -name use-ipv6.pl

This should give you the location of a directory. Change to that directory and make sure that the following files can be found there:

-rwxr-xr-x 1 root root 461 Feb 4 12:05 create-mime.assign.pl
-rwxr-xr-x 1 root root 241 Feb 4 12:04 include-conf-enabled.pl
-rw-r--r-- 1 root root 3585 Feb 4 12:05 index.html
-rwxr-xr-x 1 root root 247 Feb 4 12:05 use-ipv6.pl

Make a subdirectory in your Backups-directory that indicates the source-location of the above files. So if you found the files in /usr/share/lighttpd:

cd ~/Working/Backups
mkdir usr_share_lighttpd
cd usr_share_lighttpd
cp /usr/share/lighttpd/* ./

If you do not have these files you can copy them from the source-package later.

For now, go back to your backup directory and, last but not least and for safety only, copy the script that is used to start/stop/restart lighttpd to the backup directory:

cd ~/Working/Backups/
cp /etc/init.d/lighttpd etc_initd_lighttpd

Check and double-check that all copied files are there! Make notes where you copied which file from. Remember to properly rename them in case you need to copy them back to their original locations!

Getting the source and patch lighttpd

Instead of patching and building the already installed lighttpd version 1.4.31 we could get the most actual version and build that. I decided against doing so, because if a new version of lighttpd (greater 1.4.31) is rolled out in the Raspberry Pi repository I want to be able to install that version with the usual apt-get sequence. If we were to install a higher version now, this would not work.

So for now, get the source directly from the lighttpd website. Just copy the link location and use wget on the Raspberry Pi to copy the tarball into the “Working” directory and unpack it:

wget http://download.lighttpd.net/lighttpd/releases-1.4.x/lighttpd-1.4.31.tar.gz
tar -xvf lighttpd-1.4.31.tar.gz

You should now have a directory named “lighttpd-1.4.31” under the working directory. Time to take a look at the patch. You may also download the patch from http://redmine.lighttpd.net/attachments/download/1370/patch.patch and take a look at it in any text editor. We do not need the file itself, just the instructions what to patch. This is what the file looks like:

diff --git a/src/connections.c b/src/connections.c
index faec09f..9136e52 100644
--- a/src/connections.c
+++ b/src/connections.c
@@ -420,6 +420,7 @@ static int connection_handle_write_prepare(server *srv, connection *con) {
 		case HTTP_METHOD_POST:
 		case HTTP_METHOD_HEAD:
 		case HTTP_METHOD_PUT:
+		case HTTP_METHOD_PATCH:
 		case HTTP_METHOD_MKCOL:
 		case HTTP_METHOD_DELETE:
 		case HTTP_METHOD_COPY:
diff --git a/src/keyvalue.c b/src/keyvalue.c
index 8ca739b..ba37611 100644
--- a/src/keyvalue.c
+++ b/src/keyvalue.c
@@ -22,6 +22,7 @@ static keyvalue http_methods[] = {
 	{ HTTP_METHOD_OPTIONS, "OPTIONS" },
 	{ HTTP_METHOD_MKCOL, "MKCOL" },
 	{ HTTP_METHOD_PUT, "PUT" },
+	{ HTTP_METHOD_PATCH, "PATCH" },
 	{ HTTP_METHOD_DELETE, "DELETE" },
 	{ HTTP_METHOD_COPY, "COPY" },
 	{ HTTP_METHOD_MOVE, "MOVE" },
diff --git a/src/keyvalue.h b/src/keyvalue.h
index 209b2cf..43ef99b 100644
--- a/src/keyvalue.h
+++ b/src/keyvalue.h
@@ -20,6 +20,7 @@ typedef enum {
 	HTTP_METHOD_PROPFIND,  /* WebDAV */
 	HTTP_METHOD_MKCOL,
 	HTTP_METHOD_PUT,
+	HTTP_METHOD_PATCH,
 	HTTP_METHOD_DELETE,
 	HTTP_METHOD_COPY,
 	HTTP_METHOD_MOVE,

This diff-file tells us everything we need to know. I’m going to briefly explain the first paragraph so you get an idea of the syntax and meaning.

  • The line starting with diff tells us that there is some difference in a file named src/connections.c
  • The line starting with @@ explains where: around line 420, in method static int connection_handle_write_prepare(…)
  • The line starting with + shows what and where to add it: add “case HTTP_METHOD_PATCH:” right after “case HTTP_METHOD:PUT:”

The other two files affected are src/keyvalue.c and src/keyvalue.h. So all we need to do is edit these files, add the lines as described in the patch and we are good to go. If you feel uncomfortable editing source files or you do not know how to use an editor on your Raspberry Pi you should stop here. Seriously.

Fire up your preferred editor, navigate to the location given in the diff-file and add those lines. The line numbers are not absolutely correct, but you will find the location at +/- 5 lines.

Maybe you are as startled as I have been when looking at the patch. There is no “logic” added, just a case statement and the list of known methods. Well, that’s enough because the webserver is not dealing with those HTTP_METHODs, it just needs to know what methods to pass to the backend (web application). By adding “HTTP_PATCH” the server will now pass these requests instead of reporting an error to the calling page.

Now we have patched the sources. The next step is to build the binaries.

Building the package

This is where the fun starts. Again, if you have never used configure and make be warned. You may encounter errors you can’t deal with and/or end up with a corrupted system. So continue at your own risk.

Usually things (binary, libs etc.) are installed under /usr/local/, however, on the Raspberry Pi the path is just /usr/, so lighttpd is located in /usr/sbin, the libs in /usr/lib/lighttpd etc. This means we need to run the configure script with directives that change the default location. Additionally I am using a SSL connection to access my Owncloud machine, so I am adding the directive for including SSL.

Normally I can configure and prepare make without being root (make install usually does need root). On my Raspberry Pi I recognized that I need to run all the building steps with sudo. This did not affect anything on my system.

You should change into the directory where the lighttpd source package was extracted to. Then we start the configure script with the correct directives:

cd ~/Working/lighttpd-1.4.31
./configure --prefix=/usr --libdir=/usr/lib/lighttpd --libexecdir=/usr/lib --localstatedir=/var --with-openssl
make

This will take some time. You should not get any errors. If any of the commands is complaining about directories or files not accessible, try to run the commands with sudo. After configure and make did run without any errors we can now build a debian install package (.deb). The tool checkinstall will do this for us (it runs make install, creates a .deb-package and installs the package on the system):

sudo checkinstall

You will be prompted for some information. Checkinstall is going to complain that there is no doc-pak directory (you may ignore this and opt not to create a default package doc). More important is the version information you can supply with your package. I chose to stick with the version number 1.4.31, but to add an identifier: “1.4.31sp” (s for ssl, p for patched). That way if a version 1.4.32 (or higher) is deployed to the Raspberry Pi repositories, apt-get upgrade should work as intended an update the patched package.

Checkinstall will ask you for a package description (lighttpd-1.4.31_patched) and then show you a screen with options. Here’s a screenshot with my settings:

checkinstall-settings

When checkinstall has finished the lighttpd package should be installed on your system. And a file named “lighttpd-1.4.31sp_armhf.deb” (or similar) should have been created in the directory you are currently in. To check if there occur any errors we are going to stop and restart the webserver:

sudo /etc/init.d/lighttpd stop
sudo /etc/init.d/lighttpd start

Troubleshooting

Most likely lighttpd will complain that some files are missing in /usr/share/lighttpd. This is why we made a backup copy of these files. Just copy them back to /usr/share/lighttpd (as root) and try to start the webserver again. This time everything should work fine (it did on my machine) and you should be able to access the Raspberry Pi from any browser.

If nothing happens (no error message, no server start) let’s check if lighttpd has been installed and check the error log:

which lighttpd

should give you /usr/sbin/lighttpd as a response. You may also try

dpkg -l lighttpd

This should output the following lines:

Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                             Version               Architecture          Description
+++-================================-=====================-=====================-==========================
ii  lighttpd                         1.4.31ps-1            armhf                 lighttpd-1.4.31_patched

The next step is to check if there are any entries in the error logs (/var/log). Some things to check:

  • lighttpd config files present (we made a backup of them)
  • file permissions (is lighttpd executable)

In case lighttpd has not been installed we are going to do this with the debian package manager:

sudo dpkg -i lighttpd-1.4.31sp_armhf.deb

Then stop/start lighttpd to check for errors.

Again: This steps all worked for me. The patched version of lighttpd is running on my Raspberry Pi happily with Owncloud, I am able to access it via SSL from any of my devices. I do not get any errors in lighttpd’s error.log. There is no guarantee that this will or may work on your machine. I am not reliable for any damages on your systems.

If everything went fine you can now use Owncloud 6 with lighttpd and even change/modify addressbook entries and calendar entries. You can even copy the .deb-file to another Raspberry Pi and use “dpkg -i filename” to install it there.

Advertisements

5 thoughts on “Owncloud 6 + lighttpd 1.4.31 + Raspberry Pi (Wheezy)

  1. Thanks for your “how to”. I am facing the same problem.
    As you download the sources of lighttpd and compile them, i was wondering why you did not use a more recent version of lighttpd (1.4.34 ? 1.4.33 ?). It should have skip the patch step.

    • Hi.
      Glad I could help you. Why I did not use a current lighttpd source file:
      Instead of patching and building the already installed lighttpd version 1.4.31 we could get the most actual version and build that. I decided against doing so, because if a new version of lighttpd (greater 1.4.31) is rolled out in the Raspberry Pi repository I want to be able to install that version with the usual apt-get sequence. If we were to install a higher version now, this would not work.

  2. Pingback: Owncloud – Good bye (for now) | MyRaspberryAndMe

  3. Thanks for your tutorial. It works like a charm!