Deploy Unity & Godot WebGL Games on ANY Web Host

Deploy Unity & Godot WebGL Games on ANY Web Host

In this tutorial we will go through deploying Unity & Godot WebGL games on ANY web host that gives you access to the file system, allows you to upload and edit files in the file system, and allows you to access and edit the .htaccess file (if using apache). This tutorial isn’t designed for non-apache servers. This tutorial should work for most common webhosts such as Hostinger, BlueHost, HostGator, DreamHost, IONOS, etc.

Exporting Your Game for WebGL

Before uploading your Unity or Godot game to the web, you will first need to export it to webgl. I have linked some great tutorials on how to export your Unity and Godot games to webgl below:

Godot Export to WebGL Video: https://www.youtube.com/watch?v=eI0jDvpFh6A

Godot Official Docs: https://docs.godotengine.org/en/stable/tutorials/export/exporting_for_web.html

Unity Export to WebGL: https://www.youtube.com/watch?v=L82geOfpQCQ

The above Godot Export to WebGL video also covers uploading your Godot webgl game to Itch.io . Uploading our webgl games to most web hosts follows an extremely similar pattern.

Uploading the Game Files to a Webhost

Once you have exported your Unity or Godot game to webgl, login to your web host and navigate to the file manager. Once you are inside your host’s file manager, you will need to upload your exported webgl game. This may take a while, depending on upload speed, file size, etc. 

Note: This tutorial does not cover domain configuration, just be sure to either upload the files to your website root or sub directory. With webhosts like Hostinger, Bluehost, etc. they usually handle domain configuration for you, you can either purchase a domain or create a subdomain of an existing domain of yours, then just navigate to the site folder for the domain in the file manager and upload your files there.

.htaccess Config

Once you have the files uploaded we will need to configure the .htaccess file. We will configure the basic security settings and enable caching, the main difference between the htaccess file for unity / godot webgl games and say a WordPress site is that for the webgl games we need to enable the wasm MIME type. Below is a sample .htaccess for your unity / godot webgl game. You can find the same file on github here: https://github.com/Phoenix-Ignited-Tech/htaccess/blob/main/htaccess%20for%20unity%20-%20godot%20webgl%20games

							
							
					# Disable directory listing
Options -Indexes

# Disable server signature (hides server version info)
ServerSignature Off

# Allow only GET and POST methods (deny others like PUT, DELETE, etc.)
<LimitExcept GET POST>
    Order Deny,Allow
    Deny from all
</LimitExcept>

# Protect .htaccess file itself
<Files .htaccess>
    Order Allow,Deny
    Deny from all
</Files>

# Block access to sensitive files (e.g., config, database, source code, etc.)
<FilesMatch "\.(env|json|log|ini|sh|py|sql|bak|psd|htpasswd|htaccess)$">
    Order Allow,Deny
    Deny from all
</FilesMatch>

# Enable caching for static assets (improves load times)
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 year"
    ExpiresByType image/jpeg "access plus 1 year"
    ExpiresByType image/gif "access plus 1 year"
    ExpiresByType image/png "access plus 1 year"
    ExpiresByType text/css "access plus 1 month"
    ExpiresByType text/javascript "access plus 1 month"
    ExpiresByType application/javascript "access plus 1 month"
    ExpiresByType application/x-javascript "access plus 1 month"
    ExpiresByType application/x-shockwave-flash "access plus 1 month"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresByType image/svg+xml "access plus 1 year"
    ExpiresDefault "access plus 1 month"
</IfModule>

# Enable support for WebAssembly (WASM)
<IfModule mod_mime.c>
    AddType application/wasm .wasm
</IfModule>

# Prevent MIME-type sniffing
<IfModule mod_headers.c>
    Header set X-Content-Type-Options "nosniff"
</IfModule>

# Cross-site scripting (XSS) protection
<IfModule mod_headers.c>
    Header set X-XSS-Protection "1; mode=block"
</IfModule>

# Prevent clickjacking
<IfModule mod_headers.c>
    Header always append X-Frame-Options "DENY"
</IfModule>

# Enforce HTTPS (Redirect to HTTPS)
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>

# Enable Gzip compression for faster page loads
<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/x-javascript image/svg+xml
</IfModule>

# Restrict access to specific IPs (Optional, adjust as necessary)
#<RequireAll>
#    Require ip 123.123.123.123
#    Require ip 234.234.234.234
#</RequireAll>				
			

Accessing Your Game

Once you have uploaded your webgl game files to your webhost and configured your .htaccess file, you can access your webgl game online! If you need a little help on how to access your webgl game I’ve included a little info just on that below:

For unity games the file structure looks something like: 

							
							
					Game/
│
├── index.html
│
├── Build/
│   ├── file1
│   ├── file2
│   ├── file3
│   └── ...
│
└── Data/
    ├── file1
    ├── file2
    └── ...
				
			

And for godot games it looks something like: 

							
							
					Game
│
├── Index.apple-touch-icon.png
├── Index.audio.worklet.js
├── Index.html
├── Index.icon.png
├── Index.js
├── Index.pck
├── Index.png
├── Index.wasm
└── Index.worker.js

				
			

The important files here are the Index.html in godot and the index.html file in unity. These are the main web page files. So when accessing your unity webgl game the address url might look like: mysite.com/path/to/myGame/index.html. For godot it might look like: mysite.com/path/to/myGame/Index.html. 

You can change the file names of these files, just remember the address urls will change also, so if you update index.html in unity to myGame.html it would look like: mysite.com/path/to/myGame/myGame.html.

For example let’s say I uploaded my webgl unity game to mysubdomain.mysite.com/games/ I also called my game directory MySuperCoolGame and I renamed my index.html file to MySuperGame.html. The full address URL to access my game would be: mysubdomain.mysite.com/games/MySuperCoolGame/MySuperGame.html.

That’s a wrap, I hope you enjoyed it, and as always let me know your thoughts! Happy Gaming!

Walter Miely is a tech entrepreneur and CEO of Phoenix Ignited Tech You can find him on Linkedin. This material is licensed under the CC BY 4.0 License LEGAL DISCLAIMER: The content provided here is provided AS IS, and part of, or the entirety of this content may be incorrect. Please read the entireLegal Disclaimer here.