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.
Related
I've been spending few days trying to figure out how to set aws s3 as external storage for Resourcespace. and i've been getting more confused with the this app.
I'm using the opensource version and trying to customize it to my needs.
I've been through the web app's lengthy documentation but couldn't find anything about setting storage (like other web apps out there) However, I found a feature called syncdir where it sets an alternative external storage (for backup) but not as an external storage, as from the documentation, it doesent seem to have a direct method to specify storage/integrate s3 with it.
I've tried the following:
I've tried using aws s3 integration and how to integrate to any php website, by changing storing directory of 'storagedir' and directory of 'syncdir' in config.default file (i added the require s3 autoload file and added aws keys in config file), but it's not working, site is still storing locally
Note: I've integrated aws s3 before with Laravel 5.7 & Codeigniter 3 frameworks successfully.
I tried adding the require aws-autoload into the file where uploading functions is, and tried to look for the code responsible to upload, but code seems confusing to me where the upload functionality is (its not a php funtion where $_FILES receives your upload.
Changed place of require aws-autoload into include/general.php, but no luck.
Followed up with some forums on the matter like:
using external storage
Amazon S3 integration
I'm assuming that using the config file (to store AWS credentials and storage set to s3 bucket url), i include the aws-autoload in general/upload file, and it would automatically understand where it should upload, but no error or bug is reporting to address it.
But most of what i found is related to the paid version of the DAM system where it seems to be already set up on amazon.
Please advise, Any help is appreciated.
I'm using Wamp on Winddows 10 PC btw
Check this discussion out, it might help you :
https://groups.google.com/forum/#!topic/resourcespace/JT833klfwjc
It look like it is still a work in progress, so you may see the WIP code,
You will find links to code in the mentioned link.
I have previously developed 1 website using php and mysql now I want to deploy it on Google cloud platform.
It will be great if someone only point out steps for below points
1.install PHP 7.x
2.creating .YAML files
3.creating mysql databse
4.upload my PHP file
5.FTP setup
Thank you
You can start setting up you environment like the documentation describes.
For creating ".YAML" files there is also documentation by google.
To create your MySQL database you should check this documentation about creating Cloud SQL.
To upload PHP file you can use follow the documentation and learn more about Cloud Storage and how to upload objects.
About ftp setup, can you specify why you trying to achieve using it? If you want to transfer files you can you see again the documentation of 4.
You can find a large set of example applications for deploying to App Engine here, or on cloud.google.com.
Try to use Google App Engine - this is the easiest way to deploy app withount install LAMP and FTP. Withount MySQL its free! See the quickstart: https://cloud.google.com/appengine/docs/standard/php7/quickstart
Answering your question in the comment;
I've created .YAML file and also created MySQL databse and uploaded
all PHP files to bucket as shown in step 4. now how can I create URL
that call the Index.php ?
If you deploy your app in App Engine you don't necessarily need to upload all your application files to Cloud Storage because App Engine will put your static files in a managed static files server. You only need to set this in the app.yaml file.
I suggest you to take a look at the this sample application's files , so you can have a good idea on how to set all configuration files in order to deploy your app to App Engine standard environment and connect to Cloud SQL.
App Engine will create a default URL for you app under appspot.com domain, check for details here.
For more information on how you can connect to Cloud SQL from GAE standard take a look here.
Just follow steps
here
it will help you setup LAMP server and upload files to server using FTP
(which you can connect using SMTP-keyfile method) and also this document help you to setup mySQL database
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 created a Google Cloud Platform account, deployed the LAMP server, and logged in through SFTP and uploaded my existing site.
My site is currently running on another server, so I also uploaded all my databases and everything.
On my current server with hostgator I upload files to the /home/username/public_html/uploads folder, but on google you can upload to buckets. I figured I would use their Cloud Storage instead.
I tried doing a PHP move_uploaded_file() to the bucket: gs://mybucket/uploads; however, that's not working.
What's the trick? The only documentation I can find is using the App Engine, but I'm just using the Compute Engine with LAMP installed.
Also, which would be better? Should I stick with saving the uploads to the LAMP server, or should I use buckets?
Thanks!
You could use the json api directly:
https://cloud.google.com/storage/docs/json_api/v1/how-tos/upload
There is also a PHP library for using the Google APIs in general:
https://developers.google.com/api-client-library/php/start/get_started
Then you could use that library to insert objects into your bucket with a call like this:
https://cloud.google.com/storage/docs/json_api/v1/objects/insert
If you're already running a LAMP stack, it's fine to serve files directly from the VM itself, using its local disk; you don't need to start using Google Cloud Storage for typical, simple use cases.
Google Cloud Storage, which is where the buckets terminology comes from, is useful for storing lots of files, or for serving a very large site, either for processing via Hadoop or for serving to a global audience. Because this involves more work on your part, this makes sense if your site is so popular that the cost of serving data directly from the VM is more expensive than using Google Cloud Storage.
However, Google Cloud Storage has much higher scalability than disks on a VM (though you can attach additional disks, you're limited to having up to 10TB of persistent disk per VM, and it's not an automatic process), but that depends whether your use case will need that much space.
Bottom line: if your site is working fine with the LAMP stack on your VM, it's fine to keep it. It's a good idea to keep track of your TCO so keep an eye on the cost of your compute, storage, and network traffic, and see at which point it may make sense to move some of your assets to Google Cloud Storage.
You can use Google Cloud Platform Pricing Calculator to estimate your costs, but also take a look at pricing for Google Compute Engine (which includes compute, storage, and networking) as well as Google Cloud Storage, and see how your particular use case will work out.
I start to use GAE with PHP. On documentation we can't find any information about Blobstore.
So the only way to upload image it's to upload image on PHP application is Cloud Storage ?
Thx
Samuel
Yes no blobstore - only persistent storage is Google Cloud Storage.
In the current PHP SDK (1.89), in the PHP libs directory (<path to>\Google\google_appengine\php\sdk\google\appengine\api\blobstore) you can see that there is a blobstore directory, and a single blobstore_service_pb.php file. It is missing the BlobstoreService.php and BlobstoreException.php files.
However, you can get pre-release version from googles git site:
https://chromium.googlesource.com/external/googleappengine/python/+/b90ec6c60be569887e4905737fc5b2fedd9fe336%5E/php/sdk/google/appengine/api/blobstore/
Download the two required files, stick it in your Google appengine SDK blobstore directory and use it.
require_once 'google/appengine/api/blobstore/BlobstoreService.php';
use google\appengine\api\blobstore
Works locally on the development server... Not sure if the files exist on the actual app engine service, as I haven't pushed a test app to the servers yet.
PHP in GAE is in experimental stage and for now not every API is available. There's no ETA. You can try to make for example python "backend" that will handle your blobs and call it from your PHP side.