How to deploy a HTML5 game on Apache?

I have packaged a game on HTML5 and it works fine when using the HTML5LauncherHelper.exe.

However I then uploaded everything to my web server and couldn’t get it to work.

Sometimes I would get a 500 internal server error, probably because of a bad .htaccess file edit.

Sometimes the page would load but the game wouldn’t work. It says in a red rectangle in the middle, “Uncaught Syntax Error: Unexpected token ILLEGAL”, and the log stops at “downloading symbols file”.

So this is overall very confusing, I have absolutely no knowledge of .htaccess files, http.conf, apache, etc. So how do I properly edit the htaccess to get it working, in a very noob language please?

By the way: the documentation seems to be very outdated: we no longer need to dowload emscriptem, python, etc. Also it needs info on how to deploy for the web.


Hey Ixiguis,

After packaging the HTML5 project, you can simply upload the folder itself onto the website. So for example, c:\builds\VehicleAdvanced\HTML5*.* can be uploaded to your webserver, for example: to /var/www/html/name/games/VehicleAdvanced/HTML5/.

You may want to upload your project and provide the link to us.

Simply uploading the game to my webserver causes that “Unexpected token ILLEGAL” error. See here:

I suppose I have to add a .htaccess file to enable gzip, as per the Readme.txt generated in the packaged folder, but I don’t know what to put in place of ${SRVROOT}.

Within the SRVROOT, you should be adding the server root. Please look at this AnswerHub post for a more visual explanation.

I tried adding this to .htaccess:

<Directory "/home/magiados/public_html/game">
   AddEncoding gzip gz

I am now getting a 500 internal server error.

Also tried the following folder: /home/magiados/

I don’t really know what the folder is… All I know is that in cPanel, the initial directory says “/home/magiados” and in the FileManager, the path to the game is “public_html/game”.

Please upload a screenshot of your cPanel showing your files. We simply need to know how your file structure looks.

We’d also like you to try removing the .htaccess file temporarily and see what the page looks like while it’s being loaded.

Once you’ve gotten this information to us, the screenshot and removal of the .htaccess file, we should be able to provide you additional steps to resolve this issue.

By the way, which version of Apache are you using?

In cPanel (main window), it says:

Main doman:

Initial directory: /home/magiados

File manager screenshot:

If I remove .htaccess I get this:

A few seconds later it changes to this:

And stays like that.

Regarding apache version… I tried several methods to discover it but nothing worked. My cPanel doesn’t show server status, phpinfo is blocked by my host, and I have no root access. So I guess the only way is asking them, I opened a ticket, but it could take a while.

Oh, they were quick :open_mouth:

It is Apache/2.4.16

Also according to my host’s tech support, the path I entered in .htaccess is correct: home/magiados/public_html/game.

They also said the “zip extension” is enabled and activated on the server (maybe they meant gzip, maybe not, I don’t know if there’s a difference).

Thanks for providing me with this information. We will contact you as soon as we have additional information. Thank you!

Thank you for your patience.

We keep getting a server 500 error. This means that it’s a server side configuration issue. We believe that it could be the .htaccess file.

However, we also noticed this:

<Directory "/home/magiados/public_html/game">
    AddEncoding gzip gz

needs to be changed to:

<Directory "/home/magiados/public_html/game">
    AddEncoding gzip .gz

Once you’ve made changes to the code, could you please let us know the progress you’ve made?



Unfortunately, no progress. I changed the htaccess file and the same thing happens, server error 500.

Got it working! I had the server 500 error as well as a bunch of other ones.

Changed the .htaccess file to this;

<files *.gz>
AddType "text/javascript" .gz
AddEncoding gzip .gz

No directory required!

Courtesy of Froffs at the forums; Html5 SimpleHTTPServer how to run another server? - Platform & Builds - Unreal Engine Forums

YESSS this is it!! Thanks!

Samantha, you know that Readme.txt that is generated on the packaged game folder? It needs to be updated with this information! :slight_smile:

Also remember to update the documentation (we no longer need to download emscriptem / python).

Thanks a lot for this!

As of some version between 4.9 and 4.23, packaged game extensions for compressed files have changed, so this is the .htaccess code that works for my server (the one from the previous reply doesn’t any longer):

<IfModule mod_headers.c>
    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\gz" -s
    RewriteRule "^(.*)\.css" "$1\.cssgz" [QSA]

    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\gz" -s
    RewriteRule "^(.*)\.js" "$1\.jsgz" [QSA]

    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\gz" -s
    RewriteRule "^(.*)\.data" "$1\.datagz" [QSA]

    RewriteCond "%{HTTP:Accept-encoding}" "gzip"
    RewriteCond "%{REQUEST_FILENAME}\gz" -s
    RewriteRule "^(.*)\.wasm" "$1\.wasmgz" [QSA]

    # Serve correct content types, and prevent mod_deflate double gzip.
    RewriteRule "\.cssgz$" "-" [T=text/css,E=no-gzip:1]
    RewriteRule "\.jsgz$" "-" [T=text/javascript,E=no-gzip:1]
    RewriteRule "\.wasmgz$" "-" [T=text/javascript,E=no-gzip:1]
    RewriteRule "\.datagz$" "-" [T=text/javascript,E=no-gzip:1]

    <FilesMatch "(\.jsgz|\.cssgz|\.wasmgz|\.datagz)$">
      # Serve correct encoding type.
      Header append Content-Encoding gzip

      # Force proxies to cache gzipped & 
      # non-gzipped css/js files separately.
      Header append Vary Accept-Encoding