All posts by Ramesh Jha

Optimize WordPress for Speed – In 5 simple steps

Improving the load time for a wordpress blog has lots of benefits – good user experience (faster page loads also results in more pageviews), better rankings in search engines (SEO), reduced cost (due to reduction in resource (RAM, CPU, cycles and bandwidth) usage) etc.

So, if you run a wordpress blog/website that needs a little optimization you should follow this guide. But you need root access to your server. If you’re on a shared server, then first things you should do is move to a VPS; it’s cheap, faster and more secure and you also get full control over the server environment.

I’m using Digital Ocean for this blog and I’m pretty happy with the performance (read my review on digital ocean and the article about setting up wordpress on vps server). They’ve plan starting at $5/mo, cheaper than most of the shared hosting providers. Signup using my referral link and get 2 months of free hosting – $10 credit to give it a try.

speed up wordpress

Step 1. Enable Caching

Caching static resources such as images, css, js etc on the browser helps in reducing page load time on subsequent page visits.You can enable browser caching either using a plugin or manually. If you’re using Apache, then you can skip this step as Hyper Cache will do that for you (using htaccess config).

Caching static content (browser)
Login to your server(over ssh) and type (I assume you’re using Ubuntu or any debian derivative for OS with nginx as the web server, otherwise change command accordingly) :

sudo nano /etc/nginx/sites-available/site.conf

Add these lines to enable browser caching with nginx.

Save the file (Ctrl x and y) and reload the nginx server to apply above configuration.

sudo service nginx reload

PHP caching If you’re using lots of plugin then the php code will take lots of time and resources to execute, that means server response time will be high (not a good thing). So, caching php code means – the server will send cached html instead of generating it on every single request (which is lot faster). As a result, the server response time (as well as TTFB (Time to First Byte)) will go down (that means faster page load, even on first visit). To enable php caching there are lots of ways, the most simple way is to use HyperCache plugin. (Disable browser caching or compression if you’ve already done that manually with nginx) Download HyperCache plugin for wordpress and enable/activate it. (you can do it from wordpress dashboard or by manually extracting the file on server)

Step 2. Enable Compression

Sending compressed data over the network means faster download time for pages, plus you’ll save bandwidth for server and user as well. All modern browser supports compression, so there is no reason why you shouldn’t be using it. SSH into to the server and type :

sudo nano /etc/nginx/nginx.conf

And add these lines to nginx config. (you may want to tweak few variables like compression level etc depending on your need, if you’re not sure, then just go with the default value)

Save the file (Ctrl x and y) and reload the nginx server to apply above configuration.

sudo service nginx reload

Step 3. Move JS to Footer

By default, most of the WordPress themes load javascript files in header and it causes render blocking issue. The browser will not start rendering the page until all the javascript files are downloaded. Moving those js files (jquery etc) to bottom of the page (before body tag) will have good impact on page loading time, especially if you use lots of js plugins.

To move the javascript to footer, simply download and install this plugin and clear the cache from wordpress dashboard -> Settings -> Hyper Cache page.

Step 4. Use CDN for jQuery

Using CDN for jquery has many advantages. It reduces load/bandwidth on your server, low latency for users (since the jquery will be downloaded from the CDN end point near to your user, that means faster download) and lots of other people use it, So, it may be already cached in user’s browser (best case). First you need to find out the jquery version you are using, so you can specify exact version from below.

  • For jquery : Google CDN
  • For jQuery migrate :  jQuery CDN

To use above CDN, just add these lines to your theme’s functions.php (at the end) and clear the cache (if you’re using any caching). Don’t forget to correct jquery version if required. (you can edit it using wordpress dashboard -> Appearances -> Editor but make sure you’ve already created a backup for theme files, in case anything goes wrong.)

Step 5. Image Optimization

