Okay, so you have your own little Apache with MySQL running on your home box and are experimenting with one, or regularly using the both of these operating systems. As the contents of your website probably don’t, or shouldn’t change at all, it is usually quite logical to share those contents between operating systems.
Since I’ve found no such tutorial via google, I’m going to go ahead and write one.
The prerequisites are simple: You need to have Apache and MySQL installed both under Windows and Linux. Since configuring those two is already a bitch on one OS and only gets more annoying if you have to do it twice, I’ve resorted to using LAMPP and XAMPP, which you can get from apachefriends.org for both Windows and Linux. It’s more or less preconfigured and ready to go after you install it. This will obviously work with any other custom compiled or installed version of MySQL and Apache though – the only difference is the need for more configuration. Since LAMPP/XAMPP’s htdocs and mysql data-directories differ from the ones of retail installations, i will go ahead and just mention both of the paths on Windows and Linux.
Okay now, this is still theoretical: you will need to decide which one of your OSs will be the actual host of your web content data. You can use either of them, but only one at a time. Both alternatives have their downsides, as you will have to trust one of the operating systems to not screw up the other’s file system. With the recent stability of ntfs-3g, I’s say the risks are equally balanced.
I myself use Windows a lot more than Linux and hence went with using Windows as a host.
The Windows-as-host-way
What we will have to do first is take a look at where our data resides. With XAMPP, the default directory of your installation should be C:\Program Files\XAMPP\. Hence the directories:
# Windows XAMPP MySQL data directory:
C:\Program Files\XAMPP\mysql\data
# Windows XAMPP Apache htdocs directory:
C:\Program Files\XAMPP\htdocs
As for the directories of retail installations of MySQL and Apache:
# Windows retail MySQL data directory:
C:\mysql\data
# Windows retail Apache htdocs directory:
C:\Program Files\Apache Group\Apache2\htodcs
Note that paths will obviously differ if you choose to install either of the packages in another directory.
Now that we have our paths written down, we don’t need to occupy ourselves with Windows any longer. Boot into Linux.
Since we have decided to put our data into the hands of Windows, we will need Linux to be able to access and write to Windows’ partition. Depending on which file system you use, you will most probably either need write access to a FAT32 or an NTFS partition. For fat, Linux has had stable write support for ages. NTFS however only became safely writable as of last year, when NTFS-3G became stable. I’d recommend using that package, as I have yet to experience any problems with it. How you install it will depend on what Linux distribution you are using, and i believe you’re better off searching google for “<your distro> ntfs-3g” than me trying to explain every angle of that here. Obviously, to continue, you will need to get this working. Also, make sure that Apache and MySQL have the actual writing rights for those partitions. You can accomplish that by putting an uid= argument in your fstab file that has the Apache user’s uid as a parameter. Same goes for MySQL. Figure it out.
Alright, all set? Then let’s do this.
In order to make our MySQL/Apache server use the data/htdocs directory of the Windows MySQL/Apache installation, we need to replace its own data directory with a symlink to the Windows MySQL-data/Apache-htdocs directory. First, we’ll need the directories under Linux. They are, for LAMPP:
# Linux LAMPP MySQL data directory:
/opt/lampp/var/mysql
# Linux LAMPP Apache htdocs directory:
/opt/lampp/htdocs
Note that those directories *might* (as in: i have no clue) vary from distribution to distribution, depending on where they put their opt files.
Again, with retail installations of Apache or MySQL, these directories would look like this:
# Linux retail MySQL data directory:
/usr/local/mysql/data
# Linux retail Apache htdocs directory:
/var/www/localhost/htdocs
Now what we do is the following: We rename (backup) the existing folders on our Linux partition and then create symlinks to the directories inside the mountpoints of our Windows partitions. In my LAMPP/XAMPP case, I do it like that:
~ # mv /opt/lampp/var/mysql /opt/lampp/var/mysql.BACKUP
~ # ln -s /mnt/windows/Program\ Files/XAMPP/mysql/data/ /opt/lampp/var/mysql
# ^ MySQL is linked.
~ # mv /opt/lampp/htdocs /opt/lampp/htdocs.BACKUP
~ # ln -s /mnt/windows/Program\ Files/XAMPP/htdocs /opt/lampp/htdocs
# ^ Apache htdocs is linked.
Now we’re all set. Good to go. Ready to rumble. You will just have to restart your lampp-service or Apache and MySQL separately and they should be using Windows’ data.
The Linux-as-host-way
This is basically the same, just the other way around. What we will need to access Linux’ file system is, in case you’re using an ext*-fs, this: http://www.fs-driver.org/. Toy a bit around with it and make it work. In my case, I assigned my Linux partition the drive letter “L”.
Also, since Windows does not support symlinks out of the box, although NTFS (3.0 and above – which is shipped with Win2k) does support junction points, we use this tool by Sysinternals to create the junction points. Bear in mind that these junction points should not be deleted via the Windows Explorer, as it will also delete the target directory on our Linux partition.
Again, in my LAMPP/XAMPP case, I’m executing these commands in a start/run/”cmd” window (see the Windows-as-host-way paragraph on what the directories would be):
C:\> move “C:\Program Files\XAMPP\htdocs” “C:\Program Files\XAMPP\htdocs.BACKUP”
C:\> junction “C:\Program Files\XAMPP\htdocs” L:\opt\lampp\htdocs
# ^ Apache htdocs directory is linked.
C:\> move C:\mysql\data C:\mysql\data.BACKUP
C:\> junction C:\mysql\data L:\opt\lampp\var\mysql
# ^ MySQL data directory is linked.
Restart your MySQL and Apache services and you should be good to go.
I guess that’s it. I hope someone is going to find this useful. Leave any comments if you wish.
Thank you for this old but useful tutorial! I will try it out today! : )
Pingback: [Linux] Setting Permissions on ntfs-3g Disks | Arkross's Blog
Pingback: Share Data Antara XAMPP Ubuntu dengan Windows | HQ's Serenity
Seems not working for me, after multiple tries …
I’m trying to make the windows-as-host way.
I followed your instructions and see that doesn’t show a ^Apache htdocs directory linked or ^MySQL data directory is linked – just silent, but when i open the /opt/lampp i did see the links created, double click will correctly show the windows’ xampp content
then i start apache – fine, start mySQL – nothing happens, it’s not working
trying to reach localhost – not working either – an error shows
Access forbidden!
You don’t have permission to access the requested directory. There is either no index document or the directory is read-protected.
please help !
Thank you sir! Still works perfectly in 2016, managed to share htdocs by changing apache conf file, but changing the mysql conf file accoplished nothing. Your symlink method finally worked! Linking to this article from my own blog and recreating a copy for psoterity
Pingback: Share mysql and apache folders from windows XAMPP to linux XAMPP | Ephestione's HQ