googlearchive / symfony-standard

Symfony for GAE (originally from SensioLabs)
http://symfony.com
11 stars 5 forks source link

How to develop locally? #3

Open dovy opened 8 years ago

dovy commented 8 years ago

FINALLY got this to run after what seemed like forever, hah. The issue is that they don't auto-create the bucket for you any longer. You have to go to the old dashboard: https://appengine.google.com/settings?app_id= and click the button on the bottom for cloud integration. It will error out, but in the end it will magically work.

Onto my question, how to run this locally? I know I can easily deploy, but I would love to just run the appengine locally. To do so I need to remove the env_variables provided in this project. Can I run a different .yaml for local without having to edit my .yaml at each deploy?

bshaffer commented 8 years ago

@dovy are you specifically asking how to run symfony locally using the Google App Engine Launcher?

dovy commented 8 years ago

@bshaffer That or to have a diff Yaml launch so I can use a local MySQL. Just trying to develop this proper.

Makes it really hard to deploy with the limitation of 10000 files and symfony composer packages. ;)

bshaffer commented 8 years ago

I definitely agree. This should be doable by separating out your configurations in app/config/app_dev.yml and app/config/app_prod.yml. Have you tried adding a doctrine configuration in app_dev for your local DB instance?

brandonpearson23 commented 8 years ago

I have been stuck on the same issue for about a week. I also realized the bucket wasn't auto created a few days ago, but I still get a 500 server error when running locally. The app runs as expected when deployed. The symfony app runs in prod mode on app engine, regardless of where you run it (locally or live), because the main app engine yaml file routes through web/app.php. The main config file app/config/config.yml imports into both _prod.yml and _dev.yml config files, but moving DBAL information to the main config file doesn't change anything. One thing I have not been able to try: The composer.json file installs symfony 2.6.* meaning currently when installing dependencies, i get symfony 2.6.11. However, this git was last released with symfony 2.6.3. I am wondering if installing 2.6.3 specifically will make a difference. Will try later tonight.

bshaffer commented 8 years ago

@brandon1499 what errors specifically are you receiving locally? Can you take a look at the AppEngineLaunger logs? On Tue, Sep 15, 2015 at 1:37 PM brandon1499 notifications@github.com wrote:

I have been stuck on the same issue for about a week. I also realized the bucket wasn't auto created a few days ago, but I still get a 500 server error when running locally. The app runs as expected when deployed. The symfony app runs in prod mode on app engine, regardless of where you run it (locally or live), because the main app engine yaml file routes through web/app.php. The main config file app/config/config.yml imports into both _prod.yml and _dev.yml config files, but moving DBAL information to the main config file doesn't change anything. One thing I have not been able to try: The composer.json file installs symfony 2.6.* meaning currently when installing dependencies, i get symfony 2.6.11. However, this git was last released with symfony 2.6.3. I am wondering if installing 2.6.3 specifically will make a difference. Will try later tonight.

— Reply to this email directly or view it on GitHub https://github.com/GoogleCloudPlatform/symfony-standard/issues/3#issuecomment-140530315 .

brandonpearson23 commented 8 years ago

@bshaffer I can't check until after work in a few hours, but I believe it was something along the line of: ERROR:root:php failure (255) with:

stdout: Status: 500 Internal Server Error

bshaffer commented 8 years ago

ahh yes, unfortunately that error really could be anything. Have you tried activating PHP error reporting

ini_set('display_errors',1);
error_reporting(E_ALL);

at the very very top of your front controller (web/app.php)?

brandonpearson23 commented 8 years ago

@bshaffer I will try error reporting tonight and respond with results. Until then, I have more information that may help:

I have ruled out that it is an issue with the SDK installation. I was able to get a 200 response and proper output when placing sample code in the "web/app.php" and not routing through symfony's kernal. The kernal request returns information when doing a "var_dump". The 500 error seems to happen once the "web/app.php" file tries to get a response through the "kernal->handle ()" function.

P.S. I'm new to commenting, so sorry I do not know how to format lines of code, etc...

bshaffer commented 8 years ago

No problem. I think I've run into this same issue, but I want to see what you get with verbose debugging to be sure.

brandonpearson23 commented 8 years ago

@bshaffer Even though the default cloud storage is setup, the error reported on localhost is:

Fatal error: Invalid cloud storage bucket name '#default#' in /home/brandon/google-cloud-sdk/platform/google_appengine/php/sdk/google/appengine/api/cloud_storage/CloudStorageTools.php on line 500
brandonpearson23 commented 8 years ago

