The ownCloud file sharing application has been around for some time now, but somehow evaded my attention. My limited imagination makes me say “think of it us Dropbox hosted on the server in your basement”.

Of course, it is much more than that. You can even get a cloud-hosted setup, but the “server in the your basement” is what led me to ownCloud in the first place. Plus, ownCloud is full package – server software, desktop clients, and mobile clients – all available for common operating environments.

The install is fairly straight-forward and is amply explained in the documentation as well as by countless bloggers. Personally, I followed this set of instructions to get ownCloud up and running on my CentOS 6 box.

I really didn’t have to do much, as I already had working LAMP configuration in place. I just created a new MySQL schema; unpacked the application tarball into a sub-folder of one of my existing sites; and made a couple of quick edits of the config.php.

Having said that, I did run into a few puzzling situations that were easy to resolve, but prompted me to do this quick write-up.

First, make sure to download the latest stable version, as the upgrade process is a bit hairy and you may want to enjoy the application’s functionality for a while before having to go down that rabbit hole.

Second, when editing that pesky config.php, understand this: the trusted_domains array must contain the actual full server name, IP, or domain – basically, whatever you type into the browser to get to it. Wildcards, IP ranges, CIDR notations – none of that is allowed. Here’s an example:

'trusted_domains' =>
  array (
    0 => 'localhost',             # obvious
    1 => '127.0.0.1',             # ditto
    2 => 'domain.com',            # your domain
    3 => 'whatever.domain.com',   # your subdomain
    4 => '192.168.120.137',       # the IP address associated with the domain
    5 => 'www.domain.com',        # that 'www' thing that got me
    6 => '192.168.1.1',           # the default gateway
  ),

Strictly speaking, if everything’s working just fine, you don’t need all of these things in your trusted_domains – just the primary address and whatever URL you use to access ownCloud.

Three, when choosing the administrator’s account name, go with anything but admin. And, when choosing the password, avoid Windows special characters, such as ()&%!*. Why? Because Windows is stupid and if you would like to connect to WebDAV, those special characters in the password will be a problem.

Four, since we’re on the WebDAV topic, here’s how to mount your ownCloud account. Open cmd.exe as administrator and type something like this:

net use Z: https://domain.com/remote.php/webdav /user:username passwd

You can also do the same via the File Explorer. To get the correct WebDAV URL for your installation of ownCloud, log in via the Web UI and in the bottom left corner click “Settings” and there it will be.

ownCloud has a troubled relationship with zend extension opcache, so you may run into this sort of errors:

Expand
[Thu Mar 28 20:51:12 2019] [notice] child pid 24816 exit signal Segmentation fault (11)
zend_mm_heap corrupted
zend_mm_heap corrupted
zend_mm_heap corrupted
zend_mm_heap corrupted
zend_mm_heap corrupted
[Thu Mar 28 20:51:18 2019] [notice] child pid 26777 exit signal Segmentation fault (11)
zend_mm_heap corrupted
zend_mm_heap corrupted
zend_mm_heap corrupted
zend_mm_heap corrupted
[Thu Mar 28 20:51:23 2019] [notice] child pid 26796 exit signal Segmentation fault (11)
[Thu Mar 28 20:51:41 2019] [notice] child pid 23345 exit signal Segmentation fault (11)
[Thu Mar 28 20:51:53 2019] [notice] child pid 26817 exit signal Segmentation fault (11)

Should this become a problem, a few suggestions:

  • Increase the value of output_buffering in /etc/php.ini
  • Also in /etc/php.ini try setting these two variables:
    opcache.revalidate_freq=7000
    opcache.fast_shutdown=0
  • If you really don’t feel like dealing with this, edit /etc/php.d/opcache.ini and set opcache.enable=0

Naturally you will need to reload httpd after making changes to php settings. And, if you went the route of disabling opcache altogether, doing so may have performance impact on whatever else is running on your Web server.

As I mentioned, ownCloud upgrade process, while not complicated, is a bit convoluted. I wrote a small helper script (you can download it here). I haven’t had much time to test it, so no guarantees…

