I have been trying to perform a simple write to my Google Cloud Bucket using the php sample that Google provides. My problem is that my remote Google Cloud VM Server does not seem to be functioning correctly. I followed all of the instructions on the website except creating a client ID because I have already created 2 so I used one of those. One of the problems I observed while trying to implement this is that php does not seem to including the google cloud storage libraries. I downloaded the git as the website instructed and I even included the path in the php.ini. This is what i included
include_path = ".:/usr/bin/php:/google-api-php-client/src" I find that even after I adding this, when I try to run
<?php file_put_contents('gs://myappid.appspot.com/hello.txt', 'Hello');?>
I get the error Unable to find wrapper 'gs//'. Even adding require_once(google-api-php-client/autoload.php) does not fix the problem. After I added require_once... my code does not run past this point. It does not throw an error, it just stops running. I am lost at how to store files into my bucket via php. I follow the instructions on Google strictly but nothing seems to work.
The gs:// wrapper is only provided on Google App Engine, not Google Compute engine.
As long as you have read and write allowed in your google compute engine, gcloud or gsutil should already be installed. Then try using normal gsutil commands like:
exec("/usr/bin/gsutil -m cp -R file.png gs://bucket/images/", $output, $image_return);
Log into your compute engine and try out like gsutil ls
Related
We use a Flexible Environment with Google App Engine for our PHP Website (Laravel) and cannot figure out how to download current website image from Google App Engine with flexible environment setup. As I now have a new developer, we need this latest version for a backup purpose and for future improvement. The idea is to get the latest code from there and also the database, which is even more important, as website already has data and users on it (it is live now, in beta).
We also have a GitHub account setup. If we could load an image from the cloud to GitHub, that could work as well.
You may be able to find the source code here:
https://console.cloud.google.com/debug
Alternatively, since you are using GAE Flex, you could ssh into your instance to try to find it:
https://cloud.google.com/appengine/docs/flexible/php/debugging-an-instance#connecting_to_the_instance
As for the Database, the answer depends on 1) which database you are using (google datastore vs google cloud sql, etc) and 2) what you intend to do with it.
For example, Google datastore has datastore admin which can retrieve a snapshot of the database (https://console.cloud.google.com/datastore/settings), but the output is not something standard like csv. It's primarily used for backups & restores. But you can use this to clone your database into another app engine project
In order to copy anything from a VM on google Cloud platform, you first need to access the docker via SSH (command: sudo docker exec -it gaeapp /bin/bash). When inside of docker, you need to archive everything you need into TAR.GZ format (or try rar or zip, my server only supported TAR.GZ), once archived, you need to copy that outside of docker, which i already forgot how I have done that (oops). But google will help. Once done there will be a very non obvious gear icon on your SSH window top right where you can simply click download file and enter a file name. Choose your archive and vuala.
I'm lost in trying to decipher google's documentation for using cloud storage. All of the documentation that I have been able to find for PHP and Google Cloud seem to be for services running on google cloud. The snippet below uses the gs://my_bucket/new_file.txt as an example.
$gs_name = $_FILES['uploaded_files']['tmp_name'];
move_uploaded_file($gs_name, 'gs://my_bucket/new_file.txt');
This does not however tell me how to upload images from remote server.
I've looked for PHP libraries and checked composer but can't seem to find what I need. All I want to do is upload a file to the cloud, get the URL of the image and save the url to serve later on. Clean and simple.
I'm currently doing this on S3 and it was all very straight forward and easy to get up and running. For some reason I am missing something here.
Can anyone shed some light, or am I trying to do something google cloud wasn't designed for?
When the app runs locally, the gs:// path is mapped to a local GCS emulation layer. You can use Developer Console or gsutil to work with the production GCS.
) i am creating a php application in google appengine. Since i will have to pay for the cloud sql, i decided to use some files instead of the sql database and read/write from it. but the problem is i am not able to create or modify the existing files using php's standard file operations like 'fopen' and 'fwrite',etc. when i run the same code in 'localhost:8080' it is working properly. but not in the uploaded version in internet. i am getting errors while creating/writing to the files. please help. thank you
You should read the appengine php runtime docs https://developers.google.com/appengine/docs/php/#PHP_The_sandbox
Specifically the section about the sandbox. The crucial statement -
An App Engine application cannot:
write to the filesystem. PHP applications can use Google Cloud Storage
for storing persistent files. Reading from the filesystem is allowed,
and all application files uploaded with the application are available.
This was a while ago, but if you still want to write to file system, you can write to the gs cloud
https://cloud.google.com/appengine/docs/php/googlestorage/#writing_files_from_your_app
you need to add the bucket to your php.ini file
google_app_engine.allow_include_gs_buckets="yourapp.appspot.com"
and make sure your Service Account Name has permissions to edit the cloud storage
HTH
I am currently trying out the Google App Engine for PHP on my local development environment. So far, I have been following the instructions at https://developers.google.com/appengine/docs/php/gettingstarted/helloworld in order to just test out a small app to get used to how the SDK works. However, when I get to the point of loading the test web server using the SDK, I get an error trying to load the very basic helloworld.php example. The command I currently run is:
../GoogleAppEngineSDK/google_appengine/dev_appserver.py --php_executable_path=/usr/bin/php --port=9999 helloworld/
As you can see I use a custom port to avoid conflict with another application that runs on the default 8080. The SDK engine loads fine, but as soon as I try to access my application under localhost:9999 I get the error:
AssertionError("invalid CGI response: ''",)
and the web page itself throws a 500 error.
So far my attempts to correct the problem have yielded nothing and was wondering if there may be something I am missing.
You should make sure you're pointing to the php-cgi executable not php. Not every OS comes with this so you may need to install it. The getting started guide has more detailed instructions.
Just had this issue. Changing my php_executable_path to /opt/local/bin/php-cgi54 did the trick.
Is it possible to run e.g. a makefile or latex on files that are stored on Google Drive?
Consider the following scenario:
Google Drive App user (logged in on his own Google Drive) 'runs' a makefile or latex on a server e.g. using a php script.
It is (relatively) easy to download the makefile or latex file at the server side, and exec a specific command (e.g. 'make' or 'latex').
The problem is that the makefile or latex file needs other files that are stored locally on the user's Google Drive. However, I do not want to download all the files to the server 'just in case'.
Maybe a complete Google Drive folder can be mapped on the server for this session?
Or maybe symlinks can be made for the complete file tree, and when they are accessed, the actual file content can be downloaded on the server?
Does anybody have any ideas and practical tips how to implement this?
No turn key solution for PHP as far as I know.
If you have admin rights on the (Linux) server the PHP runs on, you can mount Google drive in an ordinary folder. If you are willing to do quite some programming, you could start out with vfs://Stream which is PHP only AFAIK.
If it is possible to ssh into your Google Drive (which I don't know) you could use the sshfs command to mount it and then execute whatever commands you desire.
Regarding Latex: CLSI (common latex service interface) seems to be a viable candidate, as it accepts urls to your resources. See the following links:
http://code.google.com/p/common-latex-service-interface/
https://github.com/scribtex/clsi
Public CLSI servers
The downloadUrl of the google drive resources can then be passed in the CLSI request.
See my answer in google drive: access webContentLink through javascript for getting the downloadUrl in javascript.