diff -rupN bin/passenger-install-nginx-module bin/passenger-install-nginx-module
--- bin/passenger-install-nginx-module	2014-07-22 16:04:26.333005170 +0200
+++ bin/passenger-install-nginx-module	2014-07-22 15:53:01.218528235 +0200
@@ -27,6 +27,7 @@ $LOAD_PATH.unshift("#{passenger_root}/li
 require 'phusion_passenger'
 require 'optparse'
 require 'fileutils'
+require 'tmpdir'
 require 'phusion_passenger/platform_info/ruby'
 require 'phusion_passenger/dependencies'
 require 'phusion_passenger/abstract_installer'
@@ -108,14 +109,12 @@ class Installer < PhusionPassenger::Abst
 	def before_install
 		super
 		myself = `whoami`.strip
-		@working_dir = "/tmp/#{myself}-passenger-#{Process.pid}"
-		FileUtils.rm_rf(@working_dir)
-		FileUtils.mkdir_p(@working_dir)
+		@working_dir = Dir.mktmpdir("passenger.")
 	end
 	
 	def after_install
 		super
-		FileUtils.rm_rf(@working_dir)
+		FileUtils.remove_entry_secure(@working_dir) if @working_dir
 	end
 
 private
diff -rupN lib/phusion_passenger/dependencies.rb lib/phusion_passenger/dependencies.rb
--- lib/phusion_passenger/dependencies.rb	2014-07-22 16:04:26.321005144 +0200
+++ lib/phusion_passenger/dependencies.rb	2014-07-22 15:53:01.219528238 +0200
@@ -22,6 +22,7 @@
 #  THE SOFTWARE.
 
 require 'rbconfig'
+require 'tmpdir'
 require 'phusion_passenger'
 require 'phusion_passenger/packaging'
 require 'phusion_passenger/platform_info'
@@ -117,6 +118,12 @@ module Dependencies # :nodoc: all
 		end
 	end
 
+	def self.create_temp_files(name1, name2, dir = PlatformInfo.tmpexedir)
+		Dir.mktmpdir("passenger.", dir) do |subdir|
+			yield "#{subdir}/#{name1}", "#{subdir}/#{name2}"
+		end
+	end
+
 	GCC = Dependency.new do |dep|
 		dep.name = "GNU C++ compiler"
 		dep.define_checker do |result|
@@ -456,9 +463,7 @@ module Dependencies # :nodoc: all
 	Curl_Dev = Dependency.new do |dep|
 		dep.name = "Curl development headers with SSL support"
 		dep.define_checker do |result|
-			source_file = "#{PlatformInfo.tmpexedir}/passenger-curl-check.c"
-			output_file = "#{PlatformInfo.tmpexedir}/passenger-curl-check"
-			begin
+			Dependencies.create_temp_files("check.c", "check") do |source_file, output_file|
 				found = true
 				File.open(source_file, 'w') do |f|
 					f.puts("#include <curl/curl.h>")
@@ -482,9 +487,6 @@ module Dependencies # :nodoc: all
 					found = false
 				end
 				result.found(found)
-			ensure
-				File.unlink(source_file) rescue nil
-				File.unlink(output_file) rescue nil
 			end
 		end
 		dep.install_instructions = "Please download Curl from <b>http://curl.haxx.se/libcurl</b> " +
@@ -514,22 +516,17 @@ module Dependencies # :nodoc: all
 	OpenSSL_Dev = Dependency.new do |dep|
 		dep.name = "OpenSSL development headers"
 		dep.define_checker do |result|
-			source_file = "#{PlatformInfo.tmpexedir}/passenger-openssl-check.c"
-			object_file = "#{PlatformInfo.tmpexedir}/passenger-openssl-check.o"
-			begin
+			Dependencies.create_temp_files("check.c", "check.o") do |source_file, output_file|
 				File.open(source_file, 'w') do |f|
 					f.write("#include <openssl/ssl.h>")
 				end
 				Dir.chdir(File.dirname(source_file)) do
-					if system("(gcc #{ENV['CFLAGS']} -c '#{source_file}') >/dev/null 2>/dev/null")
+					if system("(gcc #{ENV['CFLAGS']} -c '#{source_file}' -o '#{output_file}') >/dev/null 2>/dev/null")
 						result.found
 					else
 						result.not_found
 					end
 				end
-			ensure
-				File.unlink(source_file) rescue nil
-				File.unlink(object_file) rescue nil
 			end
 		end
 		if RUBY_PLATFORM =~ /linux/
@@ -546,22 +543,17 @@ module Dependencies # :nodoc: all
 	Zlib_Dev = Dependency.new do |dep|
 		dep.name = "Zlib development headers"
 		dep.define_checker do |result|
-			source_file = "#{PlatformInfo.tmpexedir}/zlib-check.c"
-			object_file = "#{PlatformInfo.tmpexedir}/zlib-check.o"
-			begin
+			Dependencies.create_temp_files("check.c", "check.o") do |source_file, output_file|
 				File.open(source_file, 'w') do |f|
 					f.write("#include <zlib.h>")
 				end
 				Dir.chdir(File.dirname(source_file)) do
-					if system("(g++ -c zlib-check.c) >/dev/null 2>/dev/null")
+					if system("(g++ -c '#{source_file}' -o '#{output_file}') >/dev/null 2>/dev/null")
 						result.found
 					else
 						result.not_found
 					end
 				end
-			ensure
-				File.unlink(source_file) rescue nil
-				File.unlink(object_file) rescue nil
 			end
 		end
 		if RUBY_PLATFORM =~ /linux/
diff -rupN lib/phusion_passenger/standalone/command.rb lib/phusion_passenger/standalone/command.rb
--- lib/phusion_passenger/standalone/command.rb	2014-07-22 16:04:26.325005153 +0200
+++ lib/phusion_passenger/standalone/command.rb	2014-07-22 15:53:01.219528238 +0200
@@ -172,8 +172,11 @@ private
 	
 	def write_nginx_config_file
 		require 'phusion_passenger/platform_info/ruby'
-		ensure_directory_exists(@temp_dir)
-		
+		require 'tmpdir'
+		@temp_dir        = Dir.mktmpdir("passenger.", "/tmp")
+		@config_filename = "#{@temp_dir}/config"
+		File.chmod(0755, @temp_dir)
+
 		File.open(@config_filename, 'w') do |f|
 			f.chmod(0644)
 			template_filename = File.join(TEMPLATES_DIR, "standalone", "config.erb")
@@ -213,8 +216,6 @@ private
 	def create_nginx_controller(extra_options = {})
 		require_daemon_controller
 		require 'socket' unless defined?(UNIXSocket)
-		@temp_dir        = "/tmp/passenger-standalone.#{$$}"
-		@config_filename = "#{@temp_dir}/config"
 		if @options[:socket_file]
 			ping_spec = [:unix, @options[:socket_file]]
 		else
diff -rupN lib/phusion_passenger/standalone/runtime_installer.rb lib/phusion_passenger/standalone/runtime_installer.rb
--- lib/phusion_passenger/standalone/runtime_installer.rb	2014-07-22 16:04:26.325005153 +0200
+++ lib/phusion_passenger/standalone/runtime_installer.rb	2014-07-22 15:53:01.219528238 +0200
@@ -23,6 +23,7 @@
 #  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 #  THE SOFTWARE.
 require 'fileutils'
+require 'tmpdir'
 require 'phusion_passenger'
 require 'phusion_passenger/abstract_installer'
 require 'phusion_passenger/packaging'
@@ -164,16 +165,14 @@ protected
 	def before_install
 		super
 		@plugin.call_hook(:runtime_installer_start, self) if @plugin
-		@working_dir = "/tmp/#{myself}-passenger-standalone-#{Process.pid}"
-		FileUtils.rm_rf(@working_dir)
-		FileUtils.mkdir_p(@working_dir)
+		@working_dir = Dir.mktmpdir("passenger.")
 		@download_binaries = true if !defined?(@download_binaries)
 		@binaries_url_root ||= STANDALONE_BINARIES_URL_ROOT
 	end
 
 	def after_install
 		super
-		FileUtils.rm_rf(@working_dir)
+		FileUtils.remove_entry_secure(@working_dir) if @working_dir
 		@plugin.call_hook(:runtime_installer_cleanup) if @plugin
 	end
 
