Laravel deployment using Google App Engine: No such file or directory

1,907 views
Skip to first unread message

Adeel Ahmad

unread,
Jun 7, 2017, 12:16:14 AM6/7/17
to Google App Engine
I have followed this tutorial and created a database under the name zoho_portal. My app.yaml contents are:


runtime: php
env
: flex

runtime_config
:
  document_root
: public

# required on some platforms so ".env" is not skipped
skip_files
: false

    env_variables
:
     
# The values here will override those in ".env". This is useful for
     
# production-specific configuration. However, feel free to set these
     
# values in ".env" instead if you prefer.
      APP_LOG
: errorlog
      STORAGE_DIR
: /tmp
      CACHE_DRIVER: database
      SESSION_DRIVER: database
      ## Set these environment variables according to your CloudSQL configuration.
      DB_HOST: localhost
      DB_DATABASE: zoho_portal
      DB_USERNAME: USER
      DB_PASSWORD: PASS
      DB_SOCKET: /
cloudsql/zoho-portal-159018:us-central1:zoho-portal

    beta_settings
:
        cloud_sql_instances
: "zoho-portal-159018:us-central1:zoho-portal"

I have also added this to my composer.json:

"post-deploy-cmd": [
   
"chmod -R 755 bootstrap\/cache"
]

However, after deploying this using gcloud app deploy, and visiting the website at: https://zoho-portal-159018.appspot.com/, I receive this error:

SQLSTATE[HY000] [2002] No such file or directory (SQL: select * from sessions where id = iq8isoeEqTaj5xVNmVm0JuFKtR8vtSEB0ajJl23o limit 1)

As far as I can see, I haven't missed any of the steps listed in the tutorial and the database is set up correctly. I also don't think it has anything to do with database migration. From what I can tell, this is an issue with how the socket file is set up.

I already asked this question twice on Stack Overflow and Server Fault, but received no proper response. I would high appreciate if someone would help me resolve this issue, as I have been stuck at this stage for a few weeks.

Thank you.


Javier Pedrera

unread,
Jun 7, 2017, 9:17:38 AM6/7/17
to Google App Engine

Hey Adeel, same happens to me, I've tried many many deploys changing many many things but I can't get this running.

Have you tried to add the unix_socket field in the mysql array in config/database.php? Like this:

'mysql' => [
   
...
   
'password'    => env('DB_PASSWORD'),
   
'unix_socket' => env('DB_SOCKET', ''),
   
'charset'     => 'utf8mb4',
   
...
]

Maybe this works for you.

My files looks exactly the same. I've been stuck into this almost a week too. If you finally solve it, please post it here. Thanks in advance
 

George (Cloud Platform Support)

unread,
Jun 7, 2017, 11:29:30 AM6/7/17
to Google App Engine
Hello Adeel, 

Your app.yaml file is peculiar in some ways. It might be of value to you checking the "Run Laravel on Google App Engine Flexible Environment" instructions page. In the "Set up Database Sessions" subchapter, you do not skip environment variables with "skip_files:
  - .env", and the line for the app key is missing: "APP_KEY: YOUR_APP_KEY". These instructions assume you log in as root, not as user. 

Takashi Matsuo

unread,
Jun 7, 2017, 12:46:16 PM6/7/17
to google-a...@googlegroups.com, Brent Shaffer

Adding the author of the tutorial
--
-- Takashi

Adeel Ahmad

unread,
Jun 9, 2017, 4:33:14 AM6/9/17
to Google App Engine
Hello George,

I have again followed all the instructions on the page you linked. My app.yaml file now looks like this:

runtime: php
env
: flex

runtime_config
:
  document_root
: public


skip_files
: false


env_variables
:
 
# The values here will override those in ".env". This is useful for
 
# production-specific configuration. However, feel free to set these
 
# values in ".env" instead if you prefer.
  APP_LOG
: errorlog
  STORAGE_DIR
:
/tmp
  APP_KEY: base64:KEY

  CACHE_DRIVER: database
  SESSION_DRIVER: database
  ## Set these environment variables according to your CloudSQL configuration.
  DB_HOST: localhost
  DB_DATABASE: zoho_portal
  DB_USERNAME: root
  DB_PASSWORD: PASS
  DB_SOCKET: "/
cloudsql/zoho-portal-159018:us-central1:zoho-portal"

beta_settings:
    cloud_sql_instances: "
zoho-portal-159018:us-central1:zoho-portal"

I also tried adding in unix_socket, but this isn't required in Laravel versions >= 5.4.16 according to the tutorial. But, I am still faced with the "No such file or directory" error when I visit https://zoho-portal-159018.appspot.com/.

I connected to my cloud_sql_proxy by setting -dir="/var/run/mysqld/" and then I ran the migrations. The only thing where I have some doubt is when we migrate our database, I think this is being done locally, because when I run "mysql -h 127.0.0.1 -u root -p -e 'SHOW DATABASES;'" it shows me all my local databases. Could this be the reason why I'm getting the "No such file or directory" error? Please take a look and let me know.

Thank you,
Adeel

George (Cloud Platform Support)

