Did everybody miss this? Holy cat whiskers batman!
Get rid of HostGator and find a real host if that's what they gave you. It's not 1986 any more
In actuality, if you have HG then you have a cPanel, and in cPanel you should be able to change your PHP version. At the very least set it to version 5.6 but it's perfectly ok to get on 7.0 or greater now. Especially since you are writing your own code.
I don't think the version was your problem, but there is no reason to learn to code and build something on 5.4! Have HG change your version and then make sure PHP is set as a handler for *.php files, which your files should be. And that "index.php" is pretty much your main entry point.
If stuff between PHP tags is "being ignored", it could be you aren't outputting anything in the first place? Or there is an error that is silently failing, showing you nothing (hence you need to change error reporting options).
You can also create a file in your root folder and just call it "phpinfo.php" and then insert the code:
And then access this file from the URL of your domain. "mynewdomain.com/phpinfo.php". And see if it works. By all means, it should. If not, it's your HostGator configuration and you should hop on their live chat and tell them about it.