I am desperately trying to mount a CIFS share on a Debian 10 box through a web user interface and get it accessible for the whole system. The mount command is executed successfully but the mount point is not listed in /etc/mtab or /proc/mounts and therefore also not shown by the mount command.
I am using apache2 as a webserver and I tried different approaches all with the same result.
The goal is to use a php-script with Apache or Nginx that mounts a share that is valid and visible for the whole OS just like if I used the mount command on the commandline.
I have tried different ways with a mount.php that calls a bash-script to mount the share:
- added www-data to sudoers without password and call the script containing “sudo mount …”
- used a c-compiled wrapper that is executed as root which calls a bash-script that mounts the share
- installed php-fpm with a root-enabled socket to call the bash script
- let the bash-script add the share into /etc/fstab and execute mount -a
All these approaches work as they should if called from the command line, even when called as www-data user (where possible).
They all also seem to mount the share when called through the web interface, because if I use the same techniques to launch a mount without any parameters in a php-script from the website the mount is listed as it should be. Also a second try to mount the share through the web interface gives the message that the device is busy.
But when I use the mount command without any parameters on the command line the mountpoint is not listed nor do I find it in /etc/mtab or /proc/mounts.
In the last approach, where I let the script edit the /etc/fstab and call a ‘mount -a’ the behaviour is exactly the same (listed in web interface but not on command line), but when I reboot the share is mounted as expected and visible.
So I am very sure that I am overlooking some kind of userspace / sandbox / terminal restriction where apache2 runs in that has some effect on the mount command. What is strange, because I even can edit the /etc/fstab with the scripts and seem to have root access to everything – even to mount, otherwise it would not start at all. But anyhow the mount command seems to write it’s mount-results somewhere else when invoked through the web interface.
Does anybody have an idea that points me in the right direction?`
Thanks in advance,
Axel
2
Answers
If you have troubles with permissions, and dont want to dig too deep on that, i recommend to use a simple Write to File function in PHP, then, with a CRON JOB execute a script that if find that file, delete it, and execute the function you desire. That cron job should not have any permission issues on the complete computer.
Apache2 has a property “PrivateTmp” which is set in /etc/systemd/multi-user.target.wants/apache2.service. Try commenting it by putting a hash (#) in front of the line.
Mount uses the temp folder and if Apache uses a private temp folder it might not appear in the mount list.