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>

    WP Super Cache

    https://wordpress.org/plugins/wp-super-cache/

    Debugging

    If you have problems configuring WP Super Cache, try to enable Debug mode. Go to the WP Super Cache settings, click on "Debug" and enable the "debugging" option. One you have saved the changes you will find the current log file at the top of the web page. 

    If you have WP-Cache installed

    If you have WP-Cache installed already, please disable it. Edit wp-config.php and make sure the WP_CACHE and WPCACHEHOME defines are deleted, and remove the files installdir/apps/wordpress/htdocs/wp-content/wp-cache-config.php and installdir/apps/wordpress/htdocs/wp-content/advanced-cache.php. These will be recreated when you install this plugin.

    Installation

    Please follow the next steps to install the plugin. 

    1. Download the plugin using the following link: https://wordpress.org/plugins/wp-super-cache/
    2. Upload this directory to your plugins directory. It will create a 'installdir/apps/wordpress/apps/wordpress/htdocs/wp-content/plugins/wp-super-cache/' directory.
    3. If you are using WordPress MU or WordPress Multisite you can install the plugin in the ordinary plugins folder and activate it "network wide".
    4. WordPress users should go to their Plugins page and activate "WP Super Cache".
    5. Now go to Settings->WP Super Cache and enable caching.

    If you choose "Mod Rewrite caching"

    If you want to enable that option, you will have to modify the file at installdir/apps/wordpress/conf/htaccess.conf with the content that the application display when you click on "Update Mod_rewrite rules". You have to block in your htaccess.conf file like this one:

    <Directory "installdir/apps/wordpress/conf">
    # BEGIN WPSuperCache
    <IfModule mod_rewrite.c>
    RewriteEngine On
    ...
    # END WPSuperCache
    </Directory>

    Moreover, you have to add these lines at the bottom of the file

    <Directory "installdir/apps/wordpress/htdocs/wp-content/cache">
    # BEGIN supercache
    <IfModule mod_mime.c>
            <FilesMatch "\.html\.gz$">
            ForceType text/html
            FileETag None
            </FilesMatch>
            AddEncoding gzip .gz
            AddType text/html .gz
    </IfModule>
    <IfModule mod_deflate.c>
            SetEnvIfNoCase Request_URI \.gz$ no-gzip
    </IfModule>
    <IfModule mod_headers.c>
            Header set Cache-Control 'max-age=3, must-revalidate'
    </IfModule>
    <IfModule mod_expires.c>
            ExpiresActive On
            ExpiresByType text/html A3
    </IfModule> `` # END supercache
    </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.

    Memcached

    Memcached is a high-performance, distributed memory object caching system, generic in nature, but intended for use in speeding up dynamic web applications by alleviating database load. This extension uses the libmemcached library to provide an API for communicating with memcached servers.

    If this module is not in your Stack, you can install it manually. These are the steps to install it in an Ubuntu Virtual Machine (if you have installed it using a Native Installer, substitute the paths where /opt/bitnami appears with your installation directory).

    • Install the following packages:
    $ sudo apt-get update
    $ sudo apt-get install build-essential libtool autoconf unzip wget libcloog-ppl1
    • Download the latest source code from the web page, uncompress it and compile the module. I have downloaded the libmemcached 1.0.16 version and the 2.1.0 module version, that are the latest stable and working version at the time this was written.

    After tried to use libmemcached 1.0.17, we received an error message during the compilation:

    libtest/server_container.cc:241: error: 'HAVE_MEMCACHED_BINARY' was not declared in this scope

    This seems to be a bug in that libmemcached version (https://bugs.launchpad.net/libmemcached/+bug/1164440), so we decided to use libmemcached 1.0.16

    $ wget https://launchpad.net/libmemcached/1.0/1.0.16/+download/libmemcached-1.0.16.tar.gz
    $ tar -zxf libmemcached-1.0.16.tar.gz
    $ cd libmemcached-1.0.16
    $ ./configure --prefix=/opt/bitnami/common
    $ make
    $ sudo make install
    $ cd ~/
    $ wget http://pecl.php.net/get/memcached-2.1.0.tgz
    $ tar -zxf memcached-2.1.0.tgz
    $ export PHP_AUTOCONF=/usr/bin/autoconf
    $ export PHP_PREFIX=/opt/bitnami/php
    $ cd memcached-2.1.0
    $ /opt/bitnami/php/bin/phpize
    $ ./configure --enable-memcached --with-zlib-dir=/opt/bitnami/common --with-libmemcached-dir=/opt/bitnami/common --with-php-config=/opt/bitnami/php/bin/php-config
    $ make
    $ sudo make install
    
    • Then, enable the module in the php.ini file:
    ...
    extension=memcached.so
    ...
    
    • If you are on Bitnami Cloud Hosting, you can enable memcache server running this commands:
    mv /opt/bitnami/memcached/scripts/ctl.sh.disabled /opt/bitnami/memcached/scripts/ctl.sh
    /opt/bitnami/ctlscript.sh start memcached
    • If you got an error, check if the Stack bundle memcached server:
    /opt/bitnami/ctlscript.sh status memcached
    
    • Usually, if you don't see "memcached" status, it is because you are using a stack that doesn't bundle memcached server or you are not using Bitnami Cloud Hosting. To install and start it, you must run:
    apt-get install memcached
    /etc/init.d/memcached start
    • Restart the Stack services:
    /opt/bitnami/ctlscript.sh restart
    • Finally, check if memcached is running properly. To do it, create a .php file on your htdocs folder with this code and access to it using the browser:
    <?php
        $mc = new Memcached();
        $mc->addServer("127.0.0.1", 11211);
    
        $result = $mc->get("test_key");
    
        if($result) {
            echo $result;
        } else {
            echo "No data on Cache. Please refresh page pressing F5 ";
            $mc->set("test_key", "test data pulled from Cache!") or die ("Failed to save data at Memcached server");
        }
    ?>

    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. For other custom installations, please use the following guide: https://wiki.bitnami.com/Components/Varnish
     

    IMPORTANT: 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.bitnamiapp.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.

     

    NOTES:

    In the following commands, we suppose that you installed Apache as root. So Apache is configured in port 80 and varnish will be configured in port 81 for testing. If everything is going well, we will switch Apache and Varnish ports and activate Varnish as your main frontend on port 80

    Apache considerations

    • You have to use port 80 (for Apache) in sed commands only if you did the installation as root.
    • You have to use port 8080 (for Apache) in sed commands otherwise.

    Varnish considerations

    • You have to use port 81 (for Varnish) in sed commands only if you did the installation as root.
    • You have to use port 8081 (for Varnish) in sed commands otherwise.

    Other considerations

    • You have to use sudo only if you did the installation with sudo (root installation)
    • If you are using OS X, you need to execute sed -i '' '...' file inside sed -i '...' file

    WordPress

    • Add the WordPress-specific Varnish configuration executing the following commands:

    If you are using Varnish < 4.0

    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

    If you are using Varnish >= 4.0

    wget -O wordpress.v4 http://wiki.bitnami.com/@api/deki/files/1745/=wordpress.v4
    sudo cp wordpress.v4 /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:

    If you are using Varnish < 4.0

    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

    If you are using Varnish >= 4.0

    wget -O drupal.v4 http://wiki.bitnami.org/@api/deki/files/1741/=drupal.v4
    sudo cp drupal.v4 /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

    NOTEYou will need to install git. If you are using a dist based on Debian (e.g. Ubuntu) you should do 

    sudo apt-get install git
    • Add the Magento-specific Varnish configuration executing the following commands:
    bash < <(curl -s https://raw.githubusercontent.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

    If you are using Varnish < 4.0

    wget https://raw.githubusercontent.com/mursalat92/magneto-varnish/master/magento-varnish3.vcl
    sudo cp 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

    If you are using Varnish >= 4.0

    wget -O magento.v4 http://wiki.bitnami.com/@api/deki/files/1743/=magento.v4
    sudo cp magento.v4 /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

    NOTEYou will need to install git. If you are using a dist based on Debian (e.g. Ubuntu) you should do 

    sudo apt-get install git
    • Add the Ghost-specific Varnish configuration:

    If you are using Varnish < 4.0

    wget -O ghost.vcl https://gist.github.com/lkarsten/6683179/raw/3d03b14b3a3ca1301a2397eaacf3158100b4c7bd/default.vcl
    sudo cp ghost.vcl /opt/bitnami/varnish/etc/varnish/default.vcl
    sudo sed -i 's/port = "[^"]*"/port = "80"/g' /opt/bitnami/varnish/etc/varnish/default.vcl​​

    If you are using Varnish >= 4.0

    wget -O ghost.v4 http://wiki.bitnami.com/@api/deki/files/1742/=ghost.v4
    sudo cp ghost.v4 /opt/bitnami/varnish/etc/varnish/default.vcl
    sudo sed -i 's/port = "[^"]*"/port = "80"/g' /opt/bitnami/varnish/etc/varnish/default.vcl

    PrestaShop

    • Add the PrestaShop-specific Varnish configuration:

    If you are using Varnish < 4.0

    wget -O prestashop.vcl https://wiki.bitnami.com/@api/deki/files/1499/=prestashop.vcl
    sudo cp prestashop.vcl /opt/bitnami/varnish/etc/varnish/default.vcl
    sudo sed -i 's/port = "[^"]*"/port = "80"/g' /opt/bitnami/varnish/etc/varnish/default.vcl​​

    If you are using Varnish < 4.0

    wget -O prestashop.v4 https://wiki.bitnami.com/@api/deki/files/1744/=prestashop.v4
    sudo cp prestashop.v4 /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

    • Enter to the Bitnami installation directory (e.g. /opt/bitnami -root installation- or  /home/user/bitnami -user installation-):
    cd /opt/bitnami
    • Restart the Varnish Service:
    ./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' apache2/conf/httpd.conf
    sudo sed -i 's/\:80/\:81/g' apache2/conf/bitnami/bitnami.conf
    sudo sed -i 's/at port.*"/at port 81"/g' apache2/scripts/ctl.sh
    sudo sed -i 's/\:80/\:81/g' apps/*/conf/httpd-vhosts.conf
    sudo sed -i 's/=80/=81/g' properties.ini
    sudo sed -i 's/port\s*=\s*"[^"]*"/port = "81"/g' varnish/etc/varnish/default.vcl
    sudo sed -i 's/VARNISH_PORT=.*$/VARNISH_PORT=80/g' varnish/scripts/ctl.sh
    sudo ./ctlscript.sh restart
    
    • Finally, remove the Firewall rule added before for port 81 in the Manage Server section.

     

    IMPORTANT: Varnish does not cache the content if Apache PageSpeed module is enabled. Please check how to disable this module here.

     

    IMPORTANT: If you are going to execute bnconfig utility, you should change server port back to 80 (or 8080) in properties.ini while running the utility. Then set back port 81 (or 8081) in order to configure the server correctly.

    sudo sed -i 's/=81/=80/g' properties.ini
    sudo apps/your_app/bnconfig --option parameter
    sudo sed -i 's/=80/=81/g' properties.ini
    sudo ./ctlscript.sh restart

     

    Tag page (Edit tags)
    • No tags
    Pages that link here
    Page statistics
    71140 view(s), 47 edit(s) and 25166 character(s)

    Comments

    You must login to post a comment.

    Attach file

    Attachments

    FileSizeDateAttached by 
     drupal.v4
    Varnish 4.1 vcl file for Drupal
    6.91 kB10:21, 20 Oct 2015jdriosActions
     drupal.vcl
    No description
    7.11 kB19:18, 28 Jan 2013DanooActions
     ghost.v4
    Varnish 4.1 vcl file for Ghsot
    1554 bytes10:21, 20 Oct 2015jdriosActions
     magento.v4
    Varnish 4.1 vcl file for Magento
    5.37 kB10:21, 20 Oct 2015jdriosActions
     prestashop.v4
    Varnish 4.1 vcl file for PrestaShop
    1443 bytes10:21, 20 Oct 2015jdriosActions
    prestashop.vcl
    PrestaShop default Varnish configuration
    1305 bytes08:24, 23 Jul 2015jorgeActions
     prestashop.vcl.txt
    PrestaShop default Varnish configuration
    1410 bytes08:19, 23 Jul 2015jorgeActions
     wordpress.v4
    Varnish 4.1 vcl file for Wordpress
    1631 bytes10:21, 20 Oct 2015jdriosActions