PDA

View Full Version : [ubuntu] How to coax Apache to download a file



GrandBob
December 16th, 2008, 05:22 PM
I'm having a blast writing my website with BASH. Everything was sailing along swimmingly until I exerted a downloading link. Zip, zero, nada. I consolidated the issue into a small example which fails.

I have experimented with several pokes at this and that, all to no avail. Also, as to an .htaccess file, the Apache docs intimate that I should not require one. Nothing exotic here... only mp3 podcast files.

We're in the directory holding the object files. For purposes of illustration, we'll focus on one file.

$ pwd
/home/grandbob/dcs/audiovisual
$ ls -hog | tail -n1
-rw-r--r-- 1 11M 2008-12-16 07:37 GORP.mp3

Now the directory with the CGI executable...

/home/grandbob/dcs
$ ls -hog download
-rwxr-xr-x 1 139 2008-12-16 07:36 download
$ cat download
#!/bin/bash
echo 'Content-type: text/html'
echo
echo 'Hello from '$(pwd)
echo '<br>'
echo '<a href="/dcsfiles/GORP.mp3">Download</a>

This is what I have in my apache site file.

$ sed '86,$d' /etc/apache2/sites-available/default | sed '1,66d'
# CGI executable
ScriptAlias /dcs/ /home/grandbob/web/dcs/
<Directory "/home/grandbob/web/dcs">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
SetHandler cgi-script
Order allow,deny
Allow from all
</Directory>

# CGI object files to be downloaded
ScriptAlias /dcsfiles/ /home/grandbob/dcs/audiovisual/
<Directory "/home/grandbob/dcs/audiovisual">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
SetHandler cgi-script
Order allow,deny
Allow from all
</Directory>

And this in my mime table...

$ grep mp3 /etc/mime.types
audio/mpeg mpga mpega mp2 mp3 m4a

Then restart apache... by log entry, it is happy.

$ sudo /etc/init.d/apache2 restart
(blah, blah, ...)
$ tail -n1 /var/log/apache2/error.log
[Tue Dec 16 08:00:15 2008] [notice] Apache/2.2.8 (Ubuntu) DAV/2
SVN/1.4.6 PHP/5.2.4-2ubuntu5.3 with Suhosin-Patch mod_ssl/2.2.8
OpenSSL/0.9.8g configured -- resuming normal operations

The browser paints a good screen.

$ lynx https://localhost/dcs/download

Hello from /home/grandbob/web/dcs
Download

The "source view" screen looks good.

Hello from /home/grandbob/web/dcs
<br>;
<a href="/dcsfiles/GORP.mp3">Download</a>

Exerting the download rudely responds...

Internal Server Error

The server encountered an internal error or misconfiguration and was
unable to complete your request.

Please contact the server administrator, webmaster@localhost and inform
them of the time the error occurred, and anything you might have done
that may have caused the error.

More information about this error may be available in the server error
log.
__________________________________________________ ________________


Apache/2.2.8 (Ubuntu) DAV/2 SVN/1.4.6 PHP/5.2.4-2ubuntu5.3 with
Suhosin-Patch mod_ssl/2.2.8 OpenSSL/0.9.8g Server at localhost Port
443

What now, Kemosabe?

Wayne_V
December 17th, 2008, 12:39 AM
$ tail -f /var/log/apache2/*log

Then hit the download again. It may become apparent .....

windependence
December 17th, 2008, 03:19 AM
You ARE a masochist aren't you? :)

I suspect without even looking at the logs that this is a permissions problem. The file that you are putting out there for download must be at least world readable.

As to the .htaccess file, no you don't need one at all, in fact I try not to have any of these on my commercial sites. Makes admin a lot simpler.

-Tim

GrandBob
December 24th, 2008, 02:38 PM
Wayne and Tim,

Thank you for your time and efforts. Your suggestions sent me down a classic path of step-by-step eliminations which lead me to the golden fleece.

My mistake was a bad case of Apache configuration speak.

Should have used Alias, not ScriptAlias, which I pasted from a working <Location> for CGI scripts, not data files.

Order has been restored to my Apache universe.

Thanks again.