I have a Raspberry Pi that I use to host a web server. I am using apache2 2.4.38, php8.1 and MariaDB 15.1 and I wanted to add a Nextcloud server to it. I am using the web installer version. I already have an external USB HDD with BTRFS connected to the raspberry pi, and I have set it to automatically connect on startup using the /etc/fstab file. All of that is working perfectly. I created a directory on the drive, to store the nextcloud data. I configured the directory to be owned by the www-data user, so that Nextcloud could write to it. But this is where I ran into a problem. Both nextcloud and a simple php test file I made, give permission denied errors. I already have enabled Apache2 access to the directory by adding the following to /etc/apache2/apache2.conf:

<Directory /media/backup/nextcloud>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted

(The drive is mounted at /media/backup and the directory I want to use is /media/backup/nextcloud/data. Both the nextcloud directory and the data directory are owned by www-data, the ones above them are owned by root)

I created a test file to trigger the error without having to re-enter a nextcloud password in the setup wizard every time and the php error log just gives a permission denied error. I got the info from the log using tail -n 20 /var/log/apache2/error.log and this is what the log says (with IP addresses censored of course):

[Sat Jun 04 22:38:46.485149 2022] [php:warn] [pid 1504] [client ____] PHP Warning:  include(/media/backup/nextcloud/data/cheese.txt): Failed to open stream: Permission denied in /var/www/html/sus.php on line 2
[Sat Jun 04 22:38:46.485437 2022] [php:warn] [pid 1504] [client ____] PHP Warning:  include(): Failed opening '/media/backup/nextcloud/data/cheese.txt' for inclusion (include_path='.:/usr/share/php') in /var/www/html/sus.php on line 2

What makes this even weirder to me is that I can read from /usr/share (which is open to apache2 by default) with the same PHP script.

I don't know what to do. The permissions are 770, the directories exist and are writable by www-data, I tested that with sudo -u www-data touch grass.txt. Any help would be greatly appreciated. Thank you in advance!


  • OS: Raspbian lite 10 (buster), kernel 5.10.103-v7l+
  • Device: Raspberry Pi 4B
  • My PHP test file: <?php include "/media/backup/nextcloud/data/cheese.txt";?>
  • The next cloud server is in /var/www/nextcloud, because I am planning on using a virtualhost in the future. For now, I am using a symlink in /var/www/html/cloud that points to /var/www/nextcloud. I thought maybe the symlink would be the problem, but after some thinking I realised that my test file is in /var/www/html and it has the same problem, so the symlink can't be the problem.
  • Versions of used software:
    • apache2 2.4.38
    • php8.1
    • MariaDB 15.1
  • open_basedir is not set, so that can't be it either

1 Answer 1


Okay, so after some further digging, I came across the answer. The directories above the directory I wanted to read from should have execute rights. So I did chmod +x /media /media/backup and it worked.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .