Caching

    Web application performance problems are not easy to fix properly. The responsiveness of your application at a moment depends on many factors: the application code, installed plugins, AWS load, server type, caching mechanism, etc.

    The most common reason for performance issues is lack of any caching. Turning it on, what for most BitNami Applications is not that diffucult, dramatically improve the server performance.

    WordPress

    W3 Total Cache

    http://wordpress.org/extend/plugins/w3-total-cache/

    In most cases, enabling "Page Caching" with "disk" option should be enough.

    Debugging

    If you have problems configuring W3 Total Cache, try to enable Debug mode. Go to the W3 Total Cache admin and select at least "Page Cache" option in the Debug section. Then go to one of your web pages and check the source code. There should be a debug info at the end, this way you can check if caching works properly.

    When WordPress is configured in the /wordpress url location

    You may found problems when your WordPress application is installed in the /wordpress location. There may be a conflict between the permalink rewrites and the ones added for W3 Total Cache plugin. The problem is the order in which those rewrites are evaluated.

    Make sure that all the Rewrite* entries are removed or commented out in the /opt/bitnami/apps/wordpress/conf/httpd-app.conf file:

    Alias /wordpress/ "/opt/bitnami/apps/wordpress/htdocs/"
    Alias /wordpress "/opt/bitnami/apps/wordpress/htdocs"
    
    <Directory "/opt/bitnami/apps/wordpress/htdocs">
        Options Indexes MultiViews +FollowSymLinks
        AllowOverride None
        <IfVersion < 2.3 >
        Order allow,deny
        Allow from all
        </IfVersion>
        <IfVersion >= 2.3>
        Require all granted
        </IfVersion>
        RewriteEngine On
        RewriteBase /wordpress/
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /wordpress/index.php [L]
    </Directory>

    Quick Cache

    Permission issues

    Permissions: Please check permissions on /wp-content/cache . Quick Cache needs write-access to this directory. Permissions need to be 755 or higher.
    Permissions: Please check permissions on /wp-config.php . Quick Cache needs write-access to this file. Permissions need to be 755 or higher.
    

    We usually set the ownership of the application files to "bitnami" user and "daemon" group, so you are able to edit the files directly as the bitnami user and Apache is able to read them. In this case, when you want Apache to be able to modify any files or directories, you need to give write permissions to the group too.

    Execute the commands below to assure both bitnami user and Apache can read and write to the "cache" directory and wp-config file?

    $ sudo chown -R bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-content/cache
    $ sudo find /opt/bitnami/apps/wordpress/htdocs/wp-content/cache -type f -exec chmod 664 {} \;
    $ sudo find /opt/bitnami/apps/wordpress/htdocs/wp-content/cache -type d -exec chmod 775 {} \;
    $ sudo chown bitnami:daemon /opt/bitnami/apps/wordpress/htdocs/wp-config.php
    $ sudo chmod g+w /opt/bitnami/apps/wordpress/htdocs/wp-config.php
    

    Minify

    This plugin uses the Minify engine to combine and compress JS and CSS files to improve page load time. There are several plugins for the same purpose: Minify, WP Minify or Better WordPress Minify. You can install one of them and it should improve your page load time. In all cases it is necessary to have WordPress running in the root URL. Check this guide to see how to move your WordPress to the root URL.

    Mediawiki

    You can enable page caching adding the following entries at the end of the /opt/bitnami/apps/mediawiki/htdocs/LocalSettings.php file:

    $wgUseFileCache = true; /* default: false */
    $wgFileCacheDirectory = "$IP/cache";
    $wgShowIPinHeader = false;
    

    You will also need to execute this command to set proper directory permissions:

    sudo chmod g+w /opt/bitnami/apps/mediawiki/htdocs/cache
    

    There are some good articles on this topic:

    http://www.mediawiki.org/wiki/Manual:File_cache
    http://www.mediawiki.org/wiki/Manual:Cache
    http://www.mediawiki.org/wiki/User:Aaron_Schulz/How_to_make_MediaWiki_fast

    Drupal

    Make sure that you have "Normal Caching mode" on in the Drupal Administer/Site Configuration/Performance section.

    Magento

    Enable all the application cache options in the Magento administration panel (In System -> Cache Management).

    Varnish

    Preparation

    The following procedure describes how to properly activate and configure Varnish in the BitNami Cloud Hosting machine. We assume that your Web Application instance (for instance WordPress, Drupal, etc.) is already running in the root url location, for instance at http://mywp.bitnamiammp.com or http://example.com/

    • First, connect to your server via SSH. Learn more.
    • Enable and start the Varnish service. You can skip this step if you selected "Varnish" option inside the "Development Options" in the server creation form. Varnish service will be started on port 81 by default so it shouldn't affect any other currently configured componens and web pages. Execute the following commands:
    sudo mv /opt/bitnami/varnish/scripts/ctl.sh.disabled /opt/bitnami/varnish/scripts/ctl.sh
    sudo /opt/bitnami/ctlscript.sh start varnish
    
    • Backup the original Varnish configuration file:
    sudo cp /opt/bitnami/varnish/etc/varnish/default.vcl /opt/bitnami/varnish/etc/varnish/default.vcl.backup
    

    Configure your application

    IMPORTANT: Varnish is connected to Apache locally so other applications like 'phpMyAdmin', 'phpPgAdmin' or 'server-status' could be public after enabling it. Please check this section to know how to block these apps for security reasons.

    WordPress

    • Add the WordPress-specific Varnish configuration executing the following commands:
    wget -O wordpress.vcl http://wiki.bitnami.com/@api/deki/files/347/=wordpress.vcl
    sudo cp wordpress.vcl /opt/bitnami/varnish/etc/varnish/default.vcl
    sudo sed -i 's/port\s*=\s*"[^"]*"/port = "80"/g' /opt/bitnami/varnish/etc/varnish/default.vcl
    

    Drupal

    • Install and enable a proper version of Varnish Drupal module from drupal.org/project/varnish
    • If you use Drupal 7.x, please add the following at the end of the /opt/bitnami/apps/drupal/htdocs/sites/default/settings.php file:
    $conf['cache_backends'][] = 'sites/all/modules/varnish/varnish.cache.inc';
    $conf['cache_class_cache_page'] = 'VarnishCache';
    $conf['page_cache_invoke_hooks'] = FALSE;
    $conf['reverse_proxy'] = True;
    $conf['cache'] = 1;
    $conf['cache_lifetime'] = 0;
    $conf['page_cache_maximum_age'] = 21600;
    $conf['reverse_proxy_header'] = 'HTTP_X_FORWARDED_FOR';
    $conf['reverse_proxy_addresses'] = array('127.0.0.1');
    $conf['omit_vary_cookie'] = True;
    
    • Modify the Varnish ctl script so it does open the terminal port:
    sudo sed -i 's/VARNISH_OPTIONS="-a/VARNISH_OPTIONS="-T localhost:6082 -a/g' /opt/bitnami/varnish/scripts/ctl.sh
    
    • Update the Varnish config file:
    wget -O drupal.vcl http://wiki.bitnami.org/@api/deki/files/476/=drupal.vcl
    sudo cp drupal.vcl /opt/bitnami/varnish/etc/varnish/default.vcl
    sudo sed -i 's/port\s*=\s*"[^"]*"/port = "80"/g' /opt/bitnami/varnish/etc/varnish/default.vcl
    

    Magento

    • Add the Magento-specific Varnish configuration executing the following commands:
    bash < <(curl -s https://raw.github.com/colinmollenhour/modman/master/modman-installer)
    source ~/.profile
    cd /opt/bitnami/apps/magento/htdocs
    modman init
    modman clone magneto-varnish https://github.com/madalinoprea/magneto-varnish.git
    wget https://raw.github.com/mursalat92/magneto-varnish/master/magento-varnish3.vcl
    sudo mv magento-varnish3.vcl /opt/bitnami/varnish/etc/varnish/default.vcl
    sudo sed -i 's/port = "8008"/port = "80"/g' /opt/bitnami/varnish/etc/varnish/default.vcl
    
    • You may review other settings editing the file /opt/bitnami/varnish/etc/varnish/default.vcl
    • Enable "Varnish" in Magento admin console, System -> Cache Management
    • Flush magento cache:
    sudo rm -rf /opt/bitnami/apps/magento/htdocs/var/cache/*
    sudo rm -rf /opt/bitnami/apps/magento/htdocs/var/sessions/*
    

    Ghost

    • Add the Ghost-specific Varnish configuration:
    wget  https://gist.github.com/lkarsten/6683179/raw/3d03b14b3a3ca1301a2397eaacf3158100b4c7bd/default.vcl
    sudo cp default.vcl /opt/bitnami/varnish/etc/varnish/default.vcl
    sudo sed -i 's/port = "[^"]*"/port = "80"/g' /opt/bitnami/varnish/etc/varnish/default.vcl

    Test and activate the Varnish service

    • Restart the Varnish Service:
    sudo /opt/bitnami/ctlscript.sh restart varnish
    
    • Go to the Manage Server section and open the "Firewall" tab. Click "Add Custom Firewall Rules", enter the value 81 in the port field and click the "Add" button.
    • Check if your website is served properly by Varnish on port 81 (adding ':81' to the domain in your webbrowser): http://xyz.bitnamiapp.com:81/
      You can use one of the online applications like http://www.isvarnishworking.com
    • If everything works ok, switch Apache and Varnish ports and activate Varnish as your main frontend on port 80:
    sudo sed -i 's/^\s*Listen .*$/Listen 81/g' /opt/bitnami/apache2/conf/httpd.conf
    sudo sed -i 's/\:80/\:81/g' /opt/bitnami/apache2/conf/bitnami/bitnami.conf
    sudo sed -i 's/\:80/\:81/g' /opt/bitnami/apps/*/conf/httpd-vhosts.conf
    sudo sed -i 's/=80/=81/g' /opt/bitnami/properties.ini
    sudo sed -i 's/port\s*=\s*"[^"]*"/port = "81"/g' /opt/bitnami/varnish/etc/varnish/default.vcl
    sudo sed -i 's/VARNISH_PORT=.*$/VARNISH_PORT=80/g' /opt/bitnami/varnish/scripts/ctl.sh
    sudo /opt/bitnami/ctlscript.sh restart
    
    • Finally, remove the Firewall rule added before for port 81 in the Manage Server section.
    Tag page (Edit tags)
    • No tags
    Page statistics
    33907 view(s), 23 edit(s) and 13730 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments

    FileSizeDateAttached by 
     drupal.vcl
    No description
    7.11 kB19:18, 28 Jan 2013DanooActions