Repository navigation
Description
Steps to reproduce
- Arch linux LAMP stack with nextcloud installed using (https://wiki.archlinux.org/index.php/Nextcloud#Installation)
- set fstab to mount synology nfs v3 mount on to data directory (migrating the default data in the process)
- Check/fix permissions using script located at https://docs.nextcloud.com/server/9/admin_manual/installation/installation_wizard.html
- restart httpd service
Expected behaviour
nextcloud writes data to new nfs mounted data mount without issue
Actual behaviour
nextcloud error "Your data directory is not writable"
[root@lin-virt02 nextcloud]# sudo -u http php occ files:scan admin
Your data directory is not writable
Permissions can usually be fixed by giving the webserver write access to the root directory. See https://docs.nextcloud.com/server/12/go.php?to=admin-dir_permissions.
An unhandled exception has been thrown:
Exception: Environment not properly prepared. in /usr/share/webapps/nextcloud/lib/private/Console/Application.php:145
Stack trace:
#0 /usr/share/webapps/nextcloud/console.php(99): OC\Console\Application->loadCommands(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#1 /usr/share/webapps/nextcloud/occ(11): require_once('/usr/share/weba...')
Troubleshooting
[root@lin-virt02 nextcloud]# sudo -u http ls -alh data
total 436K
drwxrwxrwx 1 http http 188 Nov 9 04:00 .
drwxr-x--- 16 http http 4.0K Nov 9 03:54 ..
drwxr-x--- 1 http http 76 Sep 30 02:03 admin
drwxr-x--- 1 http http 146 Sep 27 19:19 appdata_ocb0vuuo4fin
drwxr-x--- 1 http http 26 Oct 25 19:14 files_external
-rw-r--r-- 1 http http 324 Sep 27 17:43 .htaccess
-rw-r----- 1 http http 0 Sep 27 17:43 index.html
-rw-r----- 1 http http 428K Nov 7 15:23 nextcloud.log
-rw-r----- 1 http http 0 Sep 27 17:43 .ocdata
[root@lin-virt02 nextcloud]# sudo -u http touch data/test
[root@lin-virt02 nextcloud]# sudo -u http ls -alh data
total 436K
drwxrwxrwx 1 http http 196 Nov 9 04:00 .
drwxr-x--- 16 http http 4.0K Nov 9 03:54 ..
drwxr-x--- 1 http http 76 Sep 30 02:03 admin
drwxr-x--- 1 http http 146 Sep 27 19:19 appdata_ocb0vuuo4fin
drwxr-x--- 1 http http 26 Oct 25 19:14 files_external
-rw-r--r-- 1 http http 324 Sep 27 17:43 .htaccess
-rw-r----- 1 http http 0 Sep 27 17:43 index.html
-rw-r----- 1 http http 428K Nov 7 15:23 nextcloud.log
-rw-r----- 1 http http 0 Sep 27 17:43 .ocdata
-rw-r--r-- 1 http http 0 Nov 9 04:00 test
FIX
Comment out:
/usr/share/webapps/nextcloud/lib/private/legacy/util.php
} else if (!is_writable($CONFIG_DATADIRECTORY) or !is_readable($CONFIG_DATADIRECTORY)) {
//common hint for all file permissions error messages
$permissionsHint = $l->t('Permissions can usually be fixed by giving the webserver write access to the root directory. See %s.',
[$urlGenerator->linkToDocs('admin-dir_permissions')]);
$errors[] = [
'error' => 'Your data directory is not writable',
'hint' => $permissionsHint
];
AND
/usr/share/webapps/nextcloud/lib/private/Console/Application.php
if ($input->getFirstArgument() !== 'check') {
$errors = \OC_Util::checkServer(\OC::$server->getSystemConfig());
if (!empty($errors)) {
foreach ($errors as $error) {
$output->writeln((string)$error['error']);
$output->writeln((string)$error['hint']);
$output->writeln('');
}
throw new \Exception("Environment not properly prepared.");
}
}
Then reboot httpd service. After doing this uploads and downloads are successful and no errors are presented.
Test
[root@lin-virt02 nextcloud]# sudo -u http php occ files:scan admin
Starting scan for user 1 out of 1 (admin)
+---------+-------+--------------+
| Folders | Files | Elapsed time |
+---------+-------+--------------+
| 12 | 19 | 00:00:00 |
+---------+-------+--------------+
Server configuration
Operating system: Arch linux
Web server: Apache
Database: Mariadb
PHP version: 7
Nextcloud version (see Nextcloud admin page): Nextcloud 12.0.3
Updated from an older Nextcloud/ownCloud or fresh install: Installed 6 months ago and kept up to date via package manager.
Where did you install Nextcloud from: Arch repo
Client configuration
Browser: chrome/firefox
Operating system: Windows/Linux
Activity
tflidd commentedon Nov 11, 2017
Did you verify that you can upload via webinterface? This would mean that there is a bug in the
is_writable()function of php...The documentation says that this function caches the result: http://php.net/manual/en/function.is-writable.php
Xarin commentedon Nov 11, 2017
Yes, I'm now able to login and upload/download/delete via the web interface.
Xarin commentedon Feb 20, 2018
Still encountering the same issue on Version 13.0.0. The fix still works but gives code integrity check warnings.
PHP
Version: 7.2.2
Memory Limit: 512 MB
Max Execution Time: 3600
Upload max size: 511 MB
Database
Type: mysql
Version: 10.1.31
Size: 2.4 MB
weikinhuang commentedon May 8, 2018
I'm also encountering this issue, when running within a docker container on kubernetes. The data directory is also from a synology nas unit.
Error
NFS and Mount settings
Dir info
Nextcloud is running as uid/gid 9000/9000.
I will note that it was previously working when I was running the nfs server on CoreOS instead of the synology nas unit.
willruss1 commentedon Jun 18, 2018
Can also verify behaviour on 13.0.3 and newest 13.0.4 release.
Setup:
Ubuntu 18.04
Nginx 1.14
MariaDB 10.1.29
PHP 7.2
Data folder symlinked to NFS mount on Synology RS816:
Commenting out checks as noted by @Xarin continues to function as a workaround, but has to be re-applied after every update; not ideal. Filesystem permissions are all right,
www-datauser writing / deleting via shell works just fine, as does uploading / deleting via the Nextcloud web UI after commenting out these checks.dromer commentedon Sep 12, 2018
I would recommend we get rid of
is_writable()because this is not a reliable check.Best is maybe to actually try writing a file?
[edit: ran in to this in #11145]
weikinhuang commentedon Sep 18, 2018
Any update on this issue?
ossgeek314 commentedon Dec 6, 2018
The issue seems to be unaddressed even in v14.0.4.
The issue only started after an upgrade from ubuntu 16.04 -> 18.04. The www-data user can write to the directory and appying the "fix" allows the program to function properely. Clearly, the php is_writable() function is the issue.... I've even got the uid of www-data and the owner on the NAS to be the same.
Can we get a different check... even for just nfs?
rcdailey commentedon Dec 18, 2018
Just verified I'm running into this issue on v15. Very annoying. Can't use NFS mounts because of this.
This post has a workaround that involves modifying the code itself.
Disable data directory write checks
nathankellenicki commentedon Jan 10, 2019
Is there any update on this? Also running this when mounting an NFS v4.1 share onto a Ubuntu 18.04 host, with that directory mapped into a Nextcloud docker volume's data/ dir.
Have double checked by exec'ing into the container and writing a file into the directory, and it is indeed writeable.
6 remaining items
Improve data directory write checking for NFS mounts
Disco1 commentedon Feb 25, 2020
I'm having this issue, specifically with an EFS mount on AWS. Everything seems to work OK. Can this error safely be ignored?
sprnza commentedon Mar 17, 2020
Currently the installation fails because of lib/Setup.php still has
!is_writable($dataDir))sprnza commentedon Mar 17, 2020
The official docker image is being used.
Even if I comment out the lines inside Setup.php and get the installation step passed getAppDataFolder() in
lib/private/Files/AppData/AppData.phpthrows NotPermittedException. I am able to create dirs by www-data inside the docker container:sprnza commentedon Mar 17, 2020
rcdailey commentedon Mar 17, 2020
@sprnza you should open another issue. I'm running version 18 on a NFS mount with no problems.
kesselb commentedon Mar 17, 2020
But please ask the community for advice first.
sprnza commentedon Mar 17, 2020
@rcdailey okay. Just to clarify: are you able to create new users? It seems to me that my issue causes the initial setup I try to perform.
rcdailey commentedon Mar 17, 2020
@sprnza Again I encourage you to follow @kesselb's advice and ask in the community. He provided a link for you. I don't think we should ping people with notifications on this thread unless the original issue has regressed.
Xarin commentedon Apr 23, 2020
Just recently rebuilt my nextcloud server on docker, and it does look like this is still an issue.
https://github.com/nextcloud/server/blob/master/lib/private/Setup.php - Line 312
if ((!is_dir($dataDir) && !mkdir($dataDir)) || !is_writable($dataDir))which still fails when using a synology mount, commenting out 312-314 fixes the issue.
lasat commentedon Oct 12, 2020
Problem still exists. I am using docker fpm and tried to move config and custom_apps directory to nfs. Afterwards nextcloud 18 rejected to start caused by is_writable checks in lib/private/legacy/util.php
After I had disabled the "Check if there is a writable install folder." and "Check if config folder is writable." NC is working again.
gabo-it commentedon Apr 3, 2022
Hi all,
i # all lines "Check if there is a writable install folder." and "Check if config folder is writable." inside the following files:
/usr/src/nextcloud/lib/private/legacy/OC_Util.php
/var/www/html/lib/private/legacy/OC_Util.php
but i'm still unable to install NC with data folder mounted on NFS. I can touch files inside /data from container... Any help??
My dockerfile:
version: "2"
services:
nextcloud:
image: nextcloud
container_name: nextcloud
environment:
- PUID=${PUID}
- PGID=${PGID}
- TZ=${TZ}
- NEXTCLOUD_DATA_DIR=/data
volumes:
- /home/**************/Docker/Nextcloud/Config:/var/www/html
- nfs-data:/data
ports:
- 444:443
- 4488:80
restart: unless-stopped
depends_on:
- nextcloud_db
nextcloud_db:
image: linuxserver/mariadb
container_name: nextcloud_db
environment:
- PUID=${PUID}
- PGID=${PGID}
- MYSQL_ROOT_PASSWORD=************
- TZ=${TZ}
- MYSQL_DATABASE=nextcloud_db
- MYSQL_USER=nextcloud
- MYSQL_PASSWORD=**************
volumes:
- /home/*********/Docker/Nextcloud/mariadb:/config
restart: unless-stopped
volumes:
nfs-data:
driver_opts:
type: nfs4
o: addr=192.168.111.50,nfsvers=4,rw
device: :/volume1/Nextcloud/
gabo-it commentedon Apr 14, 2022
if i try that, i get
Error while trying to initialise the database: Failed to connect to the database: An exception occurred in the driver: SQLSTATE[HY000] [14] unable to open database file