unread,
Jun 12, 2017, 4:21:41 PM6/12/17
to Google App Engine
You still kept the line, in place of the suggested skip_files:  - .env. 

If you want me to take a look, the easiest would be to send your project name by private email, using the drop-down list offered by the "reply" button at the top-right of the window. 

George (Cloud Platform Support)

unread,
Jun 14, 2017, 3:51:44 PM6/14/17
to Google App Engine
How does your final, corrected app.yaml look like? Does it contain a line similar to the following one? 

 # Ensure we skip ".env", which is only for local development
skip_files:
  - .env 

What migration commands did you employ, exactly? 

What is the result of running the "gcloud sql instances describe YOUR_INSTANCE_NAME" command? 
Message has been deleted
Message has been deleted

Javier Pedrera

unread,
Jun 15, 2017, 3:42:42 AM6/15/17
to Google App Engine
Did you finally solve it? If so please don't forget to add the solution, I'm still stuck into it. Thanks.

Adeel Ahmad

unread,
Jun 15, 2017, 9:21:23 AM6/15/17
to Google App Engine
Hi George,

Here are my app.yaml contents:

runtime: php
env
: flex

runtime_config
:
  document_root
: public

skip_files
:
 
 
- .env

env_variables
:
  APP_LOG
: errorlog
  APP_KEY
: base64:BEVs/DqwJFIx+WAhNu/AMgbs3uv4rOyg84kgFgMg81M=
  STORAGE_DIR
: /tmp
  CACHE_DRIVER: database
  SESSION_DRIVER: database

  DB_HOST: localhost
  DB_DATABASE: zoho_portal
  DB_USERNAME: root
  DB_PASSWORD: PASS
  DB_SOCKET: "/
cloudsql/zoho-portal-159018:us-central1:zoho-portal"

beta_settings:
    cloud_sql_instances: "
zoho-portal-159018:us-central1:zoho-portal"Enter code here...

For migrations, I ran the following commands:

  • ./cloud_sql_proxy -instances=zoho-portal=tcp:3307 -dir="/var/run/mysqld/" (ran this from my '~' home directory, used port 3307 as 3306 was busy)
  • mysql -h 127.0.0.1 -u root -p -e "CREATE DATABASE zoho_portal;"
  • php artisan session:table
  • php artisan migrate --force
Here is the output of "gcloud sql instances describe zoho-portal":

connectionName: zoho-portal-159018:us-central1:zoho-portal
etag
: '"S7mq0U3H_YqBSBXO0x5cA9E1UOg/MjI"'
instance
: zoho-portal
instanceType
: CLOUDSQL_INSTANCE
ipAddresses
:
- ipAddress: 104.197.134.245
kind
: sql#instance
project
: zoho-portal-159018
region
: us-central1
serverCaCert
:
  cert
: |-
   
-----BEGIN CERTIFICATE-----
   
MIIDITCCAgmgAwIBAgIBADANBgkqhkiG9w0BAQUFADBIMSMwIQYDVQQDExpHb29n
    bGUgQ2xvdWQgU1FMIFNlcnZlciBDQTEUMBIGA1UEChMLR29vZ2xlLCBJbmMxCzAJ
   
BgNVBAYTAlVTMB4XDTE3MDIyMTE2NTgyM1oXDTE5MDIyMTE2NTkyM1owSDEjMCEG
    A1UEAxMaR29vZ2xlIENsb3VkIFNRTCBTZXJ2ZXIgQ0ExFDASBgNVBAoTC0dvb2ds
   
ZSwgSW5jMQswCQYDVQQGEwJVUzCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoC
    ggEBAKCPDkQPGuLW
+zyms2m5FrqoNmRPwZ5NhfNnvkoEHTsXuOSO9xHULJ8NEVFi
    C5LECS
/Xasnn4OLWtBa1YoRVjDpK2/oXKJCJpp8O53S56wRrasw4LhrUAL28jpOA
   
Yp0YRXUX23Awaj2fqIsAg/8FxN+dkvJ/mH2PP6U987Jcdf4I/7nzL8uR4L3oxK+q
    hLjIL7t5Dtgypw0zXljcTfU58c74mogOBsxGvzysTuI6u
+ajqEufIK2iHBGJtX7B
   
BNz5exUT2bywun25zzyKkR8iHr8y19C0FnjAjfoJBrbxUzq3NUyTQt39bALJZer2
   
7sHYOGmsa/4KU8pKLxI0dnGHhCUCAwEAAaMWMBQwEgYDVR0TAQH/BAgwBgEB/wIB
   
ADANBgkqhkiG9w0BAQUFAAOCAQEAHY6KDZLi7ZgjNPXe+j1H+e7aWzHkyP5F9bYI
   
KyRnsH9TNSHWz6N2W4U3kyYUyg3SgXmQ9r+tuBWVcOsnUDT6Ft87yNz4hWqmTODp
    HR24FmU
+M69MmvRUz0zYJVklBZmsjlyIjg7HjccUmr1tsY+//e7Knmb2S13DdDFO
    e90qtLJ
