PHP stream wrapper for Google Cloud Storage - php

I am in a process of setting up Prestashop installation in a cluster of 3 GCE instances, managed by Kubernetes. I use Cloud SQL as DB and all seems to be running well, except, of course the images part, since prestashop in each pod uploads and shows images to/from it's local filesystem.
In App Engine I cloud use stream_context_set_default() and that would allow me to use "gs://mybucket" as a regular path. Is there a way to do that in Compute Engine? If it is possible, making Prestashop use Cloud Storage bucket can be done in 2 lines of code.
There is a StreamWrapper for Amazon S3 service that does exactly what I need: http://hiousi.tumblr.com/post/94824087894/prestashop-images-hosted-on-amazon-s3
But I would like to use Cloud Storage.

The source code for the stream wrapper can be downloaded at https://github.com/GoogleCloudPlatform/appengine-php-sdk/tree/master/google/appengine/ext/cloud_storage_streams.
It has a couple of dependencies on other GAE APIs such as App Identity & Urlfetch. They may need to be stubbed out or replaced by equivalent services on GCE.

i have created a PHP StreamWrapper for Google Compute Engine, if you're still interested. Here is the link to my adapted version.
https://github.com/jimyaghi/GCECloudStorageStreamWrapper
Sorry it's not more friendly, but it's a good useful bit of work. i'm using it and it works great.

Related

Run PHP in Google Cloud Storage Bucket

I can't get run PHP in Google Cloud Storage. Every time it downloads the page instead of run.
I saw in Documentation Troubleshooting, if page get's downloadet change Meta Type to text/HTML
Instead of run PHP it looks like, if you see a PHP site in XAMPP with inactivate server.
Do I have to install client libaries on Google Cloud to get PHP run, or Appache?
What can I do to get PHP run?
Google Cloud Storage does not provide compute services. Cloud Storage only supports static web sites.
PHP requires compute services provided by services such as App Engine, Compute Engine, etc. Also, you cannot install Apache on Cloud Storage. Typically PHP is "hosted" by a web server such as Apache or Nginx.
Google offers a number of services to host a website. You can continue to store your static assets (images, JavaScript, css, etc.) on Cloud Storage.
Google Cloud web hosting services

Can files be uploaded to a compute engine on GCP using an application page written in php/html?

Can we upload image files to a GCP running compute engine directly using PHP?
I know that it can be done using the backend ssh on GCP.
I have a solution that works in my local system to upload files but does not work on GCP.
Based on initial research it appears that GCP does not allow file upload directly.
Need confirmation though or if there is a way in which file upload can work, please enlighten.
I do not think it can be done directly through php, through ssh yes.
You can upload files with PHP.
If you want to upload to the server local disk, things become a bit simpler. Just ensure you have PHP configured for upload: PHP File Upload
If you want to upload to Google Storage, say to a bucket, you'd need to authenticate and get access there. Google Cloud SDK can provide this. Then you can install API Client Libraries for PHP and optional Cloud SDK components. That way you might call gcloud shell command or use API. Cloud SDK will provide transparent connection and authentication for you so that you can upload to the Google Storage.
Please see:
Cloud SDK
Google API Client Libraries

CodeIgniter Rest Server vs Amazon AWS

I have to create an API (JSON REST) for a project that has recently moved onto AWS, with a PHP CodeIgniter code-base, and an RDS database.
I have a bit of a dilemma, because I'm unsure what route to take to create the API. My two options seem to be:
Create an API with CodeIgniter Rest Server
Use AWS, using a combination of Lambda and the API Gateway to GET and POST to my RDS database.
The paramount priority is security, so that points towards using AWS, as far as I understand, but after failing in my attempt to make a small scale mock-up on AWS, I'm left a bit confused.
I wondered if anybody had any input as this is somewhat of a niche question, and I've had no interaction with AWS or CodeIgniter Rest Server.
Thank you for your time!
I can help you in a bit since I've experience with deploying Codeigniter base web system onto AWS.
First of all, the security in questions... AWS wont help much. Yes, it is by default have more security layer. But it is no use if your application itself is not secured.
So here goes:
If you want to deploy fast, I'd suggest go through EC2, install one of the image that have LAMP configured (from market, should've free image that you can use)
Upload to the server, configure the right config
Then it should work as per what it is intended.
But if you want to utilized auto scaling features
Setup the Elastic Beanstalk (EB) for PHP environment
ZIP up the codeigniter source code with all setting configured as below
Database setting point to RDS
Session to use database driver and create the needed table in the RDS
Upload and deploy to the EB
Then hopefully everything is working fine
Then, if to use API Gateway & Lambda, you will actually need to learn a bit more things.
How to configure API Gateway, to get familiar with how to use it
How to "link" it to lambda
How Lambda need to read request & response back etc
Also on Lambda no PHP support yet, so need to learn nodejs/python etc in order to use it
Basically if want to use API Gateway & Lambda you might need to start the development from scratch.

Can I write/read Google Cloud Storage from my website which is not a Google App Engine?

Can I write (and read) files using PHP in my google cloud storage when Im not using a Google App Engine?
In other words, may I have my website running on another web hosting and use google cloud to store (and read in future) my JSON files only? the JSON files need to be written on runtime and by users.
you can store any files using any programming language like PHP to any cloud storage like google cloud storage or amazon s3, dropbox...etc
Checkout this documentation:
https://github.com/GoogleCloudPlatform/google-cloud-php#google-cloud-storage-ga

How to connect Google App Engine (PHP) with Cloud Datastore?

I am trying to connect my Local Development Site (using PHP) to Cloud Datastore, but unfortunately I do not know how to set up my code to reach the Datastore. I have tried the solution of tomwalder/php-gds, but I do not know, how to set up the code to work with my site. After the installation with composer, I do not know which file should be modified, there is no config.php in my directory. There are also no Google Documentation about Datastore for PHP.
I am open for any solution to connect the Datastore with my site.
Can you please give us a few tips, how to start the work?
I'd suggest taking a look at https://github.com/tomwalder/php-gds. Tom just released a version that connects natively to the datastore, which is faster than going via Cloud Datastore.

Categories