andreask99
Posts: 9
Joined: Mon Nov 25, 2013 3:48 pm

Owncloud 'failed to connect to database'

Mon Nov 25, 2013 6:54 pm

Hi,
I just got my Owncloud server up and running but when i rebooted the system, owncloud says 'failed to connect to database'? Anyone who knows whats worng?
Thankful for answers!

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: Owncloud 'failed to connect to database'

Mon Nov 25, 2013 10:28 pm

By default Owncloud uses a SQLite database, stored in the file "data/owncloud.db" in your Owncloud installation's folder. It sounds like Ownclound can't access this file for some reason, either it's been deleted or Owncloud doesn't have permissions to access it. If it exists, you can view it's permissions with the command:

Code: Select all

ls -l data/owncloud.db
It should be owned by the user "www-data" (or "apache" on some distributions). If it's not, you can change the owner with the "chown" command:

Code: Select all

sudo chown www-data data/owncloud.db

andreask99
Posts: 9
Joined: Mon Nov 25, 2013 3:48 pm

Re: Owncloud 'failed to connect to database'

Tue Nov 26, 2013 1:35 pm

Code: Select all

sudo ls -l data/owncloud.db
ls: cannot access data/owncloud.db: No such file or directory
The file dont exist?
But why did it worked before i rebooted the RPI?

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: Owncloud 'failed to connect to database'

Tue Nov 26, 2013 2:37 pm

You'll need to run that command in the directory (AKA folder) where Owncloud was installed, by default it's in /var/www/owncloud. Use the "cd" command to change directories, for example:

Code: Select all

cd /var/www/owncloud
Then run the "ls" command, which lists all the files in the directory you specify, or the current directory if you just run "ls":

Code: Select all

ls -l data/
The "-l" flag (AKA option) tells ls to list the files in long format, showing each file's permissions and owner, along with some other info.

andreask99
Posts: 9
Joined: Mon Nov 25, 2013 3:48 pm

Re: Owncloud 'failed to connect to database'

Tue Nov 26, 2013 3:30 pm

When i check with filezilla the folders on the pi, i see that its 2 owncloud directories with the same file, /home/pi/owncloud and /var/www/owncloud?
When i run the ls to /var/www/owncloud i get this

Code: Select all

sudo chown www-data var/www/owncloud
chown: cannot access `var/www/owncloud': No such file or directory
Am i doing wrong?

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: Owncloud 'failed to connect to database'

Tue Nov 26, 2013 7:01 pm

The /home/pi/owncloud folder is the pi user's Owncloud files, I think that's where uploaded files will be kept.

When specifying a file or directory from the command line, you have two ways to tell the command which file/folder you want: absolute paths and relative paths.
Absolute paths show where the file is relative to the root directory, the root directory contains all other files and directories and is represented by a slash ("/"). So, the absolute path to Owncloud would be "/var/www/owncloud", meaning the "owncloud" directory is in the "www" directory which is in the "var" directory in the root "/" directory.
Relative paths show where the file is relative to your current working directory. When you start a new terminal session, your working directory (the directory you are "in", so to speak) is your home folder, for example "/home/pi". If you specify a path without a leading slash "/", then the path is relative to "/home/pi", so if you type "ls owncloud" then the shell will interpret that as "/home/pi/owncloud".

You can change your working directory with the "cd" command, so to go to the main Owncloud folder run:

Code: Select all

cd /var/www/owncloud
From there, you can use relative paths:

Code: Select all

sudo chown www-data data/owncloud.db
The shell interprets "data/owncloud.db" as "/var/www/owncloud/data/owncloud.db".

andreask99
Posts: 9
Joined: Mon Nov 25, 2013 3:48 pm

Re: Owncloud 'failed to connect to database'

Tue Nov 26, 2013 7:13 pm

Code: Select all

sudo chown www-data data/owncloud.db
chown: cannot access `data/owncloud.db': No such file or directory

Code: Select all

ls
3rdparty  COPYING-AGPL    db_structure.xml  lib         robots.txt
apps      COPYING-README  files             ocs         search
AUTHORS   core            index.html        public.php  settings
backup    cron.php        index.php         README      status.php
config    data            l10n              remote.php  themes
what should i do? The file seems to be deleted

hunternet93
Posts: 336
Joined: Mon Dec 12, 2011 4:34 pm

Re: Owncloud 'failed to connect to database'

Tue Nov 26, 2013 7:17 pm

That could be the problem, the Owncloud database file got deleted or never got saved for some reason. You can try reinstalling Owncloud, however this might erase any data you've saved:

Code: Select all

sudo apt-get install --reinstall owncloud owncloud-sqlite

Return to “Troubleshooting”