/qEhJmMA+34CZLy7zAcvhyivWKpQzc9g5/gFgy9STTWrraPYM2FIs8BNH
   
UBqFenNltiaeUAM71Qm7EGPuqBKzCghZkqc5i36rib3nNAIrcmltteW+R9XAO9dJ
   
18A0cmDzconCmCM1nC2IMe0p8sq8Q4XAe6ZlHiSqq2SyFbCTpA==
   
-----END CERTIFICATE-----
  certSerialNumber
: '0'
  commonName
: C=US,O=Google\, Inc,CN=Google Cloud SQL Server CA
  createTime
: '2017-02-21T16:58:23.901000+00:00'
  expirationTime
: '2019-02-21T16:59:23.901000+00:00'
  instance
: zoho-portal
  kind
: sql#sslCert
  sha1Fingerprint
: f9542f8127049fbd53fc7fd31bd354d4d193b342
serviceAccountEmailAddress
: cf7gohcs4bai7ifkuygjlj2qgq@speckle-umbrella-7.iam.gserviceaccount.com
settings
:
  activationPolicy
: ALWAYS
  backupConfiguration
:
 
- binaryLogEnabled: true
    enabled
: true
    id
: 2c4b4c97-96e8-45e2-8f84-0f799259c262
    kind
: sql#backupConfiguration
    startTime
: 08:00
  ipConfiguration
:
    enabled
: true
    kind
: sql#ipConfiguration
  kind
: sql#settings
  pricingPlan
: PER_USE
  replicationType
: SYNCHRONOUS
  settingsVersion
: '22'
  tier
: db-f1-micro
state
: RUNNABLE

George (Cloud Platform Support)

unread,
Jun 16, 2017, 4:50:19 PM6/16/17
to Google App Engine
Hi Adeel!

The tutorial you mentioned surely works well. What steps differ in your case, from the tutorial? Any small detail may count, so if you provide an exhaustive list of differences, you enable us to properly reproduce the issue on our side. 

Adeel Ahmad

unread,
Jun 20, 2017, 1:07:21 AM6/20/17
to Google App Engine
Hi George,

I have gone through the tutorial again and these are the steps which differ from it:

  1. I haven't added the following script in my composer.json file as it causes some errors during deployment:
    "post-deploy-cmd": [
        "php artisan cache:clear"
    ]
  2. In the tutorial, cloud_sql_proxy is installed globally, but I run this from my home directory (~). Also, the port used
    in the tutorial is 3306, but I'm using 3307
    , instead. This is the command that I execute:

  1. ./cloud_sql_proxy -instances=zoho-portal=tcp:3307 -dir="/var/run/mysqld/"
  1. I also provide it a path to my socket file, which is not done in the tutorial.
  2. The database in the tutorial is named laravel, but I named it zoho_portal. I don't think this causes any problems, though.

Please let me know if any of the above mentioned differences let you debug the problem. Also, the source code is hosted on my
GitHub repository. This might help you run this from your end.


Thank you,

Adeel

George (Cloud Platform Support)

unread,
Jun 20, 2017, 4:43:51 PM6/20/17
to Google App Engine
Hi Adeel, 

At point 2 of your reply above, the way you employ the "-dir=" parameter does not correspond to any possible options, for cloud_sql_proxy. You can compare and gather more relevant detail in the "Example proxy invocations and mysql client connection strings" sub-chapter of the "About the Cloud SQL Proxy" online document

To refer to a local directory, you need to have FUSE (Filesystem in User Space) installed. 

Adeel Ahmad

unread,
Jun 22, 2017, 2:21:56 AM6/22/17
to Google App Engine
Hi George,

I just tried the command without the -dir part, like this:

./cloud_sql_proxy -instances=zoho-portal=tcp:3307

But, I'm still faced with the same issue. Would it be possible for you to clone my GitHub repo and try deploying it from your side.

Thanks,
Adeel

George (Cloud Platform Support)

unread,
Jun 23, 2017, 4:37:19 PM6/23/17
to Google App Engine
Hi Adeel, 

Needing some extra time to reproduce; your understanding is highly appreciated. 

Adeel Ahmad

unread,
Jun 30, 2017, 1:37:49 AM6/30/17
to Google App Engine
Hello George, any update with the progress? Thanks!

George (Cloud Platform Support)

unread,
Jun 30, 2017, 3:23:35 PM6/30/17
to Google App Engine
Hi Adeel, 

Again unable to reproduce. I cloned your app, deployed, installed the cloud proxy and ran the command: ./cloud_sql_proxy -instances=[project name]=tcp:3307 -credential_file=[name of credentials file].json. In short, the good news is that your app works exactly as it is. 

You can install the local Cloud SQL Proxy as specified on the "About the Cloud SQL Proxy" documentation page

To create the appropriate service account and get the credentials *.json file, you can consult the "Creating and Enabling Service Accounts for Instances" page

Alkaid Cruz Llanes

unread,
Apr 5, 2018, 4:18:52 PM4/5/18
to Google App Engine
Hello Adeel, Have you finally solved this problem?
Reply all
Reply to author
Forward
0 new messages