This is a quick tutorial to explain how to host GitHub pages locally. GHP is a free web server that allows you to serve GitHub pages locally for testing. Using this web server, you can serve the GitHub pages that you have created with ease. It takes the root path from you where the files for GitHub page you want to host are. After that, it runs a server on the specified port where you can see then pages in action. However, for now, it doesn’t supports Jekyll and compiled markdown based pages. But in the later updates, markdown will be supported.
Using normal web servers for testing GitHub pages is not that efficient. Because there are some issues with absolute paths in links. But in this web server, you won’t face any of those issues. It can serve files even if the file extension is missing in the link. It can intelligently verify if the requested asset is a file or a directory and returns the content accordingly. This is a cross-platform tool and open source as well. If you want to build it from its source code then you can do that.
How to Host GitHub Pages Locally?
To use GHP, you can download its binary for your platform and then start using it. There is a simple command to start the server with given pages. After downloading the binary for your platforms, simply open command prompt there. Also, paste the folder of your GitHub pages site that you want to serve.
Now, to start the server using the command that is given below. By default, it uses the current directory as the server root. But you can specify the a custom path as well. Also, by default, it runs on port 8080. But that is customizable too.
ghp -root "fodler name"
In this way, you can simply use this tool to quickly run and test GitHub pages locally. And this simple server tool helps you do that. There are just a couple of commands you have to use to get the server up and running. And you can see the logs right on the command prompt or terminal window.
Final thoughts
GPH is a good local server tool to test and run GitHub pages locally. You just keep all the files needed for the pages in a root directory and then simply serve them with the help of this tool. So, if you often feel needs to test GitHub pages locally, then you may give this tool a try.