Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
vms:webdev:apache [2015/06/25 17:59]
admin [Fixed IPs]
vms:webdev:apache [2017/03/31 15:13] (current)
admin ↷ Links adapted because of a move operation
Line 235: Line 235:
 > sudo mount -t vboxsf <​www-share>​ </​path/​to/​montpoint>​ > sudo mount -t vboxsf <​www-share>​ </​path/​to/​montpoint>​
 </​code>​ </​code>​
 +
 +<WRAP center round tip>
 +In case at this point you run into a mount error of type:
 +<​code>​
 +mount: unknown filesystem type '​vboxsf'​
 +</​code>​
 +
 +You need to install the VirtualBox Guest Additions, see the [[vms:​python:​django#​install_virtualbox_guest_additions| Install VirtualBox Guest Additions]] section on this wiki.
 +</​WRAP>​
 +
 ----- -----
 ===== Setting Permissions and Mount Options ===== ===== Setting Permissions and Mount Options =====
Line 509: Line 519:
 ===== Tricks ===== ===== Tricks =====
 ---- ----
 +
 +==== Pages Caching ====
 +----
 +The above configuration worked seamlessly for months, and then, all of a sudden, the updates that were made on the files were not available on browser'​s reload !\\
 +This means, when editing a file and trying to refresh the corresponding page in the development environment,​ the "​old"​ version of the page, the first one served after the apache2 start, would be delivered over and over, no matter if its file code had been modified or not. At first it seemed obvious that it would be an Apache cache issue, but after making sure the [[http://​httpd.apache.org/​docs/​2.2/​mod/​mod_cache.html|mod_cache]],​ [[http://​httpd.apache.org/​docs/​2.2/​mod/​mod_disk_cache.html|mod_disk_cache]] and [[http://​httpd.apache.org/​docs/​2.2/​mod/​mod_mem_cache.html|mod_mem_cache]] modules were completely disabled... It didn't fix the issue!
 +
 +Even reloading/​restarting the apache2 service couldn'​t help, only a full server reboot would do the trick :-/
 +
 +=== Setting a short cache time ===
 +
 +First thing, we can try and set the apache2 caching time to only one second. This can be done by making sure the apache'​s "​expires"​ and "​header"​ modules are enabled, then set a very short caching time in .htaccess:
 +
 +<​code>​
 +> sudo a2enmod expires headers
 +> sudo service apache2 restart
 +> nano /​your/​site/​home/​.htaccess
 +<​FilesMatch "​\.(htm|html)$">​
 +  ExpiresActive On
 +  ExpiresDefault A1
 +  Header append Cache-Control must-revalidate
 +</​FilesMatch>​
 +</​code>​
 +
 +Using the "​FilesMatch"​ filter will allow to determine what files are affected by the caching policy, in case some programmatically generated (i.e: .php) files are already bearing the cache restriction header...
 +
 +=== System level caching ===
 +
 +This didn't completely resolved the problem on my configuration.\\
 +It turned out the problem came from the VM Linux system itself, it was somehow caching the operation. Luckily I found [[http://​serverfault.com/​questions/​163894/​file-change-on-a-lamp-development-server-not-taken-into-account|this post on ServerFault]],​ coming with the //sync; echo 3 > /​proc/​sys/​vm/​drop_caches // command that effectively solved this issue. It is possible to "​manually"​ launch the command repeatedly using the //watch -n // command to clean the system cache every second:
 +<​code>​
 +> watch -n 1 'sync; echo 3 > /​proc/​sys/​vm/​drop_caches'​
 +</​code>​
 +
 +We could also have a bash script running an endless loop every second, avoiding the need of the manual launch of the //watch// command. To this purpose, we'll create a shell //​**drop_caches.sh**//​ script file and put in an //**@reboot cron task**// (following commands assumed as root):
 +<​code>​
 +> nano /​etc/​init.d/​drop_caches.sh
 +
 +PASTE:
 +#!/bin/bash
 +sync; echo 3 > /​proc/​sys/​vm/​drop_caches
 +
 +> chmod +x ~/​scripts/​drop_caches.sh
 +> crontab -e
 +
 +PASTE:
 +@reboot /​root/​scripts/​drop_caches.sh
 +
 +> reboot
 +</​code>​
 +
 +To make sure that the script is well running after reboot:
 +<​code>​
 +> ps aux | grep [c]aches
 +root      2260  0.0  0.0   ​4184 ​  576 ?        Ss   ​02:​50 ​  0:00 /bin/sh -c /​root/​scripts/​drop_caches.sh
 +root      2266  0.3  0.1  10768  1412 ?        S    02:50   0:00 /bin/bash /​root/​scripts/​drop_caches.sh
 +</​code>​