-1

I am new to both Google Cloud Storage and Google Analytics API v4.

I have created a helloworld application where I add JS and CSS files. I have uploaded the same in the google storage. But JS and CSS files are not working.

This is what I have done so far.

  1. I have created a new project.
  2. I have generate a new service and keep the downloaded JSON file in the root of the project.
  3. I have created a storage bucket.
  4. I am using default app engine.

I am using GCConsole to upload the project. While uploading I am using old settings with new properties. At the end when I give command gcloud app console, in the service list, I do not found and I do not asked by the console to mention the storage bucket. I have add the bucket in my PHP file. Below I have shared my files.

Questions

  1. I have created storage bucket, service JSON file. I am using default app engine. Is there anything I am missing?
  2. Is it possible to upload the project in VM Instance and test?
  3. What is the difference between VM Instance and App Engine?
  4. How do I create and test proper app.yaml file?
  5. Is it mandatory to use and configure bucket in PHP code? Is there any alternatives?
  6. I do not found the project under the bucket I have created. I found it in App Engine > Source. In the bucket there are 3 different folders are created automatically. Is this approach correct?
  7. Is it possible to update the project URL with user friendly URL?
  8. How can I run Google Reports API v4 scripts (PHP, Java) in Google Storage?
  9. Why JS and CSS files are not working?

Project's Folder Structure

\root\
   \vendor\
   \css\style.css
   \js\main.js
   index.php
   app.yaml
   abcde-9c0e6b4e4b6c.json
   composer.json
   composer.lock
   README.md

index.php

<?php 

require 'vendor/autoload.php';

use Google\Cloud\Storage\StorageClient;
use google\appengine\api\cloud_storage\CloudStorageTools;

$projectId = 'projid';
$bucketId = 'buckid';

$storage = new StorageClient([
    'projectId' => $projectId,
    'keyFilePath' => 'abcde-9c0e6b4e4b6c.json',
]);

$gcsBucket = $storage->bucket($bucketId);
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
    <link rel="stylesheet" href="css/style.css">
    <title>GCP PHP</title>
</head>
<body>
    <h1>Welcome to GCP World</h1>
    <div class="p1">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Perferendis nihil molestias mollitia iste aliquam placeat quis nobis nesciunt, pariatur ipsa eligendi eveniet ipsam voluptatibus, voluptate eaque alias velit voluptatem id enim sed quisquam praesentium necessitatibus sint. Distinctio nam deleniti, a, eos reprehenderit eligendi, officiis nisi adipisci nostrum et delectus earum.</div>
    <div class="p2">Iure, rerum, inventore! Nulla nesciunt autem, facere eius quas, a ipsum necessitatibus adipisci, reprehenderit eaque fugit debitis dicta voluptates dignissimos quos? Tenetur deleniti impedit excepturi dolorem voluptas, quidem animi ullam! Deserunt eum, modi, eligendi et quam, magni sapiente dolorem porro eaque quibusdam nihil ratione consequuntur amet autem voluptas suscipit, molestiae!</div>
    <div class="p3">Molestias architecto a expedita nostrum, ullam sapiente quia temporibus nesciunt aperiam, asperiores dolor tempore, delectus ipsam sunt? Consequuntur facere reprehenderit nemo voluptatibus ad facilis nostrum temporibus perferendis sequi quasi voluptas, voluptatum repellendus rerum quas repudiandae quidem ipsam eligendi ex numquam sint culpa itaque eum? A saepe deserunt ea asperiores fugiat.</div>
    <div class="footer1"></div>
    <script src="js/main.js"></script>
</body>
</html>

app.yaml

runtime: php73

handlers:
- url: /.*
  script: auto

runtime_config:
    document_root: .
Amit
  • 91
  • 1
  • 9

1 Answers1

1

You can refer to the documentation for useful information that might solve your questions.

  1. Creating config files for creating JSON config files.
  2. You can upload your project into a bucket and create a VM instance and download it from there. But you will have to create the environment for deploying it.
  3. App Engine is a Platform-as-a-Service, so basically you just do code there and the platform is the one that will manage the rest. Compute Engine is a Infrastructure-as-a-Service. You get your VM instance and you are the one that will manage it, as you own computer. However, check this link to another StackOverflow thread where you can have a further explanation about this.
  4. For creating a proper app.yaml file according to yaml syntax, you can go to this page http://www.yamllint.com/. To create a proper one in Google Cloud Platform for deploying your application, you can have the information about the elements in the documentation about app.yaml Configuration File.
  5. You can manage your buckets in many different ways, check them out in this documentation for Uploading objects.
  6. In order to answer that question I would need to know how you created the bucket.
  7. Yes, it is. With a custom domain you can change the URL.
  8. There is no way to run anything from Storage if you meant that.
  9. You are missing the handlers, for using Style Sheets should be like this:
   handlers:
   # Serve a directory as a static resource.
   - url: /stylesheets
     static_dir: stylesheets
