Dan's picture

Let me preface this question by saying I have an internal only LAMP server... used for Intranet... I have full control over who gets to it and trust those machines.

Ok... I have a shared folder on a Windows machine that I am successfully mounting via the /etc/fstab file upon bootup and when I run the command from the console "mount -a"

The issue I have is that the windows machine gets powered off from time to time and the mapping gets lost.   

I wanted to make a button on my PHP web page (intranet) that users could click to restore the mapping.

The problem so far is that the www-data user is not allowed to run mount I think.

Can I / Should I give www-data root priveleges so it can?

Thanks for any advice, I've been looking online and just haven't found what will work yet.

Forum: 
Jeremy Davis's picture

You could give it root privileges, but IMO that's a bad idea, even in your "safe" network environment. It's further complicated by the fact that the default webserver user (www-data) doesn't have a shell (for security reasons), and TBH, I'm not sure of the best way to work around that.

TBH, I'm not a regular Windows user, so I'm not super familiar with mounting SMB shares (TBH, no longer having to work with Windows shares was one of my great reliefs transitioning to Linux only house). Also, I don't have much experience with PHP so, can't provide much advice from that angle either... Having said that, you should be able to get it to work.

A quick google suggests that the tool you'll likely want is smbnetfs. For further details, have a look through the answers on this Q&A (whilst it's for Ubuntu, it should also apply to Debian too mostly). You'll likely then need to run system commands via PHP. Having said that, there are other ways to allow PHP to do specific tasks on your server, e.g. like this. Remember that www-data doesn't have a shell by default though, so you'll still need to work around that.

Personally, if it were me, I'd probably approach your issue from a different direction. There are many ways to skin a cat!

If the TurnKey LAMP server is always on, but the Win machines is sometimes turned off, first thing I'd do is consider moving the default location of the data (to the Linux machine). Then get the Win machine to mount the Linux share on boot (or via a script etc).

If the Win machine is a laptop, or the Linux machine is sometimes also off, then I'd consider some sort of file sync tool. One that I've been playing with a bit lately is Syncthing (shameless plug: we'll hopefully be releasing a Syncthing appliance soon). Obviously that may not be the most efficient option, especially if it's a large dataset and/or changes lots, but could be worth consideration?

Another angle might be a cronjob, e.g. perhaps something like this (although perhaps best to check if the Win machine is available via the network before trying to mount?).

Hopefully that gives you some ideas. Good luck with it and please share the solution you come up with.

Add new comment