TurnKey Linux Virtual Appliance Library

Is it possible to use a folder of the host OS as DocumentRoot?

Excuse me if I overlooked the answer to this question. I've searched the forum and the internet, but couldn't find anything on the subject (except for this, but I don't think it answers my question).

I'm running the Turnkey LAMP appliance, works like a charm so far. Is it by any chance possible to mount a folder of the host OS (Windows 7), say c:/Users/localhost and set that as the documentroot?

Thank you very muych in advance!

Jeremy's picture

You could do that, although I'd go the other way.

So share a folder on the LAMP appliance using Samba and map it as a network drive on your Windows 7 machine. You could use Samba as a client to go the way you want but IMO it will involve a bit more mucking around.

To share your current docroot (/var/www by default) first install Samba (and the Samba Webmin module):

apt-get update && apt-get install samba webmin-samba

Off the top of my head, I reckon the easiest way to go would be to add a new Linux user and add them to the www-data (webserver) user group. Set the new user's home as /var/www AFAIK permissions will default to 755 (which should be ok) but depending on your web content you may wish to change this (or if I'm wrong). So permissions can be set for that folder to 755 (or 744 even if only html is to be used, or if your site requires write access then go 775 or 774 - google found me this great Linux file permissions explaination here). You can do this via an SFTP client (such as Filezilla) or through Webmin (File Manager >> Info) or at the command line:

chown -R 755 /var/www

Then sync the new Linux user as a Samba user (Samba keeps its own user list - keep the name the same to avoid confusion). Now share /var/www (I use the Samba Webmin interface, it's fairly straightforward). You won't need to worry about file permissions as we've handled that earlier. Once you're finished restart samba on your appliance. If you want more info about Samba have a look at the Ubuntu documentation here.

Now on your Windows host browse to the share you just created in a Explorer window you will want something like this:

\\<appliance_ip>\

It will ask for your username and password, use the details of the new Linux user you created. Then browse to the folder (it will be the only one shown and if you allow Windows to remember password then you can map this share as a Network drive.

Hey JedMeister, Thank you

Hey JedMeister,

Thank you very much for your clear and detailed answer. Leaving the house in five minutes so I'll have to wait until later before I can try it out.

The reason I want it the other way around is because that way I could keep my Turnkey install (and the *.vdi) clean. I was hoping to keep a backup of my vdi disk in case something goes awry. I could easily restore it, without having to sync any work files. My current localhost contains over 10GB of work files, so that could be somewhat of a hassle. Another reason is that I could have access to my files even when Virtualbox is not running. If you happen to know a way to do this I would love to hear it.

Thanks again for helping me out, really appreciated!


Jeremy's picture

Ok it looks like you'll want smbclient then...

I haven't tested any of this so we may need to tweak some details.

Install smbclient and smbfs like this:

apt-get update && apt-get install smbclient smbfs

I'm not sure of the exact details but it will basically involve connecting to the file share and then mounting it to the local linux filesystem. 

Some config info can be found in the Ubuntu docs here. I haven't read it all but this on Mounting Win Shares permanently may also be useful. You may need to have a play around with it to get it working nicely. FYI it seems there may be some bugs netween Windows Live Essentials and Samba access to Win 7 shares, you may need to uninstall Live Essentials, see this thread on Ubuntu forums. There is also an outdated (but possibly still useful) tutorial on Ubuntu forums here.

Good luck and please document your experience so you can post back with info in case others want to do the same as you.

I got it to work!

After some tinkering it seems like I've got it working and it's actually not that hard to do. I'm now rocking a clean virtual lamp stack with a Document Root that resides on the host OS. It seems to run pretty well!

I'm still working on some of the details - for example, I'd like to move mysql's datadir to the host OS too - but as soon as I'm done I'll post a follow up with the steps needed to get this working.

Thanks JedMeister for getting me started!


Jeremy's picture

No worries

Glad you got it all running. You should be fine moving the database too, but just keep in mind that TKLBAM may need tweaking if you want backups as well. Assuming you mounted your docroot in the usual place then TKLBAM shouldn't even notice the difference.

Which solution worked for you?

I'm interested if you ended up using samba, smbclient and smbfs, or ultimately found a way to use VirtualBox's shared folder feature.

Rik


Here's how I did it.

I looked into using Virtualbox's shared folders feature (as I believe Guest additions are in the repos) but ended up using samba instead simply because I already had a few pointers at hand (here's to you, JedMeister!). I'm not exactly a Linux rocket scientist, so if there's anything I did that can or should be done differently I'd love to hear it!

First order of business was ssh'ing into TKL and installing samba and webmin's smb module (although I ended up not having to use it):

root@lamp:~# apt-get update && apt-get install smbclient smbfs webmin-smb

I created a folder on the host OS (Windows 7) to be my Document Root:

c:/Users/appel/Localhost

and shared it on the network so it would be available like so:

//<HOST-OS-IP>/Localhost

Then I created a mount point in TKL:

root@lamp:~# mkdir -p /mnt/Localhost

and after some trial and error I mounted it with this command:

root@lamp:~# mount.cifs //<HOST-OS-IP>/Localhost /mnt/Localhost -o user=<USERNAME>,password=<PASSWORD>

My next step was to make these changes persistent. I opened /etc/fstab:

root@lamp:~# pico /etc/fstab

and slapped this on the end of the file:

//<HOST-OS-IP>/Localhost /mnt/Localhost cifs user=<USERNAME>,password=<PASSWORD>,dir_mode=0777,gid=root 0 0

I rebooted to see if that worked and sure enough it did... Great success!

So then I opened Apache's main conf file:

pico /etc/apache2/sites-enabled/000-default

and changed the variable DocumentRoot to reflect the new location:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /mnt/Localhost
        <Directory />
                Options FollowSymLinks
                AllowOverride All
        </Directory>
</VirtualHost>
I restarted Apache:
root@lamp:~# service apache2 restart
and then checked in the browser to see if it worked. And it did!
 
That's pretty much it. Hope this helps others!

just needed smbfs

All I had to do was create my local share in widnows then "apt-get install smbfs", then add the mount (did smbfs not cifs) to fstab and an Alias & Directory to sites-available/default.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <p> <span> <div> <h1> <h2> <h3> <h4> <h5> <h6> <img> <map> <area> <hr> <br> <br /> <ul> <ol> <li> <dl> <dt> <dd> <table> <tr> <td> <em> <b> <u> <i> <strong> <font> <del> <ins> <sub> <sup> <quote> <blockquote> <pre> <address> <code> <cite> <strike> <caption>

More information about formatting options

Leave this field empty. It's part of a security mechanism.
(Dear spammers: moderators are notified of all new posts. Spam is deleted immediately)