iker lasaga
  • 267
  • 2
  • 17
  • Thank you for the reply. Your handlers resolved my related issue. Also shared URLs are helping. I will share how I create the bucket. Also some related questions. I will placed one by one. Please see and reply. Thanks again. – Amit Jan 16 '20 at 21:30
  • 1. I have created from the Console > Create Bucket. Is there any alternative way to add the same in my project so that only this single bucket can contain my all files and other 3 buckets will not be created? – Amit Jan 16 '20 at 21:34
  • 2. Does custom URL needs a purchased domain? In local server, say WAMP, we are creating the URL using httpd.config file of apache. Is there anything to do like this in google cloud? – Amit Jan 16 '20 at 21:36
  • 3. In my root folder there are multiple php files now and these are connected in menu. But after uploading only index.php's content is showing in all pages. What I missed in handler? – Amit Jan 16 '20 at 21:40
  • 4. Is there any possibility to create App Engine per project basis? Or it is just a default version sharing by all the projects? – Amit Jan 16 '20 at 21:42
  • 5. In PHP web version there is an example code in google' website. I am following it. I have to run it using command - php -S localhost:8080 and its working perfectly in local server. But it is not working in VM instance. Is there any way to run it from console in cloud? – Amit Jan 16 '20 at 21:46
  • 6. How do we create a report with data and display it in browser using both Java and PHP? Please refer some examples. – Amit Jan 16 '20 at 21:49
  • 7. Is it possible to generate google analytics reports v4 using REST API? How does it differ from OAuth? Which one is preferrable and easier? Please share some documents, guides, tutorials etc. to understand and put me into development stage using examples in PHP and Java. – Amit Jan 16 '20 at 21:53
  • 8. Where do I get the documents from google to generate reports using PHP and Java? Please refer from google and others. – Amit Jan 16 '20 at 21:55
  • 1. There are quite a few other ways to create buckets: using [gsutil](https://cloud.google.com/storage/docs/creating-buckets#storage-create-bucket-gsutil), the client libraries (such as the [PHP client library](https://cloud.google.com/storage/docs/creating-buckets#storage-create-bucket-php) you use on the shared code) or the [REST APIS](https://cloud.google.com/storage/docs/creating-buckets#storage-create-bucket-console). – Daniel Ocando Jan 17 '20 at 11:48
  • 2. You need a purchased domain. Find all the relevant information about mapping a custom domain to your App Engine application [here](https://cloud.google.com/appengine/docs/standard/php7/mapping-custom-domains). – Daniel Ocando Jan 17 '20 at 11:49
  • 3. Refer to [this section](https://cloud.google.com/appengine/docs/standard/php7/config/appref#handlers_element) of the documentation to understand what the handlers element do on the app.yaml file as well as [this](https://cloud.google.com/appengine/docs/standard/php7/configuration-files) section to understand how you need to structure your application. – Daniel Ocando Jan 17 '20 at 11:50
  • 4. You can create only 1 App Engine application per project. This application consists of a single application resource and can have 1 or more services in the same project. If you want to communicate between different application hosted in different Google Cloud Platform projects simply use HTTP requests. Please read the [Product Overview](https://cloud.google.com/appengine/docs/standard/php7/an-overview-of-app-engine) for a better understanding. – Daniel Ocando Jan 17 '20 at 11:50
  • 5. Share the link of the exact tutorial you are following.`php -S localhost:8080` uses the [built-in web server](https://www.php.net/manual/en/features.commandline.webserver.php) in order to view the application on Compute Engine you should run something like a [LAMP stack](https://cloud.google.com/community/tutorials/setting-up-lamp) and use the VM's external IP Address.You should be able to run itwithout any issues using the [Cloud Shell's web preview](https://cloud.google.com/shell/docs/using-web-preview). – Daniel Ocando Jan 17 '20 at 11:50
  • 6. 7. 8. I would recommend you to refer to the [Google Analytics API documentation](https://developers.google.com/analytics/devguides/reporting/core/v4). Notice there are [Quickstarts](https://developers.google.com/analytics/devguides/reporting/core/v4#quick_start_guides) for both Java and PHP. Sorry I can't be of further assistance regarding Google Analytics, but my knowledge of it is very limited. – Daniel Ocando Jan 17 '20 at 11:50