How to run Larvel's php artisan commands on Google App Engine - php

I have my staging site for a Laravel app hosted on a Google App Engine instance. The production site is hosted on Compute Engine and isn't a managed server so I am not as familiar with the set up on GAE - I wanted to try it out in order to eventually move our production site onto a managed server.
I'm having an issue where I can't figure out how to run php artisan commands on staging! I managed to use the google sdk and the cloud sql proxy in order to access the staging database, and I assumed I could use some kind of gcloud command to run the artisan command, like something like gcloud --compute="php artisan migrate" but I can't figure out the best way to do it.
I also have tried using GCP's in-app terminal to ssh into the instance, but it seems like I have no access to the actual project files within that ssh so I can't run the artisan commands.
Does anyone know best practices for running a migration on this type of server?
I'm also using an app.yaml file to build the instance, so I was thinking maybe I should figure out how to put the command there, but I'm not sure if that's the right move as the only information I have in that file is the env info and server resources info.
Please help! thank you :)

One way of running migrations to your laravel project that is hosted on Google App Engine would be to connect your local environment project to the project's Google Cloud SQL. From there you can just run the migrations from your local environment.

Like #TMK said, connect through the SQL proxy. It's simple.
Create an SQL instance using the instructions found here
Follow the instructions here
with that done, you can run your migration command right from your bash terminal

Related

How to setup Laravel application in AWS Elastic Beanstalk using external RDS database

I want to start deploying my laravel app to production. To avoid changing AWS config in the near future, I decided to try to add continuous integration. To do this I'm using elastic beanstalk and pushing the code there using another AWS tool. All this is working perfectly. I put a test message in /public/index.php to output "hello world" and it works as expected when going to the URL. When I remove this text and run my laravel app as normal, I get a 500 internal server error. I'm not sure all what elastic beanstalk does on deployment for laravel apps. Because of this I'm not sure if this error is occurring from a bad DB connection or laravel app not fully setup yet.
I created an RDS DB instance outside of elastic beanstalk. I am able to access this from sequel pro and I added the database I will use to store all my data. I added all the necessary db connection values (host, port, database, username, password) to /config/database.php and the elastic beanstalk server configuration environment variables.
I've searched online for days for info but haven't found anything specific to this. Also part of my issue is a lack of understanding of how laravel is setup during a deployment in beanstalk. Is there something with /.ebextensions that will help me accomplish these goals?
When I deploy my code I need to make sure all vendor files are installed through composer and then I also need to make sure all database migrations/changes happen. I want to automate as many steps as possible so I can just push up code changes and server will change code and keep working.
I also want to make sure there isn't anything I'm missing for setting up my db connection. Are there any other files in laravel I need to setup or something in elastic beanstalk I need to have configured? I'm keeping my db open to all connections and then I can tighten restrictions later
EDIT: My database may not be configured correctly yet, but that appers to not be source of the issue. I think my issue is knowing what scripts and how to run them during deployment. I want to make sure composer and php artisan migrate is ran to keep everything up to date. How can I do this with elastic beanstalk?
This is a little off topic but with my experience I do not recommend using beanstalk to achieve a good workflow pushing and deploying. I recommend
you to use Forgelaravel.com to deploy your GitHub repository. In forge Laravel you will be able to create a server from AWS and it will automatically create database connections and stuffs, then with just one click you can deploy to the server and keep a good workflow.
Given that we're speaking of a Laravel application, this 500 Server Error
often occurs when one is creating new infrastructure. Why? It's likely to forget to add the environment variables to the EB environment.
Simply go to that EB environment configuration, then under software modify to include at least the following environment properties
APP_DEBUG (can be, for example, false)
APP_KEY (this is the key generated with php artisan key:generate)
APP_NAME (tiagoPeres)
Then the issue will be gone.

How to run php websoket server file(server.php) on google cloud server oR AWS

I have setup my php websocket application on google cloud and i have test it using cloud shell and putty terminal after running my server.php file but i want to run this file permanently so I am unable to do this.So please help me about it.
We can talk about two options:
The App Engine for standard or flex, but the websockets has limitations for php.
The second option is Compute Engine, we have to prepare the environment (apache), and assign the Public IP.
Please check the next links:
https://cloud.google.com/community/tutorials/setting-up-lamp
http://socketo.me/docs/hello-world

Laravel MySQL Google App Engine - ERROR: (gcloud.sql.instances.describe) There was no instance found

