) 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
Related
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
I use this code
move_uploaded_file($file_tmp,$us_id.".jpg");
but after run this script it not error but file not appear into folder ,how can it do?
before these, I test in localhost it work.
You haven't specified what $file_tmp contains, but... in an Azure Web App, the root folder is at d:\home\site\wwwroot. And you'll find the %HOME% environment variable set to d:\home.
Edited based on #David's comments and Kudu's Azure runtime environment
In a Cloud environment, saving files to the current filesystem of your Web App is not advised. If you simply upload your site through FTP, you might not have issues, but if you rely on Continuous Integration or automated deployment scenarios, your site folder might change or have content overwritten.
That is why, for storage of files that need to be accesed in the future or need to be permantently saved, you might want to use something like Azure Blob Storage. Not only is really cheap, but you can apply CDN over it for improving your files delivery.
Here is how to use it on PHP and the Azure SDK for PHP.
As I leverage your code at Azure window sever can't upload file from php in my test project, it works perfectly on my side, even I don't value the $us_id in your code, the picture is still updated to the uploadimg folder with the name .jpg.
I suspect whether if your Web Apps's disk space has reached the limitation of your App Service plan.
As every App Service pricing tier has a limit disk space and will shared in all the web apps in this App Service plan. You can check the metric on dashboard page of your web app portal, e.g.
You can refer to https://azure.microsoft.com/en-us/pricing/details/app-service/ for details.
I think the question says it all. Since PHP5 we have a lot of methods for SQLite database handling. Now I have uploaded a SQLite file to my Google Drive Folder and granted read and write access for all to it. Is it now possible for me to connect to this database file from PHP with functions like:
$dbconn = sqlite_open($googleDriveLink); // or
$db = new SQLite3($googleDriveLink);
Read and write access in the context of google drive, means "read and write using their User Interface or APIs", on the other hand, PHP needs "Operating System's read and write access" to the file. Google is not exposing the file in a way that SqLite can handle it. The most best that perhaps in a tricky way, you can obtain is a download and an upload of it, but will collide with others and wont be useful.
You may want to educate yourself on Google Drive's API reference, specifically its section about Files.
You could pass it the download URL, as I assume that's what you mean by $googleDriveLink, but I don't think that's what you're looking for. Say, for example, privacy settings on the file are changed that don't allow anonymous downloads.
To take advantage of the Google Drive APIs in PHP, you'll need to leverage an HTTP client in your code that handles the communication, that or create a backend that your PHP code uses. It may be beneficial to read the Google API PHP Client Library's getting started document.
In whichever path you choose, you'll more than likely have to download the SQLite file to your PHP server and manipulate it locally, and then optionally update it on Google Drive.
Hope that helps.
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.
I want to develop a website like file manager. Where user register and will get fix disk space lets say 20MB.
Now user can upload their pdf, doc, txt, jpeg etc files upto their disk limit.
I can develop upto this using PHP.
Now below is my issue:
1) If user's files are corrupted they can rollback their folders before 2-3 days.
Files must be secure and safe from viruses as users are uploading their important documents.
Is there any 3rd party storage server who provides such facility?
2) Also all files should be previewed from browser.
I am using Google doc viewer. Is is good and safe way to preview file in browser?
But google links are accessible from all, I need to add some restrictions as file can be viewed only by their owner.
I know it's a major task, but i just need some sort of logic. Please share your thoughts.
Thanks.
Any cloud storage service can be used for this. You'll get HDD space. There is not storage server who provides revision control system for this. You can use git, svn for this though. But as the files are binary you can not get full facility of these tools.
How file will be previewed depends on you. If you use PHP you make the site and at the backend you use the API to interact with the storage service. Google doc is not an option for this if you use PHP. Also note Google links can be made private.
I suggest you this,
Find a cloud storage service and use the storage in your server. Any will do.
Create UI using PHP and control the access using PHP too.
Manipulate files in your server directly or in 3rd party storage server via API
Use a revision control system to track the changes. And use its API in PHP end.
Some cloud storage service
Amazon S3. It also supports Versioning.
Google Cloud Storage
Microsoft Azure
Try Microsoft SkyDrive or Google Drive or Dropbox