Create a server on Google Cloud
Use this guide to begin hosting on servers at Google Cloud.
Create a Google Cloud account
You can sign up for Google Cloud using either of the following Google accounts:
- Gmail account.
- Google Workspace account. — If your domain’s email is hosted by Google, you have a Google Workspace account.
Google Cloud’s free trial includes a $300 credit that is valid for 90 days.
To sign up for Google Cloud:
- Go to the Google Cloud free trial signup.
- Click on “Get Started for Free”.
- Sign in with your Google account.
- Follow the prompts to provide your billing information and activate your account.
Optional: Install the CLI
If you prefer using the command line, install the Google Cloud CLI.
If you’re using your browser to create Google Cloud resources, you don’t need to install the Google Cloud CLI.
The Google Cloud CLI lets you create and manage Google Cloud resources
from the command line using the gcloud
command.
To install the gcloud
command on MacOS,
download and run the appropriate Google Cloud CLI installer for your computer’s architecture:
To install the gcloud
command on Windows,
download the run the
Google Cloud CLI installer for Windows.
To install the gcloud
command on Linux,
see the
instructions for Google Cloud CLI for Linux.
Next, authorize the CLI to access your Google Cloud account
by using the gcloud auth login
command.
gcloud auth login
A browser window will open for you to complete the authorization.
Create a project
All resources belong to a Google Cloud project. You can create separate Google Cloud projects for each of your clients or for dev/stage/prod environments.
By using separate projects:
- You ensure security isolation between projects.
- You will be able to view cost breakdowns on a per-project basis.
- You will be able to change the credit card used to pay invoices on a per-project basis.
- Go to the create a project page in Google Cloud console.
- In the Project Name field, enter a name for your project.
- A project ID will be generated based on your chosen project name. To change the project ID, click the Edit link next to the project ID. The project ID can’t be changed after the project is created.
- If you see an Organization option, select the organization the project will belong to. If your Google Cloud account is on the free trial, skip this step as the organization list is not shown.
- For the Location option, select either No organization or the name of the organization the project will belong to.
Choose a project ID for the new project you’ll create and set a shell variable with the project ID.
PROJECT_ID="MY-PROJECT-ID"
The project ID must meet the following requirements:
- Must be 6 to 30 characters in length.
- Can only contain lowercase letters, numbers, and hyphens.
- Must start with a letter.
- Cannot end with a hyphen.
- Cannot be currently in use or used by previously deleted projects.
Next, create the project.
gcloud projects create "${PROJECT_ID}"
Set this project as the default project for gcloud
command:
gcloud config set project "${PROJECT_ID}"
Next, link your billing account to the project. Your billing account was automatically created when you created your Google Cloud account.
Get the ID of your billing account using the following command:
gcloud billing accounts list --filter=open=true --format="value(name)"
The billing account ID will have the format XXXXXX-XXXXXX-XXXXXX
.
Set a shell variable with the billing account ID shown by the above command.
BILLING_ACCOUNT_ID="XXXXXX-XXXXXX-XXXXXX"
Link your billing account to the project you created:
gcloud billing projects link "${PROJECT_ID}" \ --billing-account="${BILLING_ACCOUNT_ID}"
Create firewall rules
By default, your Google Cloud project’s firewall is configured to only allow SSH traffic.
You must create firewall rules to allow HTTP and HTTPS traffic.
First, create a firewall rule to allow HTTP traffic.
- Go to the firewall policies page in Google Cloud console.
- Click Create firewall rule.
- Set the following values (leave the default values for all other fields):
- Name:
default-allow-http
- Description:
Allow HTTP from anywhere
- Targets: select the “All instances in the network” option.
- Source IPv4 Ranges:
0.0.0.0/0
- Protocols and ports:
- Select the TCP checkbox.
- TCP Ports:
80
- TCP Ports:
- Select the TCP checkbox.
- Name:
- At the bottom of the form, click Create.
Next, create a firewall rule to allow HTTPS traffic.
- Go to the firewall policies page in Google Cloud console.
- Click Create firewall rule.
- Set the following values (leave the default values for all other fields):
- Name:
default-allow-https
- Description:
Allow HTTPS from anywhere
- Targets: select the “All instances in the network” option.
- Source IPv4 Ranges:
0.0.0.0/0
- Protocols and ports:
- Select the TCP checkbox.
- TCP Ports:
443
- TCP Ports:
- Select the UDP checkbox.
- UDP Ports:
443
- UDP Ports:
- Select the TCP checkbox.
- Name:
- At the bottom of the form, click Create.
First, create a firewall rule to allow HTTP traffic.
gcloud compute firewall-rules create default-allow-http \ --allow="tcp:80" \ --description="Allow HTTP from anywhere" \ --direction="INGRESS"
Next, create a firewall rule to allow HTTPS traffic.
gcloud compute firewall-rules create default-allow-https \ --allow="tcp:443,udp:443" \ --description="Allow HTTPS from anywhere" \ --direction="INGRESS"
Choose a region
A server’s region determines the city where your server will be located.
The following Google Cloud regions are available.
If you’re unsure of which region to choose, see the Google Cloud region map and region picker.
If you’re using your browser to create a Google Cloud server, you’ll select the region you’ve chosen when you create the server.
Set a default region and zone for resources created with gcloud
commands.
There’s no difference between the zones within a region unless you’re using an uncommon machine type that is not available in all zones.
gcloud config set compute/region us-central1gcloud config set compute/zone us-central1-a
gcloud config set compute/region us-west2gcloud config set compute/zone us-west2-a
gcloud config set compute/region us-east4gcloud config set compute/zone us-east4-a
gcloud config set compute/region southamerica-east1gcloud config set compute/zone southamerica-east1-a
gcloud config set compute/region europe-west3gcloud config set compute/zone europe-west3-a
gcloud config set compute/region europe-west2gcloud config set compute/zone europe-west2-a
gcloud config set compute/region me-west1gcloud config set compute/zone me-west1-a
gcloud config set compute/region asia-east1gcloud config set compute/zone asia-east1-a
gcloud config set compute/region australia-southeast1gcloud config set compute/zone australia-southeast1-a
Choose a machine type
A server’s machine type determines the server’s number of vCPUs and amount of memory.
The most commonly used machine types are the E2, N1, and N2 series. See the machine type comparison for additional machine types.
- E2 series — Low-cost machine types that may use either Intel or AMD processors.
- N1 series — General purpose machine types that use Intel processors.
- N2 series — High-performance machine types that use newer Intel processors.
The N1 and N2 series are eligible for 30% Sustained Use Discounts (SUDs). See below for details.
The table below shows pricing for the us-central1 region. See VM instance pricing for region-specific pricing.
You’ll select the machine type you’ve chosen when you create the server.
You’ll select the machine type you’ve chosen when you create the server.
Sustained Use Discounts
A 30% discount is automatically applied to N1 and N2 series servers that are online for the entire month.
The Sustained Use Discounts (SUDs) automatically begins when a server has been online for more than one-quarter of the month. The discount increases based on the percentage of the month the server has been online.
Percentage of month | Effective discount |
---|---|
25% | 0% |
50% | 10% |
75% | 20% |
100% | 30% |
SUDs also apply to a server’s disk usage costs.
See the Compute Engine Sustained Use Discounts documentation for more details.
Free Tier
Compute Engine has a Free Tier that provides free usage of one server that meets the following criteria:
- Machine type: e2-micro
- Region: us-west1, us-central1, or us-east1
- Disk type: Standard persistent disk
- Disk size: up to 30 GB
- Outbound data transfer: 1 GB per month (excluding China and Australia)
Static IP addresses are not included in the Free Tier. If you assign a static IP address to your e2-micro instance, you will be charged for the static IP address.
You do not need to use the same e2-micro instance the entire month. You can delete and recreate the server. Free Tier usage is calculated hourly. For example, if you have two e2-micro instances for half of the month, that will count as your Free Tier usage for the month.
The Free Tier is available to all Google Cloud users. You do not need to have an account on the 90-day free trial. For more information, see Google Cloud’s free cloud features.
Choose a disk type
As the machine type determines only the vCPUs and memory, the server’s disk type and size are chosen separately.
The most commonly used types of persistent disks are Standard, Balanced, and SSD. See the disk type comparison for the full list of disk types.
- Standard persistent disks — Economical for storing large amounts of data. Slower (higher latency) than Balanced persistent disks.
- Balanced persistent disks — Backed by solid-state drives (SSDs), this is the best disk type for the vast majority of servers. Offers a balance of performance and cost.
- SSD persistent disks — Suitable for servers with databases that have very high rates of input/output operations per second (IOPS).
For IOPS and throughput limits of each disk type, see zonal persistent disk performance.
The table below shows pricing for the us-central1 region. See persistent disk pricing for region-specific pricing.
Disk type | Monthly cost (us-central1) |
---|---|
pd-standard | $0.40 per GB |
pd-balanced | $1.00 per GB |
pd-ssd | $1.70 per GB |
You’ll select the disk type you’ve chosen when you create the server.
You’ll select the disk type you’ve chosen when you create the server.
Create snapshot schedules
Create a daily snapshot schedule that retains snapshots for 90 days.
- Go to Snapshots in Google Cloud console.
- Click on Create snapshot schedule.
- Set the following values;
- Name:
daily-snapshots
- Region: choose the region where you will create your server.
- Schedule frequency: select Daily.
- Autodelete snapshots after:
90
days.
- Name:
- Click Create at the bottom of the page.
Use the gcloud compute resource-policies create snapshot-schedule
command
to create snapshot schedules.
Create a daily snapshot schedule that retains snapshots for 90 days.
gcloud compute resource-policies create snapshot-schedule daily-snapshots \ --max-retention-days="90" \ --start-time="4:00" \ --daily-schedule
Create a server
Compute Engine is the Google Cloud service you use to create a server. In Google Cloud, a server is called a Compute Engine instance or a VM instance.
Before you can create a server, you must first enable the Compute Engine API in your project.
- Go to the Compute Engine API page in Google Cloud console.
- Click Enable. If there is no Enable button, then the Compute Engine API is already enabled for this project.
Enable the Compute Engine API using the gcloud services enable
command.
gcloud services enable compute.googleapis.com
Next, create the server.
- Go to the VM Instances page in Google Cloud console.
- Click Create instance.
- You’ll start out in the Machine configuration pane.
- Choose a Name for the server. Only lowercase letters (a-z), numbers, and hyphens are allowed.
- Choose a Region.
- Leave Zone set to Any.
- Choose a Machine type.
- Click on the OS and Storage pane.
- In the “Operating system and storage” section, click Change.
- For Operating system, select Ubuntu.
- For Version, select Ubuntu 24.04 LTS (x86/64, amd64).
- For Boot disk type, leave the default Balanced persistent disk unless you have identified a different disk type for your use case.
- For Size (GB), enter your desired disk size.
- Click Select.
- In the “Operating system and storage” section, click Change.
- Click on the Data protection pane.
- Select Snapshot schedules.
- Choose the schedule named daily-snapshots.
- Click Create at the bottom of the page.
Set shell variables for the instance name, disk size, machine type, and image family.
INSTANCE_NAME="my-first-server"DISK_SIZE="50"MACHINE_TYPE="e2-standard-2"IMAGE_FAMILY="ubuntu-2404-lts-amd64"
The instance name has the following requirements:
- Must be 1 to 63 characters in length.
- Can only contain lowercase letters, numbers, and hyphens.
- Must start with a letter.
- Cannot end with a hyphen.
The disk size is in gigabytes.
The image family can be one of the following:
- Ubuntu LTS:
- Ubuntu 24.04:
ubuntu-2404-lts-amd64
- Ubuntu 22.04:
ubuntu-2204-lts
- Ubuntu 24.04:
- Ubuntu Pro LTS:
- Ubuntu Pro 24.04:
ubuntu-pro-2404-lts-amd64
- Ubuntu Pro 22.04
ubuntu-pro-2204-lts
- Ubuntu Pro 20.04
ubuntu-pro-2004-lts
- Ubuntu Pro 18.04
ubuntu-pro-1804-lts
- Ubuntu Pro 24.04:
Create the server using the gcloud compute instances create
command.
gcloud compute instances create "${INSTANCE_NAME}" \ --image-project="ubuntu-os-cloud" \ --image-family="${IMAGE_FAMILY}" \ --machine-type="${MACHINE_TYPE}" \ --boot-disk-size="${DISK_SIZE}" \ --boot-disk-type="pd-balanced"
Next, apply the daily snapshot schedule to the server.
gcloud compute disks add-resource-policies "${INSTANCE_NAME}" \ --resource-policies="daily-snapshots"
Use a static IP address
By default, your server uses an ephemeral IP address that will change each time you reboot your server.
On Google Cloud, the price for a static IP address that is assigned to a server is $3.65 per month.
Before pointing DNS to your server’s IP address, promote the server’s ephemeral IP address to a static IP address.
- In Google Cloud console, go to IP addresses.
- Find the row that has both of the following:
- Access type: “External”
- In use by: “VM instance [your server name]”
- Click on the three vertical dots on the right side of the row.
- Click on Promote to static IP address.
- In the dialog box that opens, set the following values:
- Name:
my-first-server-address
- Name:
- Click Reserve.
Get the server’s IP address.
gcloud compute instances list --format="value(NAME, EXTERNAL_IP)"
Set a shell variable with the IP address.
Replace x.x.x.x
with the IP address.
IP_ADDRESS="x.x.x.x"
Promote the address to a static address using the
gcloud compute addresses create
command.
gcloud compute addresses create "${INSTANCE_NAME}-address" \ --addresses="${IP_ADDRESS}"
SSH into the server
- Go to VM instances in Google Cloud console.
- Click on SSH for the server you just created.
- When prompted to “Allow SSH-in-browser to connect to VMs.”, click Authorize.
gcloud compute ssh "${INSTANCE_NAME}" --quiet
If this is the first time you’ve used gcloud compute ssh
,
a new SSH key will be generated in your home directory at ~/.ssh/google_compute_engine
.
Once you’ve SSH’d into your server, you’ll see the username in the shell prompt is the username of your Gmail account or Google Workspace account.
Run the ServerPilot installer
Do the following to connect the server to ServerPilot:
- In your browser, go to the Servers page in the ServerPilot dashboard and choose Connect Server.
- In the form, check the box that says “I don’t have a root password or public IP address.”
- Enter the display name to use for your server in ServerPilot. You can change this later.
- Click Connect to ServerPilot.
- You’ll be shown a unique installer command for this server. Copy the command to your clipboard.
- Switch back to the terminal window where you’ve SSH’d into your server.
- Paste the installer command from your clipboard and press Enter.
Once the installer command completes, switch back to your browser window to see ServerPilot’s progress configuring your server.
Once your server is connected to ServerPilot, you can create an app to begin hosting sites on your server.
Relay outbound email
To send email from servers at Google Cloud, you must configure your server to relay outbound email through a mail delivery service. This is necessary because Google Cloud blocks outbound port 25.
Google Cloud has the following guides for configuring your server to relay email through a mail delivery service.
- Relay email through SendGrid
- Using this guide, you will enable SendGrid through the Google Cloud Marketplace.
- To see pricing, go to SendGrid on the Google Cloud Marketplace and click View all plans.
- SendGrid’s free plan allows sending up to 100 emails per day.
- Relay email through Mailgun
- Using this guide, you will enable Mailgun through the Google Cloud Marketplace.
- To see pricing, go to Mailgun on the Google Cloud Marketplace and click View all plans.
- Relay email through Mailjet
Alternatively, if your organization uses Google Workspace for your domain’s email, you can relay email through Google’s mail servers. See Google’s guide to relaying messages through Google’s mail servers and use the instructions for configuring Postfix on your server. Configure relaying through either port 465 or port 587, not port 25.
Clean up
If you no longer need the resources you created using this guide, delete the resources to stop further costs from accruing.
Delete the server
Deleting the server will permanently delete the data on the server.
Deleting the server will not delete any snapshots. Snapshots created by your snapshot schedule will be deleted automatically according to the schedule’s retention policy.
- Go to VM instances in Google Cloud console.
- For the server you want to delete, click on the three vertical dots.
- Click on Delete.
- In the confirmation window, click on Delete.
gcloud compute instances delete "${INSTANCE_NAME}"
After deleting the server from Google Cloud, delete the server from ServerPilot.
- In the ServerPilot dashboard, go to the Servers page and click on the name of the server.
- Click on Delete.
- Click on Delete Server.
- Click on Confirm Delete Server.
Delete the static IP address
Google Cloud charges an additional fee for static addresses that belong to your project but that aren’t assigned to a server.
If you no longer plan to use the server’s static IP address, you can delete the address.
- In Google Cloud console, go to IP addresses.
- Find the row that has the following:
- Name:
my-first-server-address
- Name:
- Check the box on the left side of the row.
- Click on Release static address. If you don’t see Release static address, click on the three blue vertical dots to the left of the icon.
Delete the static IP address using the
gcloud compute addresses delete
command.
gcloud compute addresses delete "address-${INSTANCE_NAME}"
Delete the snapshots
- In Google Cloud console, go to the Compute Engine Snapshots page.
- Check the box next to each snapshot you want to delete.
- Click Delete. If you don’t see Delete, click on the three blue vertical dots to the left of the icon.
First, get a list of all snapshots using the
gcloud compute snapshots list
command.
gcloud compute snapshots list
Next, repeat the following command for each snapshot you want to delete.
Replace SNAPSHOT_NAME
with the name of the snapshot shown in the output
of the above command.
gcloud compute snapshots delete SNAPSHOT_NAME
Delete the project
Deleting a Google Cloud project will delete all resources in the project.
- In Google Cloud console, go to the IAM & Admin Settings page.
- Click on Shut down.
- In the dialog box, type the name of the project.
- Click Shut down anyway.
To delete a project, use the gcloud projects delete
command:
gcloud projects delete "${PROJECT_ID}"
You can restore a deleted project within 30 days of when you deleted the project.
To restore a deleted project:
- In Google Cloud console, go to the Manage resources page.
- Scroll down to the bottom of the page.
- Click on Resources pending deletion.
- Check the box for the project you want to restore.
- Click Restore.