#!/bin/bash
#
#                                      |
#                                  ___/"\___
#                          __________/ o \__________
#                            (I) (G) \___/ (O) (R)
#                                Igor Oseledko
#                           igor@comradegeneral.com
#                                  2019-03-25
# ----------------------------------------------------------------------------
# Upgrade local installation of ownCloud
#
# CHANGE CONTROL
# ----------------------------------------------------------------------------
# 2019-03-25  igor  wrote this script
# ----------------------------------------------------------------------------
function func_configure() {
mustbe="root"                                 # privileged user to run this update; usually root
httpd_user="apache"                           # user running the Web server process; usually apache or www-data
httpd_group="apache"                          # primary group of the user running the Web server process; usually apache or www-data
web_root="/var/www"                           # path where current 'owncloud' folder is located
owncloud_folder="owncloud"                    # name of the ownCloud folder; by default is 'owncloud'
db_user="root"                                # database user
db_host="localhost"                           # database server
db_name="owncloud"                            # database name
backup_dir="/opt/backups"                     # backup directory
# ----------------------------------------------------------------------------
this_time="$(date +'%Y-%m-%d_%H%M%S')"
this_host="$(hostname | awk -F'.' '{print $1}')"
tmpdir="$(mktemp -d)"
}
function func_checkuser() {
# This function verifies that the script is running under the required user ID.
if [ "$(whoami)" != "${mustbe}" ]
then
echo "Must be ${mustbe} to run this script. Exiting..."
exit 90
fi
}
function func_get_dbpass() {
echo -n "Enter password for database user ${db_user}: "
read -s db_pass
if [ -z "${db_pass}" ]
then
echo "Database password cannot be null. Exiting..."
exit 88
fi
MYSQL="/usr/bin/mysql --batch --skip-column-names --max_allowed_packet=100M -h${db_host} --port=${db_port} -u${db_user} -p${db_pass} ${db_name} -e"
MYSQLDUMP="/usr/bin/mysqldump -u${db_user} -p${db_pass} ${db_name}"
}
function func_get_version() {
echo -n "Enter ownCloud version to install (i.e. 10.1.0): "
read owncloud_version
if [ -z "${owncloud_version}" ]
then
echo "Application version cannot be null. Exiting..."
exit 98
fi
owncloud_url="https://download.owncloud.org/community/owncloud-${owncloud_version}.tar.bz2"
echo "Downloading ${owncloud_url}"
curl --connect-timeout 5 -k -s0 -q "${owncloud_url}" > "${tmpdir}/owncloud-${owncloud_version}.tar.bz2"
if [ ${?} -ne 0 ] || [ ! -f "${tmpdir}/owncloud-${owncloud_version}.tar.bz2" ] || [ $(/usr/bin/file "${tmpdir}/owncloud-${owncloud_version}.tar.bz2" | grep -c bzip2) -ne 1 ]
then
echo "Unable to download ${owncloud_url}. Exiting..."
exit 99
fi
}
function func_validate() {
/bin/cd ~
httpd_user_real="$(ps -ef | grep [h]ttpd | grep -v ^root | head -1 | awk '{print $1}')"
if [ "${httpd_user}" != "${httpd_user_real}" ]
then
echo "You said httpd user is ${httpd_user}, but it seems to be ${httpd_user_real}. Exiting..."
exit 103
fi
if [ ! -d "${web_root}" ]
then
echo "The specified web root location does not exist: ${web_root}. Exiting..."
exit 105
fi
if [ ! -d "${web_root}/${owncloud_folder}" ]
then
echo "The specified ownCloud location does not exist: ${web_root}/${owncloud}. Exiting..."
exit 105
fi
db_check="$(${MYSQL} "show tables;" 2>/dev/null | grep -c comments)"
if [ "${db_check}" -eq 0 ]
then
echo "Unable to work with database ${db_name}. Exiting..."
exit 112
fi
if [ ! -d "${backup_dir}" ]
then
mkdir -p "${backup_dir}" 2>/dev/null
if [ ! -d "${backup_dir}" ]
then
echo "Unable to create backup directory ${backup_dir}. Exiting..."
exit 122
fi
else
touch "${backup_dir}/.writecheck" 2>/dev/null
if [ $? -ne 0 ]
then
echo "Unable to write to backup directory ${backup_dir}. Exiting..."
exit 132
else
/bin/rm -f "${backup_dir}/.writecheck"
fi
fi
}
function func_backup_do() {
echo "Backing up ${web_root}/${owncloud} to ${backup_dir}/${owncloud_folder}_${this_time}.tgz"
tar cfz "${backup_dir}/${owncloud_folder}_${this_time}.tgz" "${web_root}/${owncloud}" 2>/dev/null
if [ ${?} -ne 0 ]
then
echo "Backup of ${web_root}/${owncloud} failed. Exiting..."
exit 142
fi
echo "Backing up database ${db_name} to ${backup_dir}/${db_name}_${this_time}.sql"
${MYSQLDUMP} > "${backup_dir}/${db_name}_${this_time}.sql" 2>/dev/null
if [ ${?} -ne 0 ] || [ ! -f "${${backup_dir}/${db_name}_${this_time}.sql}" ]
then
echo "Backup of ${db_name} failed. Exiting..."
exit 152
fi
echo "Compressing database backup ${backup_dir}/${db_name}_${this_time}.sql"
gzip "${backup_dir}/${db_name}_${this_time}.sql"
}
function func_service_stop() {
echo "Stopping Web server"
/sbin/service httpd stop
sleep 3
if [ $(ps -ef | grep -c [h]ttpd) -gt 0 ]
then
echo "Unable to stop httpd. Exiting..."
exit 203
fi
echo "Stopping cron daemon"
/sbin/service crond stop
sleep 3
if [ $(ps -ef | grep -c [c]rond) -gt 0 ]
then
echo "Unable to stop crond. Exiting..."
exit 205
fi
}
function func_service_start() {
echo "Starting Web server"
/sbin/service httpd start
sleep 3
if [ $(ps -ef | grep -c [h]ttpd) -eq 0 ]
then
echo "Unable to start httpd!"
fi
echo "Starting cron daemon"
/sbin/service crond start
sleep 3
if [ $(ps -ef | grep -c [c]rond) -eq 0 ]
then
echo "Unable to start crond!"
fi
}
function func_enable_maintmode() {
echo "Enabling maintenance mode"
/usr/bin/sudo -u ${httpd_user} php "${web_root}/${owncloud_folder}/occ" maintenance:mode --on
}
function func_disable_maintmode() {
echo "Disabling maintenance mode"
/usr/bin/sudo -u ${httpd_user} php "${web_root}/${owncloud_folder}/occ" maintenance:mode --off
}
function func_upgrade_do() {
echo "Enabling maintenance mode"
func_enable_maintmode
func_service_stop
/bin/mv "${web_root}/${owncloud_folder}" "${web_root}/${owncloud_folder}_${this_time}"
tar -jxf "${tmpdir}/owncloud-${owncloud_version}.tar.bz2" -C "${web_root}/" 2>/dev/null 1>&2
if [ ${?} -ne 0 ]
then
echo "Unable to extract ${tmpdir}/owncloud-${owncloud_version}.tar.bz2. Putting everything back and exiting..."
/bin/mv "${web_root}/${owncloud_folder}_${this_time}" "${web_root}/${owncloud_folder}"
func_service_start
sleep 3
func_disable_maintmode
exit 230
fi
echo "Setting ${web_root}/${owncloud_folder} ownership"
chmod -R ${httpd_user}:${httpd_group} "${web_root}/owncloud"
/bin/mv "${web_root}/owncloud" "${web_root}/${owncloud_folder}"
echo "Deleting new config and data folders"
/bin/rm -rf "${web_root}/${owncloud_folder}/data" 2>/dev/null
/bin/rm -rf "${web_root}/${owncloud_folder}/config" 2>/dev/null
echo "Copying old config and data folders"
/bin/mv "${web_root}/${owncloud_folder}_${this_time}/data" "${web_root}/${owncloud_folder}/"
/bin/mv "${web_root}/${owncloud_folder}_${this_time}/config" "${web_root}/${owncloud_folder}/"
func_service_start
echo "Running ownCloud update"
/usr/bin/sudo -u ${http_user} php "${web_root}/${owncloud_folder}/occ" upgrade
func_disable_maintmode
}
function func_cleanup() {
/bin/rm -rf "${tmpdir}" 2>/dev/null
}
# ----------------------------------------------------------------------------
# RUNTIME
# \(^_^)/                                      __|__
#                                     __|__ *---o0o---*
#                            __|__ *---o0o---*
#                         *---o0o---*
# ----------------------------------------------------------------------------
func_configure
func_checkuser
func_get_dbpass
func_get_version
func_validate
func_backup_do
func_upgrade_do
func_cleanup