UPDATE: I've updated this guide, and turned it into a pretty long video on YouTube which you can access at this link.
What is OwnCloud? In a nutshell: It is like DropBox, but self-hosted. If your main use case for DropBox is just to have your own, personal, storage in the cloud, then you might find OwnCloud to be a useful alternative. Or, maybe it's just epeen to have one. Either way, it's pretty sweet, and installing it is quite educational. You can always delete it later if you don't have a use case. This guide will take you 30-45 minutes to complete.
EDIT: Please see the comments below this post, especially this one. There are more ways to install OwnCloud, to say nothing of its web serving/database stack, than I can possibly count. And I use the word "definitive", in the title, as sort of a joke on this fact.
There are a bunch of decent guides out there for installing OwnCloud. Unfortunately, I didn't like any of them, because they all seem to suffer from one or more of the following:
- Just robotic, mystical, instructions, with no learning value. (If you want things to "just work", then buy a Macintoaster.)
- Actual errors, or very sub-optimal choices for FreeNAS install scenarios.
- A desire to proselytize for people's favorite stack permutations (we don't need forks of MySQL for a stupid OwnCloud guys, come on!).
But "whoa whoa whoa DrKK" you're saying. OwnCloud has a pbi plugin on FreeNAS. Why not just use that? Well, OK. It..."works". But it's not an ideal configuration, it's not an efficient configuration in some peoples' view (I don't know, I haven't tried it), it's not easy to upgrade, and it's certainly not very educational, and some people have had problems. It's really a crutch for people without enough skill and drive to do these things themselves, and accordingly, it's bad for the epeen.
I am offering below a process that I've wasted my whole weekend on honing for everyone to use, that should--thanks to about 20 iterations of me reworking it--take about 30 minutes to get your OwnCloud up and running on your FreeNAS (or, FreeBSD proper, subject to modification of the instructions). I'm going for the following:
- Reasonably minimal memory and disk requirements.
- We use a standard jail and the FreeNAS warden -- we will not be touching the FreeNAS appliance.
- We'll use pre-built packages -- compiling from ports was...interesting. It is possible to do, but there are several gotcha's with some pretty esoteric things, like the event handlers, and I just figure you can't be bothered.
- Light use case.
- SSL-enabled, in case you want to open it up to the WAN.
- You can use the WebGUI for OwnCloud, or the various DAV or dev clients, on files of any size, up to a few GB.
- Just enough comments sprinkled through as to what's going on so that the process of installing it is at least mildly educational (that's why we're using FreeBSD, right?).
Assumptions:
- You are familiar with Linux/UNIX-style basic commands and file system. i.e., I can say "go up to the parent directory and check the permissions on file x" and you know what I am saying.
- I will use the IP address http://192.168.1.200/ to designate our OwnCloud jail. Yours will vary, of course, and you are to use the correct one, obviously, for your installation.
- You will be creating a jail whose only purpose is to serve OwnCloud. Accordingly, the way I have you do this makes OwnCloud the "root" of your web server, so you will enter http://192.168.1.200/, and not http://192.168.1.200/owncloud/ (and, you will likewise suppress the 'owncloud' in any third-party WebDAV client that you use).
- FreeNAS 9.2.0 or newer (if you are older than this, there will some things--like accessing the jail command line from the GUI--that you can't do, so you'll have to work around that).
Let's get started, shall we? Those using FreeBSD itself (and not FreeNAS) need not necessarily create any jail. Skip ahead as needed.
1. Create a Standard Jail
Go into the Jails dialogue to create a new jail. (If you have never created a jail before, you'll need to set your jail root and so on. See the
FreeNAS docs.) Make sure you create a
standard jail type, and uncheck the buttons for "vanilla", "vimage", and "NAT". You don't need any of that. Note the IPv4 address your jail is assigned. At the risk of ambiguity in this guide, I named my jail "owncloud".
2. Setup SSH.
Out of the box, the ssh and sshd config in new jails isn't convenient. We need ssh working well because we have some files to edit and what not. Even though this isn't strictly the "right way" to proceed, I just save myself a lot of trouble by ssh'ing into my
main FreeNAS command line, and copying over the entire ssh config from that (which is set up the way I, and presumably you, like it) directly into the jail directory (from the FreeNAS appliance, you can get to any jail directories you want--just not vice versa). My jails root is in /mnt/ssd/jails/, and so my call looks like this:
Code:
[root@freenas] ~# cp /etc/ssh/* /mnt/ssd/jails/owncloud/etc/ssh/
In the above, the "owncloud" in the directory is the
name of the jail from step 1.
Now, (assuming you're on at least FreeNAS 9.2.0, you can do this right in the GUI), access the command line of your owncloud jail, and perform the following steps:
- type passwd to set up your root password in the jail.
- type service sshd onerestart to actually enable the ssh service.
You're probably going to get a bunch of warnings about services_ssh. It's fine. This part is only for our convenience during install--we'll turn off ssh later.
3. Update pkg, and Get a Text Editor.
Now, log into your jail's IP with your ssh client (putty, whatever), and:
Code:
pkg update
pkg install nano
These two commands should not take very long at all.
nano is your basic text editor. If you are newer than 9.2, then pkg update will probably ask you if you want to install it. Do so. It may ask you to type pkg2ng. Just go ahead and do that...if you don't need it, it won't hurt anything.
4. Update pkg.conf and Prepare to Get Software
This is not strictly necessary, the part I mark below as OPTIONAL. Some people with 9.2.1.3 had problems when they did the optional part. So don't do it unless you turn out to need it:
(((BEGIN OPTIONAL)))
Edit your pkg.conf file by typing:
Code:
nano /usr/local/etc/pkg.conf
and changing it to these three lines, which will be very similar to what's already in there (you'll be stripping off the reference to FreeNAS, for example):
Code:
PACKAGESITE: http://pkg.cdn.pcbsd.org/9.1-RELEASE/amd64
PUBKEY: /usr/local/etc/pkg-pubkey.cert
PKG_CACHEDIR: /usr/local/tmp
You may have some other lines (MIRROR for example). Just delete those. You only need these three lines.
Having done this, let's bring ourselves up-to-date with this repository by again typing
(((END OPTIONAL)))
and then typing
This should update the pkg software itself.
Type the exact same thing, a second time!
This may now update several built-in packages. In my case, 14 software packages were brought current--for some people on 9.2.1.3, nothing happened. If you type it again a third time, you should see no new updates. Good!
5. Time to Get OwnCloud!
We're now going to get the OwnCloud code, and the dependencies it requires in the pkg's repository. This will download about 50 things, and my research indicates that many of these are not strictly necessary---but who cares.
Code:
pkg install owncloud
It might take a minute or two to fetch and install everything.
EDIT: Please see the additional posts below this one. As of this writing, we've discovered that we're getting OwnCloud scripts that are about 6 months old. It is better to get the latest versions. There are instructions below referring you to Joshua's OwnCloud guide (elsewhere in this forum), and other pointers that you'll want. YOU MAY NOT WANT TO OBEY THIS STEP AS WRITTEN!
6. Get Lightweight Web Server
This is where we sort of get into personal taste. OwnCloud, at its most fundamental level, is nothing but instructions
for a web server to serve content (in this regard, it is similar to the GUI in FreeNAS). Accordingly, it needs a web server to be installed to communicate with. OwnCloud "comes with"
apache in the repository for this purpose (and that's what you get with the FreeNAS pbi if you use it). But, one can argue, this is a lot like using an
M242 to shoot squirrels, or using a school bus to drive to work. It's a bit heavy. Your FreeNAS Web GUI uses something lighter, called
nginx for this purpose--famously, it is said (paraphrasing) that "while apache does 1000 different things, nginx only does, say, 5--and it does 4 of those fifty times faster than apache". I'm going to suggest we go even lighter still, and use what's called
lighttpd, i.e., "lighty".
lighttpd is pretty bad ass, even though it is quite simple, and, for example, serves wikimedia and YouTube pages (or at least did---not sure if it still does).
Code:
pkg install lighttpd
and might as well do this to clean up:
.
Congratulations--at this point, you have all the software in your jail that you'll need. Now, we're down to configuration. Which, alas, is a bit of a pain in the ass. By the way, your jail is probably about 600MB in size now, and we're done downloading software. That isn't bad.
OK, let's do it. This is where I assume you understand basic navigation in a Linux/UNIX environment.
7. Basic lighttpd Configuration
Begin editing the webserver configuration file:
Code:
nano /usr/local/etc/lighttpd/lighttpd.conf
and make, and save, the following changes:
- Change the server root, by locating the server.document-root line, and setting it to
Code:
server.document-root = "/usr/local/www/owncloud/"
- (IMPORTANT) The compiled pkg of lighttpd was compiled without IPv6 support (odd--especially since IPv6 support is the lighttpd config default), (EDIT: now that I've thought about it some more, I don't know if maybe it's the fact that I didn't configure IPv6 in the jail or the FreeNAS? Either way, this hasn't been a problem in the past when I've installed other webservers, so I don't actually know what the issue is with IPv6 for my install---just take it out to be safe) so you will/may have to take it out. Locate the line that says server.use-ipv6 = "enable" and "comment it out", by placing a "#" in front, like so:
Code:
#server.use-ipv6 = "enable"
- Also, comment out the line (probably the last line in the file) that sets up an IPv4 listening socket on port 80, again, by placing the hash "#" mark:
Code:
# IPv4 listening socket
# $SERVER["socket"] == "0.0.0.0:80" { }
This one took me quite a while to track down--it turns out for reasons that I don't particularly understand, lighttpd will open this socket ANYWAY, so if you specifically ask for it to be opened, you will get a "0.0.0.0:80 could not open socket, socket already opened" (or something like that) error.
- Also, you may (optional) want to lower the settings for server.max-fds and/or server.max-connections. I use 256 and 128, respectively. You could go lower. But the defaults are much, much, much, much too high for this use case.
- (Pro Tip) Don't worry about it if you mess up the configuration file beyond all repair. You will find the unmolested version of the file as lighttpd.conf.sample in the directory, and you can just delete the messed up file, and copy this file over and start anew. Similarly for most other config files we'll be messing with.
8. (Optional) Give It a Test
Code:
service lighttpd onerestart
should start the webserver without any errors if you did step 7 correctly. Now, go to your web browser, and go to the IP of your jail. If everything is working, you will get a
403-forbidden message. Don't panic, that's a sign everything is actually WORKING. There's more to configure. (The problem is that OwnCloud just served up a .php file, and you haven't configured anything to handle PHP--so the fact that you see the error means, ironically, that everything is "working" as much as it can at this point. Excellent!)
9. Set up FastCGI/PHP in lighttpd
We must activate the FastCGI module.
Code:
nano /usr/local/etc/lighttpd/modules.conf
find this line:
#include "conf.d/fastcgi.conf"
and "uncomment" it by removing the "#" at the beginning. Then, edit the
fastcgi.conf file itself:
Code:
nano /usr/local/etc/lighttpd/conf.d/fastcgi.conf
and add your own
fastcgi.server block (leave all the commented-out examples in there...):
Code:
fastcgi.server = ( ".php" => ((
"bin-path" => "/usr/local/bin/php-cgi",
"socket" => "/tmp/php.socket",
"max-procs" => 1,
"bin-environment" => (
"PHP_FCGI_CHILDREN" => "3",
"PHP_FCGI_MAX_REQUESTS" => "1000"
),
"bin-copy-environment" => (
"PATH", "SHELL", "USER"
),
"broken-scriptfilename" => "enable"
)))
This sets up a bunch of PHP listeners for the web server, but far, far fewer than would be used in a publicly-available web page that would be accessed by tons of people. This keeps the resources required fairly modest.
10. Set up PHP itself
PHP is tremendously complex and annoying to set up. Don't even try to Google it. Two "sample configurations", both of which are insanely more complex than we need, are in the
/usr/local/etc/ directory, namely
php.ini-development and
php.ini-production. Your PHP configuration depends upon what's in the file
php.ini. Which doesn't exist. Yet. So, make a new file by editing it in nano:
Code:
nano /usr/local/etc/php.ini
and simply have it contain the following five lines:
Code:
post_max_size = 2000M
upload_max_filesize = 1999M
upload_tmp_dir = /tmp
cgi.fix_pathinfo = 1
memory_limit = 32M
You might be wondering, "what the hell's with the 1999MB limit on the file size" etc? Great question. And one that I lost some sleep over. Turns out there's a "bug" or something in PHP, where you're not going to be able to use anything over 2GB. After discovering this, and tracking it down, it seems like
this git commit will fix this in future versions, but as of right now (March 2014), the PHP that pkg installed for me still had the bug. If you try to use a bigger file size, you'll receive an error, every time you upload ANY file, about the "file size" being "too big for the HTML max filesize specified in the HTML command" or something ridiculous like that. Of course, this is only for the WebGUI/PHP. If you upload to your "cloud" using the OwnCloud client you won't have any such limitations.
11. Test Your OwnCloud!
Let's give it a try!
Code:
service lighttpd onerestart
If it's working, it should have started quickly and without any warnings, and when you type "top" at the command line, you should see a single
lighttpd and a few
php-cgi processes owned by the www user:
Code:
last pid: 49189; load averages: 0.33, 0.32, 0.29
13 processes: 1 running, 12 sleeping
CPU: 0.0% user, 0.2% nice, 0.4% system, 0.0% interrupt, 99.4% idle
Mem: 16M Active, 811M Inact, 14G Wired, 4564K Cache, 465M Buf, 589M Free
ARC: 10G Total, 4683M MFU, 4383M MRU, 290K Anon, 207M Header, 1170M Other
Swap: 8192M Total, 8192M Free
PID USERNAME THR PRI NICE SIZE RES STATE C TIME WCPU COMMAND
45369 www 1 23 0 132M 19080K accept 0 0:03 2.20% php-cgi
45145 root 1 20 0 69588K 5224K select 0 0:02 0.00% sshd
45367 www 1 20 0 33168K 4532K kqread 1 0:01 0.00% lighttpd
44319 root 1 52 10 18636K 2180K wait 1 0:01 0.00% sh
45148 root 1 20 0 17568K 2964K pause 1 0:00 0.00% csh
44467 root 1 20 0 14180K 1596K nanslp 1 0:00 0.00% cron
44293 root 1 20 0 12080K 1576K select 0 0:00 0.00% syslogd
45368 www 1 52 0 128M 11052K wait 0 0:00 0.00% php-cgi
49189 root 1 20 0 16600K 2408K CPU1 1 0:00 0.00% top
49187 root 1 52 10 3816K 1488K nanslp 1 0:00 0.00% sleep
46557 root 1 52 0 46888K 4524K select 0 0:00 0.00% sshd
45370 www 1 52 0 128M 11000K accept 1 0:00 0.00% php-cgi
45371 www 1 52 0 128M 11000K accept 1 0:00 0.00% php-cgi
Awesome, now when you go to your IP address in your web browser, you ought to be greeted by the OwnCloud first-time start up page! Everything is ready to go! One you get it set up, try to drag in a medium sized file (say, 25MB? something like that), and make sure it uploads correctly.
If you want https (SSL) installed, keep reading. If not, skip to Step 14! Congratulations.
12. Create SSL certificate
This is for encryption, and not necessarily authentication. i.e., if you're at Starbucks, and want to get back to your OwnCloud and not have your password typed in the clear or have your OwnCloud data snoopable on the wire, this is what you want.
Make a certificate directory. I chose
/usr/local/etc/lighttpd/certs but you can choose whatever you like. Just remember what it is. Navigate to the directory and create your certificate:
Code:
openssl req -new -x509 -keyout lighttpd.pem -out lighttpd.pem -days 1000 -nodes
Enter the information requested (you can lie if you want, doesn't matter), and then
Code:
chmod 400 lighttpd.pem
.
13. Instantiate an HTTPS Socket in lighttpd
At the bottom of
/usr/local/etc/lighttpd/lighttpd.conf, add the following block:
Code:
# https socket
$SERVER["socket"] == ":443" {
ssl.engine = "enable"
ssl.pemfile = "/usr/local/etc/lighttpd/certs/lighttpd.pem"
}
where the directory and filename listed is the one you used from step #12.
14. Final Check
Restart everything with
Code:
service lighttpd onerestart
Check the following to your satisfaction:
- http connection.
- https connection (if installed).
- test the upload of a small file in the web browser.
- test the upload of a larger file in the web browser.
- verify that any OwnCloud clients you will be using (in practice, people upload and download with the sync'ing owncloud client that they download, similar to how DropBox is done) are working correctly with respect to uploading, downloading, and what not.
- Everything should be fairly snappy with this configuration.
15. Making it Permanent
- Make your web server (and hence, OwnCloud) start automatically with the jail by adding it to the sysrc:
Code:
sysrc lighttpd_enable=yes
- Disable ssh until such time as you need it again--this was not a very good/secure set up for ssh. Exit your ssh client, go back to the FreeNAS GUI, bring up your jail's command line, and disable ssh services:
Code:
sysrc sshd_enable=no
andCode:
service sshd onestop
That's it! Try stopping and restarting the jail, and making sure everything is cool! I hope that was useful. I donated an entire weekend to making this process and post :)