Score:0

Ubuntu Server - Apache2 - Files show as raw data

do flag

0

Ubuntu server running Apache2 and then I try to display a PDF or PNG file it shows the raw file, not the graphical view. Using different browsers do not open the file in normal viewing mode, but shows the raw data.

Example: https://docs/mydoc.pdf Result: %PDF-1.7 %���� 1 0 obj <> endobj 2 0 obj <> endobj 3 0 obj <> endobj 4 0 obj <> strea

Same file on another server opens as you'd expect.

Different browsers same results. Checked mime.types for pdf entry.

raj avatar
cn flag
raj
Look into HTTP headers served with your file, probably it is served as `text/plain` instead of `application/pdf`.
JBringolf avatar
do flag
Thank you - yes it appears to be text/html - second question is how/where do I fix that?
raj avatar
cn flag
raj
There are multiple sources Apache uses. First, check `/etc/apache2/mods-enabled` directory for `mime.conf` and `mime.load` entries to verify if MIME module is correctly loaded. If `mime_magic` entries are also there, remove them for now. Then, check your `/etc/apache2/apache2.conf` file and ALL the files it includes (from `conf.d` and `sites-enabled` subdirectories) for any lines mentioning MIME type for PDF file. Finally, check also `.htaccess` file in the same directory where PDF file is located. In any of these places something could be modified.
raj avatar
cn flag
raj
Basically, you should familiarize yourself with Apache configuration (the documentation at https://httpd.apache.org/docs/ is pretty extensive) before trying to debug any problems.
JBringolf avatar
do flag
Thank you - I believe I've checked those files and they appear correct - found this is for more than PDF's also PNG, JPG etc. Appears to be any mime type file. Have another server that works fine so I enab;ed\disable the same mods and still not working. No .htaccess in the mix.
JBringolf avatar
do flag
Apparently this was the issue in the apache2.conf file: SetHandler application/x-httpd-php
raj avatar
cn flag
raj
If you used the `SetHandler` directive unconditionally, then yes, because it caused ALL files to be treated as PHP files, so effectively, HTML code. This directive must be used conditionally, only for files with `.php` extension. If you installed PHP, then the file `php.conf` (may include some number after `php`, corresponding to PHP version) in subdirectory `mods-enabled` usually already contains the correct configuration.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.