-1

I CANNOT DISABLE caching of the PHP files, (haven't tried html or JS files yet). I just migrated a really old server to the above specs, (except it has RHEL7.6).

I have been using vagrant as a dev server environment for 6 years. I just built a replica for development for the newly migrated server with CentOS 7.6, Apache, and PHP 5.6.40.

I cannot seem to edit and then test those changes at all. I have tried DOZENS of suggestions found online, and at the moment the only way to see any changes I make, is to destroy the box and vagrant up a new box. NOT A SOLUTION.

I've tried. Inline PHP header statements inside the actual file

<?php header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 3600)); ?>

-> FAIL

Adding .htaccess file to the directory I'm working in

 #Initialize mod_rewrite
RewriteEngine On
<FilesMatch "\.(php|html|htm|js|css)$">
  FileETag None
  <IfModule mod_headers.c>
    Header unset ETag
    Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
    Header set Pragma "no-cache"
    Header set Expires "Wed, 12 Jan 1980 05:00:00 GMT"
  </IfModule>
</FilesMatch>

-> FAIL

Add to httpd.conf

<IfModule mod_headers.c>
    <filesmatch "\.(html)$">
        Header set Cache-Control "no-cache"
    </filesmatch>
</IfModule>

-> FAIL

I created a php file with this to include for developing a file... cacheOff.php:

header("Content-Type: application/json");
header("Expires: 0");
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT");
header("Cache-Control: no-store, no-cache, must-revalidate");
header("Cache-Control: post-check=0, pre-check=0", false);
header("Pragma: no-cache");

Then tried this in the file -> FAIL

I tried commenting out any cache.conf files in the httpd folder conf.modules.d 00-base.conf

LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule cache_module modules/mod_cache.so
#LoadModule cache_disk_module modules/mod_cache_disk.so
LoadModule data_module modules/mod_data.so

-> FAIL

I found php.ini suggestions like opcache, but it isn't in this version.

Here is my httpd.conf and php.ini files VagrantServerFiles

HELP.... PLEASE This should be easy, shouldn't it????

Quadrivium
  • 137
  • 2
  • 2
  • 15
  • Vagrant is 2.2.5. I'm using Chrome with the Developer Tools OPEN, Cache disabled in the browser. – Quadrivium Oct 14 '19 at 17:16
  • I have also checked by going to the VM, and verifying that changes I make in my IDE (phpstorm) are immediately reflected in the VM, by going to the file in the terminal, and looking. The changes are there, but when the server is hit again, I still get the original old message back. – Quadrivium Oct 15 '19 at 20:54
  • I have tried restarting apache, but it doesn't help. Only destroying the Vagrant machine, and bringing up a new one, will show that change. Seriously frustrating. – Quadrivium Oct 15 '19 at 20:55
  • 1
    What happens if you add a non-php file (i.e. test.html) and load it up and then change it. Are you seeing the changes? If you've turned off your browser cache then you've ruled out most of the approaches above (headers and htaccess are suggestions to the browser, which would be ignored if your brower's cache was disabled) so that would suggest memcache/opcache/phpaccellerator/etc or some other server-side caching going on. Or you have some kind of redirect on and don't realize it. – Ben D Oct 16 '19 at 18:02
  • Can you provide a phpinfo() output ? – Will Oct 17 '19 at 08:26
  • I have found that doing a "vagrant reload" does reset the cache, it does take a while still but not an entire 3-5 minutes. So I know there is a cache happening, i just don't know where it is. – Quadrivium Oct 17 '19 at 16:26
  • 1
    Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Questions without a clear problem statement are not useful to other readers. See: [How to create a Minimal, Reproducible Example.](https://stackoverflow.com/help/minimal-reproducible-example) – F. Hauri - Give Up GitHub Oct 20 '19 at 10:38

2 Answers2

0

change, or add this line to php.ini:

 opcache.enable=0

opcache is a php.ini.all type so it can be invoked in the php page like:

  ini_set (opcache.enable,0);

by default, the value is 1 or "on" if not declared in php.ini

drtechno
  • 298
  • 2
  • 9
  • I see no opcache section in the php.ini file, and no opcache at all in the phpInfo() output. I attempted this anyway, restarted apache, page worked, remove some text from an echo, and now the page won't load at all. Error 500. Not sure why it broke, all I did was change some echo output from "Finished with the report !!!" to "Finished !!!" Shouldn't cause an error 500. Reloading Vagrant box – Quadrivium Oct 16 '19 at 17:04
  • I don't think this php build is using opcache, I already tried this, see last couple lines in original message. I'm not that versed in the inner workings of PHP, I've always just been able to look up a problem and fix it. However, there appears to be a BIG difference between the Builds using YUM vs APT on UBUNTU. – Quadrivium Oct 16 '19 at 17:16
  • How is php working ? Is it with mod-php or php-fpm ? – Will Oct 17 '19 at 08:25
  • I updated the question with a link to a google drive folder with php.ini, httpd.conf, and phpinfo().htm in it. I can add other configs from the conf.modules.d folder if needed.. – Quadrivium Oct 18 '19 at 17:26
  • you have to add the line: opcache.enable=0 anywhere in the first section of php.ini, which is the [php] section. If you dont, it will be enabled. – drtechno Oct 19 '19 at 06:46
  • on mac versions, the differences in code has to do with the end of file marker handling in the os and parsing them during uploads and file reading. Is that the issue? Otherwise, its the same. – drtechno Oct 19 '19 at 07:29
0

Not certain, but if you've ruled out client side cache (which you have) and you don't think you're running a PHP-caching system (opcache/accelerator/etc) there are some Vagrant settings you might play around with:

Either dropping the cache (manually I think this would look like: echo 1 > /proc/sys/vm/drop_caches)

Or, possibly disabling sendfile() (see more on this answer: Vagrant/VirtualBox/Apache2 Strange Cache Behaviour)

Ben D
  • 14,321
  • 3
  • 45
  • 59