Connect Mac OS X to a Samba File Server Remotely via PHP
Ever had to connect a Mac web server to a Samba file share remotely via a PHP/HMTL form? No?! Really!? Are you sure?? Check again, I'll wait.
What's that you say!? The answer is still no!? Oh. Well.. OK.
Well anyways, I had to do this the other day and I'm going to write it down here so that I don't forget how I did it.
My work uses a little Mac web server to serve up a GitList installation (a listing of all our repos). Problem is, the Git repositories live on our LAN (Samba) file server. The Mac needs to talk to the LAN so that it can read the Git repositories and display them on the page via GitList. The Mac web server doesn't have any credentials of its own to supply to the Samba share, so, with this scipt, we ask the user for their credentials and then use those to connect to the Samba share.
Sounds like fun (kinda). I created the connect-samba.php
HTML/PHP form/script and hosted it on the Mac. When someone views the page, they'll be asked to login with thier credentials. Then the Mac will make the connection to the Samba server and mount the share to /Volumes
. When disconnect-samba.php
is run (or visited in the browser) the share will be unmounted.
We are passing user credentials via $_POST
here so obviously an SSL'd connection to the web server and Samba share is recommended.
This was one of the first experiences I had calling an external process with PHP via exec()
.