I ran into SOOO many issues while learning to host websites on the ICP, despite being quite experienced in building & hosting traditional websites, so I decided to document everything I encountered and created this site/tool to make things easier for the next person (runs 100% inside your browser--no data collected).
The Basic Concept: After your website/page is created and ready, create a new canister on the ICP NNS, create necessary files and proper project folders, then in your computer's Bash terminal (standard on MAC, installable on Windows) download and install DFX from Dfinity which is the tool for uploading your local web files to your canister on the ICP. Finally, you would setup your custom domain name to connect to the canister with advanced DNS settings. There will be a lot of little details involved, and I will cover everything step by step!
Create your website/page with HTML, your favorite WYSIWYG editor, or even with ChatGPT! Just make sure to have your web files tested locally and ready to go (html, image files, css, js, etc.). Make sure it is static, which means it doesn't require server-side backends/databases. Try my FAST AI website generator to create a simple multi-page website on any topic if you like!
Navigate to https://nns.ic0.app and sign in with your Internet Identity (or create one now). Click the profile icon (top right). Go to "Canisters", create and fund one with the required 2T cycles (barely a few dollars in ICP), then copy the canister name & ID for the next step.
Now we need some domain related files to be created and configured. They will also be placed in the appropriate folder structures.
You're about to download a complete project package pre-configured for Internet Computer deployment. This zip file will contain:
canister_ids.json
, dfx.json
and .ic-assets.json
files in the project root folderic-domains
that sits inside a newly created folder ".well-known" which sits inside the "assets" folderWhen you click "Download", you'll receive a zip file containing all the files we just created in all the proper folder structures. Just extract and drop all the files into your project folder on your computer.
Next, drop all your website related files (index.html, etc.) into the "assets" folder.
Here's an example of what the directory structure may look like inside your project folder:
βββ .ic-assets.json
βββ assets
βΒ Β βββ .well-known
βΒ Β βΒ Β βββ ic-domains
βΒ Β βββ app.js
βΒ Β βββ styles.css
βΒ Β βββ image.png
βΒ Β βββ index.html
βββ canister_ids.json
βββ dfx.json
Now that you've downloaded the project structure, follow these steps to run terminal on your computer:
Open Terminal on your local computerOpen Terminal by:
Navigate to your project folder:
cd /users/username/desktop/project_folder
Since Windows do not come preinstalled with native Bash (Bourne Again SHell), we now need to install Windows Subsystem for Linux (WSL) in order to have Bash for upcoming steps. Use the following command in terminal/PowerShell to install WSL:
wsl --install
After installation is complete you'll be asked to reboot your computer. After rebooting, open terminal/PowerShell again and run wsl --install again and it will download and install the WSL instance Ubuntu. When this finishes you are ready to run WSL for the first time:
wsl
You will now be asked to create a new Unix user account and a password. After doing so, the installation is complete, you are in the WSL/Bash environment! Now navigate to your project directory using the commands below:
cd /mnt/c/users/YOURUSERNAME/PROJECTFOLDERNAME (or wherever your project folder is located)
pwd
Print current directory pathls
List files and directories in current locationcd ..
Move up one directory levelcd /
Move to root directorycd ~
Move to home directorycd foldername
Move into a specific folder*** You only have to install DFX once. For subsequent deloyments you just need to make sure you are in your Bash terminal environment, where you'd start DFX and then use DFX to deploy your site. See commands in step 6 of this section.
sh -ci "$(curl -fsSL https://internetcomputer.org/install.sh)"
Be sure to exit out of the current terminal (type 'exit') and restart it again so that DFX will take effect (open powershell and run wsl again). Now we can check if DFX is working with the following command:
dfx identity get-principal
When you run this command, DFX will create default as the user name of the identity. At the end of the output, you'll see a long identity string separated by dashes. This is your Principal ID for the default user. Make sure to copy this entire Principal ID for the next step.
Example output might look like: abc123-def456-ghi789-xyz...
After obtaining your Principal ID, go back to the Internet Computer Network Nervous System (NNS) website:
This step is crucial to allow your local DFX to have access and deploy to the canister.
This command starts the DFX server in the background, creating a local environment needed for deployment. It ensures the server is running and ready for subsequent deployment steps.
dfx start --clean --background
Now that DFX is running, the next line of code will deploy your local web files in the "assets" folder to your Internet Computer Canister.
dfx deploy --network ic --no-wallet
*** If you didn't get the canister URL toward the end of the long deployment resonse and encountered permission related errors, you likely need to grant specific permissions to that principal ID.
This usually only happens to additional canister controller IDs being used to deploy your site when you are using another device/computer to deploy to a canister which has different principal IDs. Use the tool below to generate the commands needed:
dfx canister call --network ic <your_canister_id> grant_permission '(record {permission = variant {Commit}; to_principal = principal "<your_principal_id>"})'
dfx canister call --network ic <your_canister_id> grant_permission '(record {permission = variant {Prepare}; to_principal = principal "<your_principal_id>"})'
When you want to make changes to your website:
Helpful commands for managing your DFX identities:
dfx identity list
- Shows list of IDsdfx identity new <user_name>
- Adds a new identity name (will ask you to setup password)dfx identity use <user_name>
- Select the specific user name to be used instead of defaultdfx identity get-principal
- Shows current user name/identify's principal IDWant to use your own custom domain with your Internet Computer hosted website?
If you completed the domain configuration earlier in this process and downloaded the project structure, you're already partway there!
Log into your domain registrar's control panel (e.g., GoDaddy, Namecheap, Google Domains).
In the advanced or custom DNS settings, add these three records:
Type | Host | Value | TTL |
---|---|---|---|
ALIAS Record | @ | mydomain.com.icp1.io | Automatic |
CNAME Record | _acme-challenge | _acme-challenge.mydomain.com.icp2.io | Automatic |
TXT Record | _canister-id | my-icp-canister-id-cai | Automatic |
After configuring DNS records, run the following command in your terminal:
curl -sL -X POST -H 'Content-Type: application/json' https://icp0.io/registrations --data '{"name": "mydomain.com"}'