A few days ago I decided to to give Owncloud a try to see what it's like, but the installation proved to be a little longer than I expected specially since I didn't want to compromise and use Apache or Nginx but my personal favorite Hiawatha.

These are the steps I took and hopefully it will save someone some time and myself in the future :)

1. Get the Owncloud repo key:

rpm --import https://download.owncloud.org/download/repositories/stable/CentOS_6/repodata/repomd.xml.key

2. Get the repo and install Owncloud (at the time of writing this will get you the latest version which is 9.0.1) :

wget http://download.owncloud.org/download/repositories/stable/CentOS_6/ce:stable.repo -O /etc/yum.repos.d/ce:stable.repo
yum clean expire-cache
yum install owncloud-files

3. In order to get a modern version of PHP we setup Remi's RPM repository:

yum install http://rpms.remirepo.net/enterprise/remi-release-6.rpm

4. Install php56 and modules:

yum install php56 \
php56-php-gd \
php56-php-pecl-dom-varimport \
php56-php-pecl-jsonc \
php56-php-xml \
php56-php-pecl-zip \
php56-php-pecl-crypto \
php56-php-mcrypt \
php56-php-intl \
php56-php-mysqlnd \
php56-php-fpm

5. Install Hiawatha 10 using an RPM from the Anku Repos:

yum install http://anku.ecualinux.com/6/x86_64/hiawatha-10.0-ecualinux.2.el6.x86_64.rpm

6. Install the city-fan repo to get an upgraded version of curl so Owncloud won't be complaining later:

rpm -Uvh http://www.city-fan.org/ftp/contrib/yum-repo/rhel6/x86_64/city-fan.org-release-1-13.rhel6.noarch.rpm
yum upgrade curl

7. Install the Percona MySQL repository:

yum install http://www.percona.com/downloads/percona-release/redhat/0.1-3/percona-release-0.1-3.noarch.rpm

8. Fix repo links:

sed -i -- 's/$releasever/6/g' /etc/yum.repos.d/percona-release.repo

9. Install Percona MySQL 5.6:

yum install Percona-Server-server-56

10. Set everything to start on boot:

chkconfig mysql on
chkconfig hiawatha on
chkconfig php56-php-fpm on

11. Add a Hiawatha user:

useradd -s /sbin/nologin -M hiawatha

12. Create a directory for the Hiawatha virtual host configs:

mkdir -pv /etc/hiawatha/conf.d

13. Tell hiawatha to run as user and group hiawatha

echo "ServerId = hiawatha:hiawatha" >> /etc/hiawatha/hiawatha.conf

14. Tell Hiawatha to include all configs under /etc/hiawatha/conf.d :

echo "Include /etc/hiawatha/conf.d" >> /etc/hiawatha/hiawatha.conf

15. Now add /etc/hiawatha/conf.d/owncloud.conf with content:

VirtualHost {
 Hostname = ------REPLACE WITH YOUR HOSTNAME OR IP ADDRESS------
 WebsiteRoot = /var/www/html/owncloud
 StartFile = index.php
 AccessLogfile = /var/log/hiawatha/owncloud-access.log
 ErrorLogfile = /var/log/hiawatha/owncloud-error.log
 TimeForCGI = 600
 WebDAVapp = yes
 UseFastCGI = PHP56
 UseToolkit = denyData
 EnablePathInfo = yes
 RequireTLS = yes
}

UrlToolkit {
ToolkitID = denyData
 Match ^/data DenyAccess
}

16. Create a self-signed SSL cert:

cd /etc/ssl/
openssl req -subj '/CN=69.87.216.249/C=US' -new -newkey rsa:2048 -sha256 -days 365 -nodes -x509 -keyout serverkey.pem -out server.crt
cat server.crt >> serverkey.pem
rm -f server.crt
chmod 400 serverkey.pem

17. Now add an SSL binding as well in /etc/hiawatha/conf.d/ssl.conf with content:

Binding {
 Port = 443
 SSLcertFile = /etc/ssl/serverkey.pem
}

18. Now add /etc/hiawatha/conf.d/php56.conf with content:

FastCGIserver {
 FastCGIid = PHP56
 ConnectTo = /var/lib/hiawatha/php-fcgi.sock
 Extension = php
}

19. Delete the vanilla php-fpm config:

rm /opt/remi/php56/root/etc/php-fpm.d/www.conf

20. Now add /opt/remi/php56/root/etc/php-fpm.d/owncloud.conf with content:

[owncloud]
user = hiawatha
group = hiawatha
listen = /var/lib/hiawatha/php-fcgi.sock
listen.allowed_clients = 127.0.0.1
pm = static
pm.max_children = 3
slowlog = /var/log/hiawatha/owncloud/php-fpm-owncloud-slow.log
php_admin_value[error_log] = /var/log/hiawatha/owncloud/php-fpm-owncloud-error.log
php_admin_flag[log_errors] = on

php_value[session.save_handler] = files
php_value[session.save_path] = /var/lib/php
php_value[soap.wsdl_cache_dir] = /var/lib/php

env[HOSTNAME] = $HOSTNAME
env[PATH] = /usr/local/bin:/usr/bin:/bin
env[TMP] = /tmp
env[TMPDIR] = /tmp
env[TEMP] = /tmp

21. Fix permissions:

chown -R hiawatha:hiawatha /var/www/html/owncloud/
mkdir -pv /var/lib/php /var/lib/hiawatha/
chown -R hiawatha:hiawatha /var/lib/php /var/lib/hiawatha

22. Before we start the services (Hiawatha,PHP-FPM and MySQL) let's make a small correction to the php-fpm script - it looks like permissions change everytime php-fpm is restarted, so this will make our change persist.

Use an editor and open /etc/init.d/php56-php-fpm, and find the start() function:

This is what it should look like now:

start () {
 echo -n $"Starting $prog: "
 dir=$(dirname ${pidfile})
 [ -d $dir ] || mkdir $dir
 daemon --pidfile ${pidfile} /opt/remi/php56/root/usr/sbin/php-fpm --daemonize
 RETVAL=$?
 echo
 [ $RETVAL -eq 0 ] && touch ${lockfile}
}

add a command to the end of the function so that it fixes the permission every time:

chown hiawatha:hiawatha /var/lib/hiawatha/php-fcgi.sock

Once you're done your function should look like this:

start () {
 echo -n $"Starting $prog: "
 dir=$(dirname ${pidfile})
 [ -d $dir ] || mkdir $dir
 daemon --pidfile ${pidfile} /opt/remi/php56/root/usr/sbin/php-fpm --daemonize
 RETVAL=$?
 echo
 [ $RETVAL -eq 0 ] && touch ${lockfile}
 chown hiawatha:hiawatha /var/lib/hiawatha/php-fcgi.sock
}

23. Start the services:

/etc/init.d/php56-php-fpm start
/etc/init.d/mysql start
/etc/init.d/hiawatha start

24. Create a database for Owncloud and add a user:

mysql -e "create database owncloud;"
mysql -e "GRANT ALL ON owncloud.* TO owncloud@'127.0.0.1' IDENTIFIED BY 'blapassword';"
mysql -e "flush privileges;"

25. Go to the own cloud starting page: http://---REPLACE WITH YOUR HOSTNAME OR IP ADDRESS---

26. Now add an admin:

  • Username: supergoat
  • Password: some-random-password

and:

Select "configure the database MySQL/MariaDB"

Fill in the following with what we've set up before:

  • Database user field: owncloud
  • Database password field: blapassword
  • Database name field: owncloud
  • Change the 'localhost' to 127.0.0.1

REFERENCES: