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/23 00:49]
admin [HTTP Server (Apache2)]
vms:webdev:apache [2017/03/31 15:13] (current)
admin ↷ Links adapted because of a move operation
Line 3: Line 3:
 ----- -----
  
-This page describes a method to compile the Apache 2.2 (2.4) server on a debian wheezy platform, preparing it to be used in conjunction with php-farm, so to let one choose a specific php version to be run for each virtual ​site served through the Apache server.+This page describes a method to compile the Apache 2.2 (2.4) server on a debian wheezy platform, preparing it to be used in conjunction with php-farm, so to let one choose a specific php version to be run for each virtual ​host served through the Apache server.
 ----- -----
 ===== Compile Apache2 ===== ===== Compile Apache2 =====
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 381: Line 391:
 </​code>​ </​code>​
  
-You probably noticed that this configuration file allows you to specify the PHP version you'd like to execute for the specified vhost [[vms:​webdev:​phpfarm|using phpfarm]].\\+You probably noticed that this configuration file allows you to specify the PHP version you'd like to execute for the specified vhost [[vms:​webdev:​phpfarm|using phpfarm ​(follow this link to learn how to install php-farm)]].\\
 We did as well specify the location where the apache logs are to be stored. We chose to have them stored under the **/​var/​www/<​vhostname>/​log** directory so they will be available straight from the host's filesystem (no need to login into the VM to consult them). We did as well specify the location where the apache logs are to be stored. We chose to have them stored under the **/​var/​www/<​vhostname>/​log** directory so they will be available straight from the host's filesystem (no need to login into the VM to consult them).
 +
 +=== Apache 2.4 ===
 +In case your installing Apache 2.4, the following code needs to be modified according to the [[http://​httpd.apache.org/​docs/​trunk/​upgrading.html#​access|directives found on the Apache website]]:
 +
 +Replace:
 +<​code>​
 +Order allow,deny
 +Allow from all
 +</​code>​
 +
 +With
 +<​code>​
 +Require all granted
 +</​code>​
 ==== Activate the New Virtual Host ==== ==== Activate the New Virtual Host ====
 <​code>​ <​code>​
Line 423: Line 447:
 Then access this page from a web browser using [[http://<​vhostname>/​info.php]],​ you should see a page summarizing your installed php config. Then access this page from a web browser using [[http://<​vhostname>/​info.php]],​ you should see a page summarizing your installed php config.
  
 +----
 ===== Fixed IPs ===== ===== Fixed IPs =====
 ----- -----
Line 490: Line 515:
 ----- -----
 ++++ ++++
 +
 +----
 +===== 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>​