[Fedora Server] can’t create or write data directory

Hello everyone
I am trying to install nextcloud on Fedora Server using this tutorial https://fedoramagazine.org/build-your-own-cloud-with-fedora-31-and-nextcloud-server/ but with data set in /opt/nextcloud catalogue. Unfortunately I am still getting this annoying warning “can’t create or write data directory”
These are my ls -la
#data directory
[root@fedora-server szymon]# ls -la /opt/
razem 0
drwxr-xr-x. 3 root root 23 05-20 15:40 .
dr-xr-xr-x. 17 root root 224 05-19 14:46 …
drwxr-xr-x. 2 apache apache 6 05-20 15:40 nextcloud

#nextcloud directory
[root@fedora-server szymon]# ls -la /var/www/html/
razem 4
drwxr-xr-x. 3 root root 23 05-20 15:17 .
drwxr-xr-x. 4 root root 33 05-19 15:55 …
drwxr-xr-x. 13 apache apache 4096 05-20 15:17 nextcloud

Should I change anything in /etc/httpd/conf/httpd.conf ?
Thanks in advance

So I assume you have all the steps completed up to the point where you need to access the web interface (Step 3).

I also have a separate data directory as well for my system. You need to edit nextcloud’s config.php file if that is the case. See the configuration parameters on docs.nextcloud.com for config.php.

Since you also mention SELinux, you may need to give the SELinux running on your system a head’s up on what you’re doing as well. That’s under the SELinux section, also on docs.nextcloud.com.

Editedconfig/config.php with ‘datadirectory’ => ‘/opt/nextcloud/’, Still no luck

Here is my config.php
GNU nano 4.9.2 config.php

<?php $CONFIG = array ( 'instanceid' => 'ocepubrk36ey', 'datadirectory' => '/opt/nextcloud', );

that could be the line in the howto that doesn’t match your setting. since you want to write to /opt/nextcloud.

grafik

SELinux? → ls -Z

Thanks a lot for your help, of course I should change those lines from howto, now i dont understand this

Even after setting context opt is still unconfined

[szymon@fedora-server config]$ ls -Z /opt
unconfined_u:object_r:usr_t:s0 nextcloud
[szymon@fedora-server config]$ sudo semanage fcontext -a -t httpd_sys_rw_content_t '/opt/(/.)?’
ValueError: Kontekst pliku dla /opt/(/.
)? jest już określony
(Meaning context for opt is set)
[szymon@fedora-server config]$ ls -Z /opt
unconfined_u:object_r:usr_t:s0 nextcloud

there is an ‘*’ missing. i think.
and you have to run the restorecon command as well.

# semanage fcontext -a -t httpd_sys_rw_content_t '/opt/nextcloud(/.*)?'
# restorecon -Rv '/opt/nextcloud/'

It seems like it finally works Thanks a lot once again! :upside_down_face:

To sum up: Setting your data outside of your web root on Fedora Server requires:

  1. Creating desired location for example
    #mkdir /opt/nextcloud/
  2. Changing ownership of this location to user apache and group apache (just like in the manual) ie:
    #chown -R apache:apache /opt/nextcloud/
  3. Configuring SELinux ie:
    # semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/config(/.*)?'
    # semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/apps(/.*)?'
    # semanage fcontext -a -t httpd_sys_rw_content_t '/opt/nextcloud/(/.*)?'
    # semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/.user.ini'
    # semanage fcontext -a -t httpd_sys_rw_content_t '/var/www/html/nextcloud/3rdparty/aws/aws-sdk-php/src/data/logs(/.*)?'
    # restorecon -Rv '/var/www/html/nextcloud/'
    # restorecon -Rv '/opt/nextcloud/'