Nextcloud "occ files:scan --all" fails

I’m trying to debug a problem with Nextcloud, which uses “External storage” setups pointing to Samba shares on another server. I tried using dietpi-drivemanager to setup the share (and then use NC with a local external storage config), but that runs into permission errors (NC is not running as dietpi but as www-data).

Here are the first few error lines:

/var/www/nextcloud# sudo -u www-data php occ files:scan --all
Starting scan for user 1 out of 5 (admin)
Error during scan: Undefined array key "attributes"
Exception during scan: Malformed state response from server
#0 /var/www/nextcloud/apps/files_external/3rdparty/icewind/smb/src/Wrapped/Share.php(216): Icewind\SMB\Wrapped\Parser->parseStat()
[...]

It looks like a 3rd party “icewind” extension is used to provide SMB access to PHP, but this is no longer maintained. There is some info here: Malformed state response from server · Issue #109 · icewind1991/SMB · GitHub

The suggestion is to install via “pecl”. I’m not very familiar with PHP, I did install php-pear, but DietPi has no php-dev package for php8.2, apparently. It’s needed for phpize:

# pecl install smbclient
downloading smbclient-1.2.0dev.tgz ...
Starting to download smbclient-1.2.0dev.tgz (35,344 bytes)
.........done: 35,344 bytes
7 source files, building
running: phpize
sh: 1: phpize: not found

I don’t know what to try next. I’d rather not mess with NC or PHP. My goal is to keep the Nextcloud areas working for my family’s user accounts, which are “attached” to remote SMB folders. As alternative for SMB mounts inside NC, is there perhaps some way for dietpi-drivemanager to mount SMB with mode 0755 so that the NC process can access these folders?

-jcw

Well, NC is a web server application. Therefore ist using the web server user.

this you would need to do manually within /etc/fstab. Theoretically you could even change the user who is mounting the drive

not the best setup so to say. Could give quite some challenges along the way :wink:

Yes, of course NC runs as www-data.

I don’t see what’s wrong with mounting remote SMB inside NC. The SMB shares are on a private NAS behind a firewall, with a large RAID disk set (a huge collection of professional photos).

NC is on a simple RasPi4 w/ DietPi and reachable from the internet. This has been working splendidly for many years.

I’ll look into the /etc/fstab suggestion you made, but that’s brittle since DietPi adjusts that file.

As alternative to mounting the Samba share as webserver user, it should work to add the webserver user to the DietPi group:

sudo usermod -aG dietpi www-data

Of course this grants it respective access to all files owned by that group, i.e. potentially more stuff in /mnt/dietpi_userdata, depending on the software you use.

On Debian Bookworm running PHP 8.2 there is php8.2-dev and on Trixie running PHP 8.4 there is php8.4-dev. So as long as the project you want to use or compile supports the PHP version which runs your Nextcloud, there should not be a problem.

Aha, that could work, with some care - I only have nginx with static sites + NC running as www-data.

As for php8.2-dev, I can’t find it:

# uname -a
Linux houtje 6.12.47+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.47-1+rpt1~bookworm (2025-09-16) aarch64 GNU/Linux
root@houtje:~# apt install php8.2-dev
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
E: Unable to locate package php8.2-dev
E: Couldn't find any package by glob 'php8.2-dev'

I’m using the default apt sources list from DietPi, AFAIK.

You are running Trixie or Bookworm

The kernel version indicates Bookworm, but to be sure:

cat /etc/os-release
cat /etc/apt/sources.list
apt update
apt policy php8.2-dev

Bookworm. Magic? I do see the pkg in there:

