High Performance LAMP based Wordpress on DigitalOcean

Here are some tips and tricks I have found that make Wordpress run very fats on a $10 Digital Ocean droplet.

  1. Setup Cloudflare via this article: Setup CloudFlare
  2. Setup Redis via this article: Server Optimization#Redis
  3. Setup your OpCache via this article: Server Optimization#OpCache
  4. Run the following:

    sudo a2enmod expires
    sudo a2enmod headers
    sudo a2enmod ext_filter
  5. If you are using GIT on digitalocean, add this to your gitignore:

    # Ignore paths that contain user-generated content.
    /wp-content/ai1wm-backups
    /wp-content/cache
    /wp-content/uploads/
    /wp-content/w3tc-config/
    /wp-content/advanced-cache.php
    /wp-content/db.php
    /wp-content/object-cache.php
    
    #htaccess for w3tc
    .htaccess
    
    
  6. Install the community version of  W3 Total Cache
    1. Go into your dashboard then Performance.
    2. Under General do the following:

      Page Cache – ENABLE
      Minify – DISABLE
      Opcode Cache - set to Zend OpCache
      Database Cache – ENABLE (set to disk)
      Object Cache – ENABLE (set to Redis)
      Browser Cache – ENABLE
      CDN – DISABLE
      Reverse Proxy – DISABLE
      Monitoring – NO ACTION
      Debug – DISABLED
    3. Under Page Cache do the following:

      Cache posts page = CHECKED
      Don't cache front page = NOT CHECKED
      Cache feeds: site, categories, tags, comments = CHECKED
      Cache SSL (https) requests = CHECKED
      Cache URIs with query string variables = NOT CHECKED
      Cache 404 (not found) pages = NOT CHECKED
      Don't cache pages for logged in users = CHECKED
      Don't cache pages for following user roles = NOT CHECKED
      1. Scroll Down to Cache Preload
        1. Check Automatically prime the page cache && Preload the post cache upon publish events

    4. Under Browser Cache, do the following:
      1. Check everything in General BUT: 
        1. Set W3 Total Cache header
        2. Prevent caching of objects after settings change 
        3. Do not process 404 errors for static objects with WordPress 
        4. Rewrite URL structure of objects

    5. Go to Extensions, do the following:
      1. Deactivate everything but CloudFlare & Yoast (if using Yoast, which you shoud!)
      2. Click on settings on Cloudflare
        1. Enter your API key and all your settings from Cloudflare should come over.  
          1. Make sure you have minify setup (which was in the other wiki on Cloudflare)
  7. On the server, add this to your .htaccess

    <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
        Header set Cache-Control "max-age=290304000, public"
    </FilesMatch>
    
    <IfModule mod_expires.c>
        ExpiresActive On
        ExpiresByType image/jpg "access 1 year"
        ExpiresByType image/jpeg "access 1 year"
        ExpiresByType image/gif "access 1 year"
        ExpiresByType image/png "access 1 year"
        ExpiresByType text/css "access 1 month"
        ExpiresByType text/html "access 1 month"
        ExpiresByType application/pdf "access 1 month"
        ExpiresByType text/x-javascript "access 1 month"
        ExpiresByType application/x-shockwave-flash "access 1 month"
        ExpiresByType image/x-icon "access 1 year"
        ExpiresDefault "access 1 month"
    </IfModule>
    
    
    
  8. Add the Autoptimize plugin
    1. Go to Settings → Autoptimize
    2. Check Optimize JS Code?
      1. Check Also aggregate inline JS?
      2. Remove all entries from: Exclude scripts from Autoptimize:
    3. Check Optimize CSS Code? 
      1. hit the show advanced settings at the top
      2. Uncheck everything except Inline all CSS?
      3. Save Changes and Empty Cache
  9. Move google fonts to footer:
    1. Do a view page source on your site.
      1. Search for 'https://fonts.googleapis.com and grab the id of the stylesheet
        1. i.e: <link rel='stylesheet' id='tp-open-sans-css'  href='https://fonts.googleapis.com/css ...
      2. Put this in your functions.php (use the id without the -css)

        /**
         * Remove Google font files from header.
         */
        function remove_google_fonts_header() {
          wp_dequeue_style( 'tp-open-sans' );
          wp_dequeue_style( 'OTHER-GOOGLE-FONT-ID' );
        }
        add_action( 'wp_enqueue_scripts', 'remove_google_fonts_header', 20 );
        
        /**
         * Add google fonts to footer.
         */
        function add_google_fonts_footer() {
          wp_enqueue_style( 'tp-open-sans' );
          wp_enqueue_style( 'OTHER-GOOGLE-FONT-ID' );
        };
        add_action( 'get_footer', 'add_google_fonts_footer', 21 );