-->


How can I host websites on Google cloud?

Sign in to your Google account.If you don't already have one, sign up for a new account.
Select or create a Cloud Platform project.GO TO THE PROJECTS PAGE
Enable billing for your project.ENABLE BILLING
Have a domain that you own or manage. If you don't have an existing domain,register a new domain.This tutorial uses the domain example.com.
Verify that you own or manage the domain you will be using. To demonstrate that you are an owner or manager of a domain, use one of theGoogle Webmaster Central verification processes. Make sure you are verifying the domain, for example, example.com, and not a site on the domain, such aswww.example.com.Note: If you own the domain you are associating to a bucket, you might have already performed this step in the past.For more information, see Domain-Named Bucket Verification.


Creating a CNAME alias


Create a CNAME alias that points to c.storage.googleapis.com.


A CNAME alias is a DNS record that lets you use a URL from your own domain to access resources, such as a bucket and objects, in Cloud Storage using your custom domain URL. For example, for www.example.com, the CNAME record might contain the following information: 
NAME TYPE DATA 
www.example.com CNAME c.storage.googleapis.com 




Your domain registration service should have a way that you can administer your domain, including adding a CNAME record.


Note: Depending on your domain registration service, you may only be able to use CNAME aliases to map to subdomains, such as Example Domain or http://myblog.example.com, and not directly to the root domain, Example Domain.


For more information about CNAME redirects, see URI for CNAME aliasing.


Creating a bucket


Create a bucket whose name matches the CNAME you created for your domain.


For example, if you added a CNAME record pointing www.example.com to c.storage.googleapis.com, then create a bucket with the name "Example Domain".


To create a bucket:


CONSOLE


GSUTIL


MORE


Open the Cloud Storage browser in the Google Cloud Platform Console.


Click Create bucket.
In the Create bucket dialog, specify:The Name of your bucket.The Storage class for your bucket:Multi-Regional.The Location of your bucket: United States.
Click Create.


Uploading your site's files


To add to your bucket the files you want your website to serve:


CONSOLE


GSUTIL


MORE
In the Cloud Storage browser, browse to the bucket that you created.
Click Upload files.
In the file dialog, browse to the desired file and select it.


After the upload completes, you should see the file name, size, type, and last modified date in the bucket.


For example a bucket with two files index.htmland 404.html appears in the Cloud Platform Console as:




Example of a bucket configured as a website.


Note: If you are migrating an existing website, or copying a large number of files, use gsutil rsync to move your content. You can use the -R option to recursively copy directory trees. For example, to synchronize a local directory named local-dir with a bucket, use:gsutil rsync -R local-dir http://gs://www.example.com


Sharing your files


To share publicly the files that you want to serve:


CONSOLE


GSUTIL


MORE
In the Cloud Storage browser, browse to each of the files that you created.
Click the checkbox in the Share publicly column.


If successful, a link titled Public link appears next to the checkbox.


Note: You can set the default object ACL for your bucket to automatically share any subsequent files that you upload to the bucket.


Optional: Assigning pages


From the files you shared publicly, you can assign an index page suffix and a custom error page.


An index page (also called a webserver directory index) is the file returned to visitors to your static site who request a "directory". If the top level site, such as http://www.example.com, is requested, or a missing page is requested, e.g., http://www.example.com/directory, the service attempts to return an index page. If you haven't assigned an index page suffix, or if the "directory" doesn't have an associated index page, Cloud Storage returns an error page. The property that controls which file acts as the index page is MainPageSuffix.


For example, if the MainPageSuffix is index.html, Cloud Storage attempts to return the object www.example.com/index.html when a user requests http://www.example.com. Similarly, if there is no objectwww.example.com/directory, then Cloud Storage attempts to return the object www.example.com/directory/index.htmlwhen a user requestshttp://www.example.com/directory. If there is no such object, Cloud Storage returns an error page.


The error page is the file returned to visitors of your static site who request a URL that does not correspond to either an existing file, or, if an index page suffix is set, the appropriate index object. The property that controls which file acts as the error page is NotFoundPage. If you don't set NotFoundPage, users receive a generic error page.


In the following sample, an index page suffix is set to index.html and a custom error page is set to 404.html:


CONSOLE


GSUTIL


REST APIS
In the Cloud Storage browser, navigate to the bucket that you created.
Click the more actions icon next to the bucket and select Edit website configuration.Note: This option is only available for buckets whose name matches a valid website pattern.
In the Configure website dialog, specify the Main Page and the 404 (Not Found) Page.
Click Save.


Note: View, change, or remove these settings from the Edit website configuration menu.


Testing the website


Test that content is served from the bucket by requesting the domain name in a browser, either with a path to an object, or if you set the MainPageSuffixproperty, with just the domain name.


Cleaning up


After you've finished the Hosting a Static Website tutorial, you can clean up the resources you created on Google Cloud Platform so you won't be billed for them in the future. The following sections describe how to delete or turn off these resources.


Deleting the project


The easiest way to eliminate billing is to delete the project you created for the tutorial.


To delete the project:
In the Cloud Platform Console, go to the Projects page.GO TO THE PROJECTS PAGE
In the project list, select the project you want to delete and click Delete project.
In the dialog, type the project ID, and then click Shut down to delete the project.


Deleting the bucket


If you do not want to delete the entire project, delete the bucket that you used for hosting your website:


CONSOLE


GSUTIL


Open the Cloud Storage browser in the Google Cloud Platform Console. 


Select the checkbox next to the bucket that you created.
Click Delete.
In the overlay that appears, click Delete to permanently delete the bucket and its contents.




5.2k Views · View Upvoters · Answer requested by Ravi L






















Related QuestionsMore Answers Below























David Base, Blogging since a kid
















The easiest way to host websites, WordPress or any web application on Google Cloud is through the cloud hosting portal CloudWays; you can deploy a ready configured cloud server on Google Compute Engine (GCE) in a matter of minutes.


Hosting Website on Google Cloud
Step 1. Select your desired application. For custom web projects; Choose PHP Stack.
Step 2. Give appropriate names for your deployment.
Step 3. Choose “Google Cloud” and needed set of system resources.
Step 4. (Optional) Choose bandwidth to get the estimated cost.
Step 5. Choose initial storage space for application files & MySQL database.
Step 6. Choose desired server location; Iowa (USA), South Carolina (USA), Oregon (USA), Europe, Taiwan (Asia Pacific), Tokyo (Asia Pacific).
Final Step 7. Press Launch Now to deploy server & activate the free trial.






Or for those who want to go through the traditional, fairly complicated route — check out the detailed answer below:
yasser
كاتب ومحرر اخبار اعمل في موقع سكاي نيوز .

جديد قسم : منوعات

إرسال تعليق