Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!

Resolve a WebDAV and PHP conflict Network
We have our development web server configured with WebDAV, which I highly recommend since it makes editing content about as easy as if the site were on your local Mac. But we ran into a strange bug where one file (xml_test.php) just wouldn't open in BBEdit from a WebDAV mount point.

Editing the file directly on the server with vi showed that the file was fine, but we would get "Premature end of file" errors when trying to open the file via WebDAV. We quickly ruled out all the obvious candidates like file or directory permissions, and were forced to the conclusion that something about the file itself was causing the problem. That's a pretty odd problem for a file server to have. Curious. For fun, I opened the file in vi on the client side, but that showed the file as empty! So that ruled out anything odd with BBEdit or virtually anything on the client side.

A quick tcpdump session showed that the file Content-length was being reported as zero. That explained the "end of file" error, but why would WebDAV arbitrarily set the content length to zero when the file clearly had bytes in it? Other PHP files in the same directory worked just fine. Curiouser and curiouser. On a lark, I checked the server error_log (I know it should have been one of the first things I did), and noticed that we were getting PHP warnings! So mod_php was trying to handle the file -- not something a file server ought to be doing.

Checking the Apache config files, I realized that PHP had been enabled globally, not just in a specific content directory. We have several different content directories where we use PHP, and I didn't want to have to turn on PHP in each of them. So I just added a RemoveType .php line to the WebDAV directory config, effectively turning off PHP handling within the WebDAV root directory. This resolved the problem.

I realize this is a pretty specific hint, but I suspect there are other people out there having similar problems. I still have no idea why it was working fine with some PHP files and not others. If PHP were trying to operate on the files at all, I would have guessed it would have served up the results of the PHP execution, not the file contents itself. So that part's still a mystery. But recognizing that PHP was even involved at all was the turning point for me, and disabling it within the WebDAV directory certainly cured the problem. By the way, our server was Linux, not Mac OS X, but since it's Apache on *nix, it's all the same animal.
    •    
  • Currently 3.75 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (4 votes cast)
 
[8,498 views]  

Resolve a WebDAV and PHP conflict | 4 comments | Create New Account
Click here to return to the 'Resolve a WebDAV and PHP conflict' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Resolve a WebDAV and PHP conflict
Authored by: kevinv on Jan 26, '05 12:56:17PM

the documentation on webdav from the Apache 2.0 manuals talks about this:

http://httpd.apache.org/docs-2.0/mod/mod_dav.html

scroll down to the complex configurations part.

This is one of the reasons I turned off WebDAV on my server, it just wasn't that useful having to maintain that amount of configuration.

Instead I installed Netatalk 2 and am much happier.



[ Reply to This | # ]
Another remote edit solution
Authored by: lullabud on Jan 26, '05 05:04:30PM

If you don't have access to install Netatalk (which is a great solution that I've used for more than just apache in the past) you can use Fugu to SFTP in. You can configure it to open up remote files inside of an editor when you double-click on them. I personally have SubEthaEdit set up to open php and html files, but I'm sure you could use other applications for web authoring. When you save the file in the editor Fugu automatically uploads the changes to the server immediately.

When you use SubEthaEdit and Fugu together it is easy to get help (from other Mac OS X users) with your code without allowing people to connect with afp, smb, ftp or ssh, since you can share your documents with them via SubEthaEdit.



[ Reply to This | # ]
Resolve Apache2 WebDAV and PHP conflict per Location
Authored by: snark on Jan 27, '05 04:39:33AM
Only that RemoveType does not work on directory or location sections - only per (virtual) host (at least for Apache 2 up to 2.0.52 currently ...) I ran into that problem last week actually.

The only reliable solution i found for Apache2 servers that shall process php in some locations and present unprocessed php in DAV locations is ForceType text/plain. If you want to retain other mime type associations, you can wrap it into File sections to only force text/plain on special extensions:


<Location /xyz>
  DAV on
  <File .php>
    ForceType text/plain
  </File>
  <File .phtml>
    ForceType text/plain
  </File>
...
</Location>
make sure, you catch all of the extensions you want to treat...

[ Reply to This | # ]
Have your cake and php too with aliases
Authored by: bo3behemoth on Sep 15, '05 01:08:23PM
I've been having the same difficulties. Turning off php and other server side scripting stuff is fine, but not if you're trying to edit a php file remotely that you then want others to use. Using aliases you can do both.

From the Apache mod_dav documentation:

======================

Complex Configurations One common request is to use mod_dav to manipulate dynamic files (PHP scripts, CGI scripts, etc). This is difficult because a GET request will always run the script, rather than downloading its contents. One way to avoid this is to map two different URLs to the content, one of which will run the script, and one of which will allow it to be downloaded and manipulated with DAV.


Alias /phparea /home/gstein/php_files
Alias /php-source /home/gstein/php_files
<Location /php-source> DAV On
      ForceType text/plain
</Location>
With this setup, http://example.com/phparea can be used to access the output of the PHP scripts, and http://example.com/php-source can be used with a DAV client to manipulate them.

[ Reply to This | # ]