How to disable PHP Phar - GZip Compression - gzip

I am trying to show echo'd statements as a PHP script is running.
I have tried every variant of flushes I can find, I have turned on Output Buffering in my server's PHP settings (Linux) but I am just out of ideas!
I have read having GZIP compression enabled can be an issue.
Our server has the PHP Phar package installed.
I added phar.readonly=1 to the php.ini with no luck it still shows enabled in PHPinfo()!

Related

Serving directory on samba share with Apache 2.4.41 truncates header

I have a strange problem when downloading files from an Apache 2.4.41 webserver serving files from a samba share on Ubuntu 20.04.
A python requests call ends in BadStatusLine('pache/2.4.41 (Ubuntu)\r\n')) and Chrome sometimes shows partial http headers in the begining of the file.
Usually the response would start with "HTTP/1.1" while with this server it directly starts with "pache 2.4.41" which looks like a shortened "Apache 2.4.41".
After digging a lot I found one helpful post: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=900821
If I set "EnableSendfile On" in Apache for this directory it now seems to work. But this is scary as hell. Will it always work? Also for file uploads, etc.? Why is this still an issue in 2021 when the original error was reported in 2018!
And here the server response:

PDF not opening correctly on web browser for files on remote folder

I'm using a Debian EC2 instance running a Apache2 server (from the open semantic search package).
When I try to open a pdf file in the web browser (inline?), it opens a modified version of it when the file is located on a remote folder but not when the file is located locally.
I saw recommendation (http://www.devside.net/wamp-server/forcing-a-pdf-or-doc-to-open-in-browser-rather-than-downloading) to modify the Apache configuration file to include:
<LocationMatch "\.(?i:pdf)$">
ForceType application/pdf
Header set Content-Disposition inline
</LocationMatch>
I tried adding it to /etc/apache2/apache2.conf
But when I restart the apache server, I get the following error message:
apachectl[16425]: AH00526: Syntax error on line 207 of /etc/apache2/apache2.conf:
apachectl[16425]: Invalid command 'Header', perhaps misspelled or defined by a module not included in the server configuration
My questions are:
Which Apache configuration file should I modify?
Is this modification going to open the pdf file in the web browser inline without downloading / modifying the pdf file when coming from a remote folder?
Thanks!
Yoann
I suspect that it isn't the PDF that is getting corrupted, but the images inside of it.
Some time ago, some server admins were having problems with images getting corrupted by apache2. See for example serverfault and drupalQuestion.
The proposed solution is to change a couple of settings in the apache2 config file. I suspect memory mapping is the issue, which can be turned off by adding the following command to apache2.conf:
EnableMMAP Off
I hope this helps!

Gzip files are corrupted when downloaded off an Apache 2.4.28 server. Fine via FTP/SZ

I am not sure when this started happening, but I have noticed that when I download .gz (gzip) files through httpd (apache 2.4.28), and try to open them on the client they are corrupted.
If I download them via sz, ftp, or another method they open fine on the client. If I transfer them via scp to another server and download them they work fine.
At first I thought it could be mod_deflate compressing it more than it should and corrupting it, but I disabled mod_deflate and the behavior still occurs.
I then downloaded nginx-1.12.2.tar.gz from nginx.org using wget on the server. When I downloaded that through Apache, it opened fine on the client.
As another test, I created a gz file on another server and transfered it over to the problematic one. Tried downloading that & it was corrupted.
So not really sure whats going on here. Can't seem to get a rhyme or reason to this bug.
Any thoughts?
Same problem here with apache 2.2 and 2.4, but removing
SetOutputFilter DEFLATE
from the vhosts configuration file (and doing an apache reload) fixed it for me on either machine.
Make sure to restart or at least reload apache after changing the vhosts config.
Turns out it was an incorrect mime type in the httpd.conf file.

Getting mod_deflate working on Apache for a PHP app on Heroku's Cedar stack

How can I get mod_deflate on Apache and Heroku Cedar with a PHP app? I have mod_deflate importing and rules set set in my htaccess, yet my responses won't gzip.
Not sure if you're still interested in solving this problem, but here goes. A lot of this is going to depend on how you've set your dyno up.
If you're running the Heroku PHP buildpack with Apache, the buildpack version of Apache comes with mod_deflate pre-installed.
Even if you're not running the Heroku PHP buildpack, there's some chance that mod_deflate might be pre-installed. You can check by running a bash prompt on a one-off dyno and using apache2ctl to list all available modules:
$ heroku run bash
Running `bash` attached to terminal... up, run.9057
$ $(which apache2ctl || which apachectl) -M
Loaded Modules:
core_module (static)
...
deflate_module (shared)
...
After ensuring that mod_deflate was installed and enabled, I then used the .htacess configuration recommended by html5-boilerplate to compress textual MIME types. I added this config to my apache config, but I would think it would work from .htaccess too. After deploying the new configuration, mod_deflate worked as expected.
Hope this helps!

JS and CSS files in vagrant not properly encoded when saved outside of the VM

I'm running vagrant on OSX, Ubuntu, and Windows 7 and using vim and Netbeans as IDEs on the host machine. The VM is running CentOS 6.3 and Apache 2.2. The docroot is set to /vagrant.
When I edit a JS or CSS file and save it, the browser then turns around and detects illegal characters. When I view the file in the browser I see the diamond-question mark character which usually points to an encoding issue. I can open the file up in vim inside the VM and save it with :w ++enc=utf-8 and the file will load normally.
I've tried multiple IDEs on the host machine and different host OSes, and can only pinpoint it to something to do with vagrant and the mounted directory. My IDEs aren't the problem as I can run the files locally and they work, or save them to a remote machine and the files work. Only when I save them to what gets mounted in /vagrant do I have a problem.
Is it Apache or something else in the OS that I need to change to get this to work?
I had this problem this morning. Set EnableSendfile to off in your httpd.conf.
If you look at your httpd.conf it says "turn this off if you serve from NFS-mounted filesystems." In http://httpd.apache.org/docs/2.2/mod/core.html#enablesendfile it explains that "By default, when the handling of a request requires no access to the data within a file -- for example, when delivering a static file -- Apache uses sendfile to deliver the file contents without ever reading the file if the OS supports it."
Since your windows host has an ntfs file system, the linux guest doesn't properly cache the file with sendfile and so apache needs to send the file itself. This may cause a marginal slowdown when requesting files from apache, but it should be negligible.
It depends on what server you are using.
For Nginx: in /etc/nginx/nginx.conf:
change the line that contains sendfile on; to sendfile off;.
For Apache: in /etc/httpd/conf/httpd.conf:
change remove comment for EnableSendfile off;
And don't forget restart your Nginx or Apache. If it still doesn't work, exit and vagrant reload or something like that - restart your VM.