Optimizing images is important because it’s usually the most heavy static resource on a web page. So, if you use lots of images in your blog pages/articles, then you should :

  • Optimize images before upload (use an online tool like this one : https://tinyjpg.com/). You can also use some plugins like this one. (BTW, I haven’t used them but it seems good)
  • Avoid scaling/resizing a big bulky image after page load. Scale images to the required size before you upload them or use this plugin – Imsanity
  • And you can also use imgur or Dropbox to host your images. (it will act as CDN)

Gnome 3.12 is released!

Gnome 3.12 is released with lots of new features, improvements and bug fixes. It’s a great news for those who’re stuck with the default desktop environment : Unity. Gnome experience is becoming better with every major release (with 3.*). The default text editor gedit, got lots of design changes; Now, the UI is more clean and minimal.

This video quickly explains all the exciting stuffs in Gnome 3.12.

What’s new in Gnome 3.12 ?

  • Now, it’s much easier to find/install applications
  • UI improvements for gedit/video applications
  • Better support for high resolution display
  • App startup time has improved
  • More efficient at handling resources
  • Folders, that lets you organize apps

Read official announcement at gnome.org

Deploying Ruby on Rails Application to OpenShift PaaS

OpenShift is a Platform as a Service (PaaS) from RedHat. It’s great for deploying web applications as you can setup/scale/manage apps quickly without any hassle, just like Heroku, but the OpenShift platform is available as a free and open source software, so you’re not locked in (you can install OpenShift on your server and create your own private PaaS if you want).

Previously, I’ve already written on various deployment options available for a rails application, also on deploying rails app to vps. In this article, I’ll guide you in deploying your Rails application to OpenShift.

Step 1. OpenShift Setup

First of all, Create a free Account. You get 3 small gears (resource container/unit : one small gear is equivalent to 512 MB RAM and 1GB storage) for free. If you need more, you can upgrade to premium plans.

Install rhc tool

gem install rhc

Note : If you use rbenv for managing ruby then you also need to run `rbenv rehash`.

rhc_setup

create token and upload public keys

rhc setup

And follow the instructions. Once the setup is completed, you can easily create/manage your apps using this client utility (rhc).

Just type :

rhc

to see available options. If you want to see all the cartridges (application environment e.g ruby, php, python etc) available, just type :

rhc cartridges

Create a Ruby on Rails App [openshift]
Run this command from the parent directory of your project (~/parent_directory/project) or it will create a directory inside your app.

Note : joblee is the name of the Rails app we’re going to deploy. So, replace it with the name of your app. And I assume you’re using Postgresql for database.

rhc app create ruby-1.9 -a joblee

Add database cartridge

rhc cartridge add postgresql-9.2 -a joblee

Add ‘pg’ to your Gemfile. And run bundle install. Although, you’ll receive database details in the end (above command) but it’s a better to use openshift environment variables in database.yml. So, update the database.yml accordingly. Something like this one : production config for database.yml (openshift)

Step 2. Preparing the application for deployment

Once the openshift is setup, move to your project directory and setup git push deployment for your app. rhc show app rails

cd joblee
rhc show-app joblee

And get the value of Git URL from the above command. Now, add the remote url for deployment. (replace GIT_REMOTE_URL with the value you got above)

git remote add openshift GIT_REMOTE_URL

Now, merge the remote repo with your development repo.

git pull openshift master

Then, you need to manually fix conflict in config.ru. Keep the default content of config.ru file.

 git add .
 git commit -am "fixed merge and now getting ready for deployment"

Step 3. Deploy

git push openshift master

That’s all :-). Now, your app should be live at : http://your_app_name-domain.rhcloud.com.

Note : If anything goes wrong, you can always ssh into your app server and fix things there. To ssh into your server, type :

rhc ssh joblee

Managing apps
ssh into the app server and type

ctl_app

to see lots of options available. You can also get rails console, just by typing :

cd app-root/repo
bundle exec rails console RAILS_ENV=production

Postgresql Database Setup

cd app-root/repo
RAILS_ENV=production rake db:setup

Assets compilation problem
I had to run few other commands on server due to some gems/assets related problems. But you can add it to openshift deployment hooks like this example rails app, so you won’t have to manually execute it every time you deploy the app.

RAILS_ENV=production bundle
RAILS_ENV=production bundle exec rake assets:precompile

Adding Custom Domain
First, add openshift app url (app-domain.rhcloud.com) as a cname record for www and the IP Address 174.129.25.170 (using the free redirection service) for root record. So, it will redirect root domain to www version.

Now, register that domain with rhc server.

rhc alias-add joblee www.joblee.in

If you don’t want to use www domain, then you should type this instead : (and you also need to add cname record for root domain, at your domain registrar)

rhc alias-add joblee joblee.in

Note : I’ve setup naked domain so, www version of the domain is getting redirected(301) to the root domain. Not all DNS providers supports this (I’m using namecheap and I can specify openshift app url as a CNAME record for the root record) and sometimes it can cause some weird behaviours, especially if you’re using email with the domain. (read more on how it can break MX records)

uGet – The Best Download Manager for Ubuntu/Linux

uGet is a free and open source software for managing file downloads (over HTTP/S, FTP etc). It’s the most popular download manager program for GNU/Linux distributions such as Debian, Ubuntu, ArchLinux, Gentoo etc. It’s also available for Windows. uGet is lightweight but still a very powerful download manager.

uget ubuntu

Features

  • Downloads queue
  • Resumable downloads (not always, as it depends on server)
  • Batch downloads
  • Clipboard monitor
  • Also supports multiple protocols (http/https, ftp, bittorrent, metalink etc)
  • Categories to easily manage downloading files
  • CLI interface for geeks/nerds
  • Download history management
  • Multiple language support
  • Scheduler & lots of other features you can read here.

Download/Install uGet

On Ubuntu (I’ve tested on current LTS release (12.04) but it should work fine on other versions as well. e.g on upcoming Ubuntu 14.04 LTS release), open a terminal and type :

sudo add-apt-repository ppa:plushuang-tw/uget-stable
sudo apt-get update
sudo apt-get install uget

For any other Linux distribution or platforms you should check out the official download page.

Also check out this web based tool for downloading SoundCloud songs.

Krita – Digital Painting Application for Ubuntu/Linux

Krita is a KDE based program for digital painting and sketching. Currently, it’s available for GNU/Linux and Windows platforms. It’s a full featured digital painting program for artists.

Krita is popular among comic book artists, illustrators, concept artists, texture painter and so. One of the great feature is that – it supports colorspaces other than RGB, such as CMYK. It also supports HDR Painting and a perspective grid.

krita screenshot
Sound of the Forest (Artist : Tyson Tan)

Installing Krita on Ubuntu

On Ubuntu, you can easily install from the recommended official ppa. (there are few more ppa available on official site but I’ve listed only the stable one)

sudo add-apt-repository ppa:kubuntu-ppa/backports
sudo apt-get update
sudo apt-get install krita

If you’re looking for some tutorials or guides to get started, I would recommend watching this video on youtube and reading docs here.