[...]
Fetched 10.4 MB in 10s (992 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
8 packages can be upgraded. Run 'apt list --upgradable' to see them.
php8.2-dev:
  Installed: (none)
  Candidate: 8.2.29-1~deb12u1
  Version table:
     8.2.29-1~deb12u1 500
        500 http://ftp.de.debian.org/debian bookworm/main arm64 Packages
        500 https://deb.debian.org/debian-security bookworm-security/main arm64 Packages

500? is it a server issue? I’ve done the apt upgrade.

And now it installs php8.2-dev just fine. Great, now I can try fixing the SMB issue in NC \o/

I’m stumped as to what happened …

Hehe no, this is the default priority of packages, so all as expected. Hence it was only an apt update missing to fetch current lists. Maybe you moved your lists to RAM via dietpi-config or cleared them at some point.

Great, I can confirm that pecl install smbclient now completes without errors:

[...]
Build process completed successfully
Installing '/usr/lib/php/20220829/smbclient.so'
install ok: channel://pecl.php.net/smbclient-1.2.0dev
configuration option "php_ini" is not set to php.ini location
You should add "extension=smbclient.so" to php.ini

The original exception during occ files:scan still happens, is this the proper file to add the suggested line: /etc/php/8.2/fpm/php.ini ? (Again, total PHP noob here, sorry)

1 Like

Yep, I did change the APT settings because aptitude was dog slow while investigating all this.

You might want to enable the APT cache and/or disable list compression. Both (disabled cache and enabled compression) reduces disk writes significantly on apt update, but slows down all APT actions which include parsing list contents likewise.

You would need to add it to /etc/php/8.2/cli/php.ini as well to be active for the occ (or on DietPi the ncc shorthand) to have it active. Or better make it a drop-in config/mod:

cat << '_EOF_' > /etc/php/8.2/mods-available/smbclient.ini
; SMB client extension
; priority=90
extension=smbclient.so
_EOF_
phpenmod smbclient

Enabling it that way adds it to the respective conf.d directories below fpm/ and cli/ and other possible PHP invokations.

Bingo, I was halfway: figured out the ini module iso an edit, but didn’t know the phpenmodcmd!

Another little detail is that I had to add a cache dir (uid/git www-data):

gencache_init: Failed to create directory: /var/www/.cache/samba - Permission denied

After re-running the scan, success at last:

root@houtje:/var/www/nextcloud# sudo -u www-data php occ files:scan --all
Starting scan for user 1 out of 5 (admin)
Another process is already scanning '/admin'
[...]
Starting scan for user 5 out of 5 (samuel)
+---------+-------+-----+---------+---------+--------+--------------+
| Folders | Files | New | Updated | Removed | Errors | Elapsed time |
+---------+-------+-----+---------+---------+--------+--------------+
| 1441    | 53002 | 0   | 0       | 0       | 0      | 00:02:58     |
+---------+-------+-----+---------+---------+--------+--------------+

As I understand it, this solves the NC + SMB error caused by icewind relying on an outdated SMB client, by building and adding the latest php-smbclient extension to bypass the smbclient cmdline utility.

Thanks, you guys rock !!!

I guess the Samba cache dir does not need to be in the public /var/www, i.e. looks more like a potential security issue. Maybe there is a way to change that directory to e.g. /run/php or something like that. Funnily first search machine finds are in Nextcloud context, even that it is stated there to be a general smbclient issue:

But also:

Seems to have been solved in recent Samba, so probably Debian Trixie solves it. … the other reports indicate that cache dir is created in the user’s home, so looks like no way to change it. And I would probably ignore it unless there are actual issues with the mounts. Else, assure to deny public access to this directory in webserver config. Seems to be a common issue with services (and related service users) using libsmbclient, which often have no write access to their home directory, or no home dir at all. some /run sub directory does then often exist, so making that cache dir adjustable would then be a sane solution, probably implemented in recent versions already. … though checking the patch https://launchpadlibrarian.net/586046474/add_dir_create_or_exists_recursive.patch there the solution was to recursively create parent directories if missing. So in our case with www-data that wouldn’t help.

So if you want to mute that error:

cat << '_EOF_' > /etc/apache2/conf-available/samba-cache.conf
<Directory /var/www/.cache>
	Require all denied
</Directory>
_EOF_
a2enconf samba-cache
apachectl -t # verify it returns OK
systemctl restart apache2
mkdir -p /var/www/.cache/samba
chown www-data /var/www/.cache/samba

And then it would be interesting to see what is inside, once you did some SMB mounts. There seem to be credentials caches for two backends in smbclient, likely it’s that.

Btw, Icewind is the nickname of a developer from Nextcloud, not the name of the PHP extension :slightly_smiling_face:.

Oops, a security hole is bad. I’m using nginx, btw. I’ll look into it, it’ll be easy to fix. There’s one 524 KB file inside that samba subdir in the cache, a .tdb file. It compresses to under 2 KB, so essentially empty (looks like connection credentials, not great that it’s world-readable).