The issue was that wkhtmltopdf was executing a shell script to determine the version of the binary to use which failed because apache has no shell (and for good reason). The solution was to set the binary explicitly.
Since our dev, staging, and prod environments vary, we created a RBConfig script that is executed within the rails app (no shell access necessary):
require 'rbconfig'
if RbConfig::CONFIG['host_os'] =~ /linux/
arch = RbConfig::CONFIG['host_cpu'] == 'x86_64' ? 'wkhtmltopdf_linux_x64' : 'wkhtmltopdf_linux_386'
elsif RbConfig::CONFIG['host_os'] =~ /darwin/
arch = 'wkhtmltopdf_darwin_386'
else
raise "Invalid platform. Must be running Intel-based Linux or OSX."
end
WickedPdf.config = {
exe_path: "#{ENV['GEM_HOME']}/gems/wkhtmltopdf-binary-#{Gem.loaded_specs['wkhtmltopdf-binary'].version}/bin/#{arch}"
}
There are several other ways to do this. For example, developing locally, your user should have shell access, in which case you really only need to set the binary explicitly for your production environment:
if Rails.env.production?
WickedPdf.config = { ... }
end
Or, as we have done, set up our chef configuration to set up all of our environments with the proper binaries. It also let us make sure all the fonts that we need were installed for production.