Two ways to host a website on remote server (for static and dynamic website)

How to host a website on a remote server? First of all, remote server refers to server that can be accessed by a group of team which requires an URL. For example: https://syahirahnsmn.github.io/ (this is static web page hosted on github)

There are many ways to do so & there are many web hosting provider as well.


One of the ways is by using github which need some simple steps:

*note: this is only for static website (doesnt require database)

(1) Host on github (url: username.github.io)


Another way I found is by hosting the website on Heroku by connecting the Heroku profile to github. The steps are as below:

*note: this is suitable for dynamic website that requires database connection [reference: https://www.youtube.com/watch?v=I4Ra-80O3R4]

(1) Set up a Heroku account and connect to a github repository

(2) Git commit project from any IDE (I am using VS Code) from github desktop -> push to github

(3) Deploy the github repo manually on Heroku

*note: usually the main page should be named as: index.php 

(Heroku does not recognize html file)

(4) The website url will be displayed (if there is no error)

To connect this web server to database:

*note: this database here refers to MySQL

(5) Make sure to have MySQL Workbench installed in your computer

(6) Create a new database on remotemysql.com (username, server, and password will be generated for you)

(7) Double click on the new created database -> it will enter MySQL Workbench

(8) Export database file from phpMyAdmin (localhost) and copy the SQL from the downloaded file & paste it in MySQL Workbench query

(9) The query will generate the required tables on "schemas" tab which can be found on the left side (if there is no error - i once encountered an error but i simply solved it by uninstall the workbench and install it again)

(10) Go to your connection (.php) file to the website page - mine is connection.php

(11) Replace the server/host, username and password with the one generated in remotemysql.com

For example:

// Remote database connection

$servername = "remotemysql.com";

$user = 'username';

$pass = 'password';

$db = 'database';

(11) Deploy the new updated php file in Heroku (don't forget to git and push from github desktop)


Comments

Popular posts from this blog

How to: Display Data from SQL Database in HTML Table - Bootstrap 5

HTML5: HTML Tags

How to: Display Data from Database in Pagination