In the app.yaml file, using #default# in the env_variables was causing a fatal error, so I tried to rename it to the actual bucket name. The error was gone and I was able to access the /clear_cache url. Unfortunately, that is all I am able to do. Now I get a few new errors when trying to access a page, such as /app/example:

Warning: include(gs://bucket-name.appspot.com/symfony/cache/classes.map): failed to open stream: "\google\appengine\ext\cloud_storage_streams\CloudStorageStreamWrapper::stream_open" call failed in /home/brandon/webApps/symfony-standard/app/bootstrap.php.cache on line 2534

Warning: include(): Failed opening 'gs://bucket-name.appspot.com/symfony/cache/classes.map' for inclusion (include_path='.:/home/brandon/webApps/symfony-standard:/home/brandon/google-cloud-sdk/platform/google_appengine/php/sdk') in /home/brandon/webApps/symfony-standard/app/bootstrap.php.cache on line 2534

Warning: array_unique() expects parameter 1 to be array, boolean given in /home/brandon/webApps/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php on line 59

Catchable fatal error: Argument 1 passed to Symfony\Component\ClassLoader\ClassCollectionLoader::getOrderedClasses() must be of the type array, null given, called in /home/brandon/webApps/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php on line 98 and defined in /home/brandon/webApps/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php on line 251
brandonpearson23 commented 8 years ago

Creating a new bucket and attempting to link env_variables to that, resulted in another error:

Fatal error: Uncaught exception 'Symfony\Component\Filesystem\Exception\IOException' with message 'Cannot rename "/tmp/appProdProjectContainer.phpSet88H" to "gs://test-bucket-11/symfony/cache/appProdProjectContainer.php".' in /home/brandon/webApps/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/Filesystem/Filesystem.php:273 Stack trace: #0 /home/brandon/webApps/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/Filesystem/Filesystem.php(474): Symfony\Component\Filesystem\Filesystem->rename('/tmp/appProdPro...', 'gs://test-bucke...', true) #1 /home/brandon/webApps/symfony-standard/app/bootstrap.php.cache(2967): Symfony\Component\Filesystem\Filesystem->dumpFile('gs://test-bucke...', '<?php\nuse Symfo...', NULL) #2 /home/brandon/webApps/symfony-standard/app/bootstrap.php.cache(2683): Symfony\Component\Config\ConfigCache->write('<?php\nuse Symfo...', Array) #3 /home/brandon/webApps/symfony-standard/app/bootstrap.php.cache(2595): Symfony\Component\HttpKernel in /home/brandon/webApps/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/Filesystem/Filesystem.php on line 273
brandonpearson23 commented 8 years ago

@dovy @bshaffer A temporary solution is to change the cache and log directories paths from gcloud, to the default symfony locations:

In app.yaml find env_variables

  CACHE_DIR: "gs://#default#/app/cache"
  LOG_DIR: "gs://#default#/app/log"

Hash tag those lines (to disable them, but save for deployment) and create local folder paths

#  CACHE_DIR: "gs://#default#/app/cache"
#  LOG_DIR: "gs://#default#/app/log"
  CACHE_DIR: "app/cache"
  LOG_DIR: "app/log"

Switch the hash tags before deployment, to disable local paths and enable gs bucket paths.

brandonpearson23 commented 8 years ago

Accessing the cache directly from the filesystem created a host of new issues. The main issue was when trying to use installed bundles (e.g. FoS_UserBundle), the cache files became scattered and doctrine was suddenly "not found". I erased everything and started over. After a clean install following the instructions here https://cloud.google.com/appengine/docs/php/symfony-hello-world?hl=en, I was again getting the Invalid cloud storage bucket name '#default# error. I modified the app.yaml file to:

# Copyright 2015 Google Inc. All Rights Reserved.
# application: <project-id>
# version: 1
runtime: php55
api_version: 1
threadsafe: true

handlers:
- url: /clear_cache
  script: clear_cache.php
  login: admin

- url: /config.php
  script: web/config.php
  login: admin

- url: /.*
  script: web/app.php

env_variables:
  CACHE_DIR: "gs://bucket_name/symfony/cache"
  LOG_DIR: "gs://bucket_name/symfony/log"

I'm using gcloud, so I do not need the application and version variables. I added a url handler for Symfony's config page, so that I could verify my PHP environment was setup correctly. I initially received a couple errors with my setup, but I was able to correct those by modifying the php.ini file to:

; Copyright 2015 Google Inc. All Rights Reserved.
date.timezone=America/Chicago
display_errors=1
google_app_engine.enable_functions="php_sapi_name, libxml_disable_entity_loader"
google_app_engine.allow_include_gs_buckets="#default#,bucket_name"
allow_url_include=1
short_open_tag=off

I am able to create files and access them in the gs bucket. However, I am getting an error when trying to access the /app/example demo page, along with any other page that is created through the front controller web/app.php. The error page outputs:

Fatal error: Uncaught exception 'RuntimeException' with message 'Failed to write cache file "gs://bucket_name/symfony/cache/classes.php".' in /home/brandon/webApps/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php:239 Stack trace: #0 /home/brandon/webApps/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php(122): Symfony\Component\ClassLoader\ClassCollectionLoader::writeCacheFile('gs://bucket_nam...', '<?php \nnamespac...') #1 /home/brandon/webApps/symfony-standard/app/bootstrap.php.cache(2534): Symfony\Component\ClassLoader\ClassCollectionLoader::load(Array, 'gs://bucket_nam...', 'classes', false, false, '.php') #2 /home/brandon/webApps/symfony-standard/app/bootstrap.php.cache(2370): Symfony\Component\HttpKernel\Kernel->doLoadClassCache('classes', '.php') #3 /home/brandon/webApps/symfony-standard/app/bootstrap.php.cache(2404): Symfony\Component\HttpKernel\Kernel->boot in /home/brandon/webApps/symfony-standard/vendor/symfony/symfony/src/Symfony/Component/ClassLoader/ClassCollectionLoader.php on line 239

I followed the trace back to Symfony\Component\ClassLoader\ClassCollectionLoader::writeCacheFile(). That function attempts to modify @chmod of the file to 0666. I don't know if that effects anything. I tried adding the acl, bucket-owner-full-control to the options in the app/AppKernel.php constructor, but nothing changed. I am not sure why there is an now creating cache files. I do not think permissions are an issue, since the cache and log folders were created. I was able to see this by accessing http://localhost:8080/_ah/gcs/bucket_name. The output of that url is:

<ListBucketResult><Contents><Key>hello.txt</Key><LastModified>2015-09-17T18:20:25.000Z</LastModified><ETag>8b1a9953c4611296a827abf8c47804d7</ETag><Size>5</Size></Contents><Contents><Key>symfony/cache/</Key><LastModified>2015-09-17T17:44:53.000Z</LastModified><ETag>d41d8cd98f00b204e9800998ecf8427e</ETag><Size>0</Size></Contents><Contents><Key>symfony/cache/annotations/</Key><LastModified>2015-09-17T17:44:54.000Z</LastModified><ETag>d41d8cd98f00b204e9800998ecf8427e</ETag><Size>0</Size></Contents><Contents><Key>symfony/cache/classes.map</Key><LastModified>2015-09-17T17:44:54.000Z</LastModified><ETag>282e75906e293054f40c39f5f2bd1a5b</ETag><Size>5612</Size></Contents><Contents><Key>symfony/log/</Key><LastModified>2015-09-17T17:44:53.000Z</LastModified><ETag>d41d8cd98f00b204e9800998ecf8427e</ETag><Size>0</Size></Contents><IsTruncated>False</IsTruncated></ListBucketResult>

Trying to develop locally with Symfony and App Engine is becoming a burden. I would really like to continue with app engine, but I am not going to deploy, clear cache and review every time I want to see new changes to my app. I hope a resolution is found soon!

dovy commented 8 years ago

And I can't continue because just using base libraries like FOS causes the file upload limit so I can't deploy. Alas, I had to use Heroku. I hope one day appengine can become viable. We sure wanted to use it.

bshaffer commented 8 years ago

@brandon1499 did you try enabling cloud integration on this page as suggested in the top of this bug? This should create the #default# bucket for you, to get past these errors.

brandonpearson23 commented 8 years ago

@bshaffer Yes I have cloud integration enabled through the app engine settings. The #default# option works as expected on the deployed app. Locally, the #default# bucket is not found. I'm using the cloud sdk on linux and running my app using gcloud preview app run /home/brandon/webApps/symfony-standard/app.yaml --php-executable-path=/usr/bin/php5-cgi. At this point, I cannot afford another week of local app engine configuring, so I may just switch to a managed VM for the time being and run an unmodified version of Symfony. I would still prefer to get this working without taking that step though. :)