I deployed my Laravel 5.6 application using Google App Engine following these steps. The Laravel app is live at a URL but I am having trouble getting MySQL set up.
I created a 2nd generation MySQL development database, then installed the Cloud SQL Proxy client on my macbook. When I try to connect to the instance I get an error that no instance was found. What am I doing wrong?
Here are the commands I ran to get my app started
$ gcloud init
$ gcloud app deploy
$ gcloud app browse
$ curl -o cloud_sql_proxy https://dl.google.com/cloudsql/cloud_sql_proxy.darwin.amd64
$ chmod +x cloud_sql_proxy
$ gcloud sql instances describe laraveljwtstarter
ERROR: (gcloud.sql.instances.describe) There was no instance found at
projects/laraveljwtstarter/instances/laraveljwtstarter or you are not
authorized to access it.
My instance is named laraveljwtstarter that I created through the Google Cloud Platform UI. How can I connect my Laravel app to this database?
Well, first of all you are not connecting to the instance with the commands that you have shared.
gcloud sql instances describe laraveljwtstarter - this command simply displays configuration and metadata about a Cloud SQL instance named laraveljwtstarter. As it has already been mentioned above, please make sure that the database is created before running that command and make sure you are specifying the correct database name.
If you wish to connect to the database using the Cloud SQL Proxy, you will have to first off start it up like it says in the article you mentioned. As far as I understood, you have an application in App Engine, therefore you are using the wrong example from the documentation. Generally, if you want to connect your GAE app with the Cloud SQL instance, there is a number of options, depending if you are using App Engine Standard environment or Flexible environment. Both options are available for PHP and you can read more here.
Normally you use the Cloud SQL Proxy because it provides secure access to your Cloud SQL Second Generation instances without having to whitelist IP addresses from which you will be connecting or having to configure SSL. You will need a Cloud SQL Proxy for your application to connect to the Cloud SQL database locally. For a deployed application there is no need for setting up a Cloud SQL Proxy.
Also, here is a short, but informative video about using Cloud SQL in App Engine.
I know that my answer is broad, but you should post a more specific question to get a specific answer.
Nevermind, just make sure the database created through the UI has actually been created!

Gcloud beta emulators data store start error Google/Cloud is not recognized as an internal or external command

In developing php appengine standard app, I wanted a local development datastore so I ran- gcloud components install cloud-datastore-emulator
I also installed google cloud data store globally using
composer require google\cloud_datastore
After that tried to start the emulator with
gcloud beta emulators datastore start --data-dir="C:\Users\Hellen\Desktop\New folder\myDstore"
But the command failed with the following output.
WARNING: Reusing existing data in [C:\Users\Hellen\Desktop\New folder\myDstore].
Executing: cmd /c C:\Users\Hellen\AppData\Local\Google\Cloud SDK\google-cloud-sdk\platform\cloud-datastore-emulator\cloud_datastore_emulator.cmd start --host=localhost --port=8081 --store_on_disk=True --consistency=0.9 --allow_remote_shutdown C:\Users\Hellen\Desktop\New folder\myDstore
[datastore] 'C:\Users\Hellen\AppData\Local\Google\Cloud' is not recognized as an internal or external command,
[datastore] operable program or batch file.
Can someone tell me what the problem is? I really don't know what next to try.
The problem was that I had both app engine server installed and Google cloud SDK, and both have similar commands. So I uninstalled both and installed only gcloud SDK. Thanks so much for the hint.

Laravel Deployment

I have a working Laravel application on my desktop. I am trying to deploy it to a godaddy server. The application has been copied and verified on the server in the same structure format as on my desktop. I have changed the database information in the config to the proper entries. When I run from the server I get the error:
FatalErrorException
Class 'name of the class' not found.
The error is generated in the Routes.php file.
Again this app works locally, any idea why it errors when deployed?
Assuming you have a VPS server running Apache (or whatever else) with a a properly configured vhost and terminal (ssh) access, if you want deploy a Laravel app there, you surely need to
Copy all project files, except for the vendor directory, from localhost to your server
Verify file ownage and access rights (chown/chmod)
Change all necessary config
run a composer update
run php artisan migrate to create the database scheme
clear cache php artisan cache:clear
Next thing is populating the database with your apps data from localhost. You can either do it manually (dump sql local, import it on server), or if you want Laravel for it you can use Seeding (Laravel docs).
There even is a nice package that let's you automaticaly generete Seeders from your current database content - so it's very useful for the purpose of moving the app to another server.
https://github.com/orangehill/iseed
Inverse seed generator (iSeed) is a Laravel 4 package that provides a
method to generate a new seed file based on data from the existing
database table.
EDIT
If you are using a shared hosting account, check out this guide
http://driesvints.com/blog/laravel-4-on-a-shared-host
This post from Laravel forum might also be of use
http://forums.laravel.io/viewtopic.php?id=9639

Categories