Apache / PHP magic MIME problems

I have a dev server (LFS) which uses magic MIME (installed that a long time ago, but I don't recall any problems), and it works fine. As for my production server (FreeBSD) I can't get magic MIMEs to work properly in any fashion. I've tried a lot, so I'm going to try and compress it as much as possible:

I upgraded Apache and PHP (and all dependencies, afaik).

Using the constant FILEINFO_MIME_TYPE results in notices that the constant is not defined. Which is odd on its own! However, using FILEINFO_MIME I get some useful warnings.

Now, it tells me:
Code:
Failed to load magic database at '/usr/share/misc/magic'.

I tried loading the other files there as well (as finfo_open() allows you to load a specific database), which result in the same messages (after I allowed access through open_basedir).

I also see Apache can use magic MIME, and has its own database in /usr/local/etc/apache22/magic. I tried loading that (again, open_basedir), and it -does- load the database, but the MIME types it returns aren't correct. (text/c++ for PHP files?)

I'm pretty sure the Apache and PHP magic MIME features aren't related, so I'm not planning on abusing the Apache magic file. I feel like I'm missing something obvious, but I don't know what. It shouldn't be this hard to get this working properly?
 
After trying a bit more, I seem to have solved it!

Things I did:

Edit: don't do this part (you can, but as SirDice pointed out, you should not overwrite base OS stuff..)
Deinstall and recompile/install file from the ports repository (/usr/ports/sysutils/file) with the following command: [CMD=""]make PREFIX=/usr && make PREFIX=/usr install[/CMD] I found that compiling it normally, it got installed under /usr/local/...

Then I deinstalled PHP 5 and all its extensions, and recompiled them all.. seems the extensions don't actually get recompiled when the files are still in place, so I got rid of them with [CMD=""]make distclean[/CMD] (this is prolly what went wrong earlier). Check if there is anything left in /usr/local/lib/php/20090626/ (or possibly other dir) before recompiling/installing the extensions.

So now everything is neatly updated, which means the fileinfo.so has gone from 53557 bytes to 1859074 bytes! I assume it now actually has the magic MIME database included in that file?.. Doesn't really matter.. at least it works now! :)
 
MPaans said:
Deinstall and recompile/install file from the ports repository (/usr/ports/sysutils/file) with the following command: [CMD=""]make PREFIX=/usr && make PREFIX=/usr install[/CMD] I found that compiling it normally, it got installed under /usr/local/...
There's a reason for that. You now have overwritten the file(1) command that's part of the base OS.
 
Yes, that was my intention.. I think it's a bit weird that when you want to upgrade something like file, it doesn't actually do that, and defaults to putting it in the local directory.. I guess there is a reason for that?
 
MPaans said:
I guess there is a reason for that?
Yes, ports and the base OS are strictly separated. Next time you're going to update your FreeBSD base OS, /usr/bin/file will be overwritten with the standard FreeBSD one.
 
Ah, that explains it then.. I'll revert it. Thanks for the info. I edited my original post so other noobs won't do the same ;)
 
Back
Top