How to Deploy a Website for FREE with Cloudflare Pages
While GitHub Pages is a fantastic option, another top-tier, free hosting service for developers is Cloudflare Pages. It’s known for its incredible speed, robust global network, and seamless integration with GitHub.
This guide will walk you through deploying a project from your GitHub repository to Cloudflare Pages.
Why Use Cloudflare Pages?
- Blazing Fast Speeds: Your site is served from Cloudflare’s massive global Edge Network, meaning it loads quickly for users anywhere in the world.
- Seamless Git Integration: Every time you
git pushto your repository, Cloudflare Pages automatically builds and deploys the update. - Generous Free Tier: The free plan is more than enough for personal projects, portfolios, and even small business sites.
- Advanced Features: It provides easy-to-use tools like redirects, custom headers, and detailed analytics right out of the box.
Prerequisites
Before you begin, you need two things:
- A Cloudflare Account: It’s free to sign up.
- A GitHub Account: Your project code must be in a GitHub repository.
Step 1: Sign Up for Cloudflare
- Go to the Cloudflare signup page: https://dash.cloudflare.com/sign-up
- Create your account using an email and password.
- You do not need to add a website or configure nameservers at this stage. You can skip the initial setup wizard if it appears.
Step 2: Create a Cloudflare Pages Project
- Log in to your Cloudflare dashboard.
- On the right-hand sidebar, click on “Workers & Pages”.
- Click the “Create application” button.
- Select the “Pages” tab at the top and click “Connect to Git”.
Step 3: Connect Cloudflare to Your GitHub Account
- A new window will pop up asking you to authorize Cloudflare to access your GitHub repositories.
- Click the “Authorize Cloudflare” button. You may need to enter your GitHub password.
- You will be asked to choose which repositories Cloudflare can access. You can either select “All repositories” or “Only select repositories”. For security, it’s a good practice to select only the specific repository you want to deploy.
- Click “Install & Authorize”.
Step 4: Select Your Repository and Configure Build Settings
Once authorized, you’ll be returned to Cloudflare to finish the setup.
-
Select Your Repository: Find the repository you want to deploy from the list and click on it.
-
Click “Begin setup”.
-
Configure Build & Deployments: This is where you tell Cloudflare how to build your site.
- Project name: This will default to your repository name. You can change it if you like.
- Production branch: This should be your main branch (usually
mainormaster). - Build settings: This is the most important part. Cloudflare offers presets for popular frameworks (like React, Hugo, etc.).
- For a simple HTML/CSS/JS site: You can often leave the “Build command” blank. For the “Build output directory,” you just need to specify the folder your
index.htmlis in. If it’s in the main (root) folder, you can set this to/or just leave it blank if that’s the default. - For a framework (like React/Vue/etc.): You would select the correct framework preset, and Cloudflare will fill in the correct build command (e.g.,
npm run build) and output directory (e.g.,/distor/build).
- For a simple HTML/CSS/JS site: You can often leave the “Build command” blank. For the “Build output directory,” you just need to specify the folder your
-
Click the “Save and Deploy” button.
Step 5: Visit Your Live Website!
That’s it! Cloudflare will now pull your code, build it (if necessary), and deploy it to their global network.
- You will see a progress screen showing the deployment status. This usually takes about a minute.
- Once it’s finished, Cloudflare will provide you with a unique URL ending in
.pages.dev(e.g.,my-cool-project.pages.dev). - Click the link to see your website live!
From now on, every time you push a change to your selected branch on GitHub, Cloudflare Pages will automatically redeploy your site.
Bonus: Adding a Custom Domain
Connecting your own domain is just as easy:
- In your project’s dashboard on Cloudflare Pages, click the “Custom domains” tab.
- Click “Set up a custom domain” and enter the domain you own (e.g.,
www.yourdomain.com). - Cloudflare will provide you with instructions, which usually involves adding a single
CNAMErecord in your domain registrar’s DNS settings.