Deploying Laravel app to Google App Engine - php

I am trying to deploy my Laravel 7.29.3 app to Google App Engine Standard environment. I have followed the guided located here https://cloud.google.com/community/tutorials/run-laravel-on-appengine-standard. However, I get a View[Welcome] not found error when I view my deployment. My app.yaml file looks like below:
runtime: php72
env_variables:
## Put production environment variables here.
APP_KEY: YOUR_APP_KEY
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
SESSION_DRIVER: cookie
Its a very simple yaml file as I am only using the welcome view and a route to a contact page. Please note that I am not using any database in this version. Please see my routing below:
<?php
use Illuminate\Support\Facades\Route;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::post('contact', 'ContactFormController#ContactForm');
I also reviewed this question here: View [welcome] not found but I am still getting the same error. From my understanding of #sllopis comment, I need to put my welcome.blade.php file in a layouts folder. I have done that, and still get the same error. Any assistance would be appreciated.
Thanks

I have found the solution. First you can add handlers to your app.yaml file. It should look like below:
runtime: php72
handlers:
- url: /(.*\.(gif|png|jpg|css|js))$
static_files: public/\1
upload: public/.*\.(gif|png|jpg|css|js)$
- url: /.*
secure: always
redirect_http_response_code: 301
script: auto
env_variables:
## Put production environment variables here.
APP_KEY: YOUR_APP_KEY
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
SESSION_DRIVER: cookie
Source: https://stackoverflow.com/a/57822141/2251229
Then you can update your config/filesystems.php file. You can add a new file system as per the sample provided below.
'gcs' => [
'driver' => 'gcs',
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'),
'key_file' => env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json
'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'),
'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null), // optional: /default/path/to/apply/in/bucket
'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below
'visibility' => 'public', // optional: public|private
],
And then update your default file system like so:
'default' => env('FILESYSTEM_DRIVER', 'gcs'),
Install the Laravel Google Cloud Storage package using the below command:
composer require superbalist/laravel-google-cloud-storage
Source: https://stackoverflow.com/a/57177913/2251229
From here you can do your gcloud app deploy, and gcloud app browse. If you get further errors, do php artisan config:clear. This should clear any cached configurations.

Related

HTTP 500 response and white screen while trying to deploy laravel 8 app to hostinger shared hosting

The title sums up my issue. I'm deploying to shared hosting by uploading my files (except mylaravelproject/public/ to the root directory, and the contents of mylaravelproject/public/ to public_html/.
I've already tried the following:
Configuring index.php to point to the correct folder in root
Running composer install and npm install in the relevant directory
php artisan key:generate
php artisan cache:clear and php artisan config:clear
composer dump-autoload
Configuring .env and changing the relevant fields: APP_URL and database related ones
I'm still met with a white screen and an HTTP 500 error. What should I do?
Whoops! I was able to solve it on my own somehow. Thanks to everyone who replied still.
For anyone having similar issues:
Start by adding the following to the top of index.php:
ini_set('display_errors', '1');
ini_set('display_startup_errors', '1');
error_reporting(E_ALL);
Turns out hpanel / hostinger's directory structure is weird, and public_html/ from the file manager is actually a shortcut to a folder not directly under root. Here's what it actually looks like:
/
| - domains
| - yourdomainname.com
| - public_html
| - index.php
So unlike most guides out there, relevant directories under index.php need to be changed to something like __DIR__.'/../../../laravelinrootname/storage/framework/maintenance.php'
Enable debugger to know the issue
inside Config/App.php change
'debug' => env('APP_DEBUG', false)
to
'debug' => env('APP_DEBUG', true)
& in .env make APP_DEBUG= true
APP_ENV=local
APP_DEBUG=true

Problem with Symbolic links in PHP\Laravel

I am using Laravel 7 on Direct admin. I don't actually have access to Command Line/Terminal, and I need a Symbolic link of Storage.
I have Tried:
Route::get('/foo', function () {
Artisan::call('storage:link');
});
and also:
symlink('/domains/MyProject.com/LaravelFolder/storage/app/public', '/domains/MyProject.com/public_html');
But I am receiving this Error:
symlink() has been disabled for security reasons
My LaravelFolder is Placed before public_html.
UPDATE: I realized that the Hosting company disabled this function; I asked them to enable it, But They say: it is impossible. Do you know an alternative way to do that?
Old Solution
But I finally Solved This, It seems little bit stupid but it works:
In Ubuntu Linux I tried to create a symlink like the storage symbolic link in Laravel, with the following Command:
ln -s ../laravelFolder/storage/app/public storage
and then I compressed this symbolic link and uploaded to my public_html Folder and it works.
I hope it will be Helpful..
2022 UPDATE (New Solution)
In such cases that your projects production environment is a Linux server and you are developing your project on Windows I offer you to set up a WSL (Windows Subsystem for Linux) development environment.
This way you can simply use Linux terminal to creating a symbolic link with the following command:
// change laravelFolder with your laravel folder name
ln -s ../laravelFolder/storage/app/public storage
Here is Microsoft's quick guide to install and use WSL.
You can modify the public disk's root path to point directly public folder. Consider the below snippet;
/** /config/filesystems.php */
'disks' => [
// ...
'public' => [
'driver' => 'local',
'root' => public_path('storage'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
// ...
],
Note that this is not a best practice.

Deploy Laravel 6 App on Google App Engine Standard Error: Please provide a valid cache path

I've been trying to deploy my Laravel 6 App to the standard environment of Google App Engine the whole day, but seems like I'm just stuck at how to make cache and some "local" files to work.
This is the error I get when I try to load any page:
(1/1) InvalidArgumentException
Please provide a valid cache path.
in Compiler.php line 36
at Compiler->__construct(object(Filesystem), false)
in ViewServiceProvider.php line 92
at ViewServiceProvider->Illuminate\View\{closure}(object(Application), array())
in Container.php line 799
at Container->build(object(Closure))
in Container.php line 681
at Container->resolve('blade.compiler', array(), true)
in Application.php line 785
(...)
I followed every tip at this question, this tutorial and this issue, but anything seemed to help me.
As CACHE_DRIVER, for convenience, I'm trying to just use file, instead of database or any other else. So, my app.yaml, have the additional env_variables :
CACHE_DRIVER: file
SESSION_DRIVER: cookie
APP_STORAGE: /tmp
VIEW_COMPILED_PATH: /tmp
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
I know that the /tmp folder is the only writable folder for the App Engine Standard Environment. With that in mind, I put the above at app.yaml, and even tried renaming /storage folder to /tmp.
I've added the following line to my bootstrap/app.php file:
$app->useStoragePath(env('APP_STORAGE', base_path() . '/tmp'));
At my composer packages, I made sure that it doesn't have facade/ignition. Also, as I can't run any command after deploy my app to Google App Engine, at composer.json I have:
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
],
"post-install-cmd": [
"composer dump-autoload",
"php artisan config:clear",
"php artisan view:clear",
"php artisan cache:clear"
]
I also tried to put at post-install-cmd php artisan storage:link, while using $app->useStoragePath(env('APP_STORAGE', base_path() . '/storage')); and the /storage folder as storage itself, but nothing worked.
I have the whole folder tree for caching at my /temp (or /storage, if this is the right way) folder:
/tmp
/framework
/cache
/data
/sessions
/testing
/views
/logs
/medialibrary
/temp
Also, besides the views not rendering, I noticed that when trying to load the favicon.ico, located at /public folder, it returns an 500 error. I am new to AppEngine, but even reading everything I can find I've been struggling to make it work. I really appreciate any help.
I figured out I had some config files published at /config, and besides changing /bootstrap/app.php, some of them had their own path to /storage folder. So, my solution was just gave up on using files cache, and for the views cache, and some other packages I had, use the path /tmp, at their respective config files. Also, I removed all cache cleaning artisan commands from composer, as I wasn't sending any cache files to deploy.
Also, I needed to make some changes in order to be able to access /public files, like some local css and js. For this, I followed these docs.
I was struggling with the same problem today and the solution was I changed the 'compiled' value in config/view.php to a root folder:
Go to root directory.
mkdir compiled_views
Change 'compiled' value to 'compiled' => realpath(base_path('compiled_views/')),
I solved it by explicitly adding the APP_STORAGE env in config/view.php:
'compiled' => realpath(env('APP_STORAGE', realpath(storage_path('framework/views')))),
(which surprises because I do have $app->useStoragePath(env('APP_STORAGE', base_path() . '/storage')); added to app.php - but it seems that it didn't yet(?) override storage_path )

symfony2 assets targets the /www server folder, not the /web symfony folder when deploy in production

I have some problems with Symfony 2 application deployment. I have import all files I need on my OVH shared server, but some errors occured like css and js files not found (internal server error for example) or error like Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://my-server/css/458dafd_bootstrap-theme.min_1.css".
Notice that I have installed the CoresphereBundle in order to have a console in my browser when my application is iploaded on my server, I have access to the console only on dev environment.
This is step by step what I did in order to deploy my application:
1 I updated my application and vendors with composer (because I have no ways to install composer on my server)
composer.phar update
2 I clear the dev cache php app/console cache:clear
3 I clear the prod cache php app/console cache:clear --env=prod --no-debug
4 I install assets php app/console assets:install web
5 I dump the assets php app/console assetic:dump web
6 I uploaded my symfony application on my server.
7 Once the files are uploaded in web/app.php I I authorize
the prod debug
$kernel = new AppKernel('prod', true);
8 Then in web/config.php I remove this block
// …
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
))) {
header('HTTP/1.0 403 Forbidden');
exit('This script is only accessible from localhost.');
}
So, on my server, if I would like to go to http://my-server/web/config.php it works well, so I see if my server is compatible with symfony. the only thing that appears is Set short_open_tag to off in php.ini*.
9 I set the access rights for the app/cache and app/log folders to 777 on my server, it allows the applications to write in these folders.
10 In web/app_dev.php I write this code, in order to allow the dev mode for my IP adress and so have access to the console bundle
// …
if (!in_array(#$_SERVER['REMOTE_ADDR'], array(
'127.0.0.1',
'::1',
'121.457.719.2' //a random ip adress it's just for you to understand
))) {
header('HTTP/1.0 403 Forbidden');
exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
}
11 So I have access to the dev environment on my server, all works well, and no errors occured here. To access to the console bundle, following to the bundle documentation, I have to wrote http://my-server/web/app_dev.php/_console (see the routing code here):
_console:
resource: "#CoreSphereConsoleBundle/Resources/config/routing.yml"
prefix: /_console
But this routes does not exist, If I wrote this url, nothing appear in my browser:
However, by the config.php, I have access to app_dev.php by following the Bypass configuration and go to the Welcome page link:
I click on the link and I arrived on app_dev.php. Like I said before, no errors occured in this environment, except for the console route. But I could have access to the console by clicking on the console logo under the symfony debug toolbar:
This is the url for the console when I click on the logo under symfony debug toolbar: http://my-server/web/app_dev.php//_console/_console, I would like to understand why?
Then when I would like to make some commands another error occured: [error] Internal Server Error in the console:
If I try to use the router debug php app/console debug:router, I have this:
and with the php app/console debug:router | grep _console:
So, there are the problems I have with my symfony application.
UPDATE
I resolved the problem of the console bundle. In fact my server does not use the same php version of my symfony application, I have to set this in the .ovhconfig at the root of my /www folder.
/www/.ovhconfig:
app.engine=php
app.engine.version=5.5
http.firewall=none
environment=production
Now when I would like to access to the production environment I have these errors concerning all my assets files (css/js/images, a 404 not found):
Failed to load resource: the server responded with a status of 404 (Not Found) -> http://my-server.com/bundles/fosjsrouting/js/router.js
Uncaught ReferenceError: fos is not defined -> routing:1
Failed to load resource: the server responded with a status of 404 (Not Found)
->http://my-server.com/css/45898d_dataTables.min_7.css
I don't really understand, the files are indeed at the root of the app, e-g I have no folder css or js or etc in http://my-server.com/. These folders are in http://my-server.com/web/. Where is the problem?
When I access to the console, this is the command I made:
1 cache:clear
2 assets:install web
3 assetic:dump web
EDIT: solution works
I understand that the assets target a /css /js /images etc folder at the root of my server, so I replace the css and js files to the root of the /www server folder, e-g in the /www folder of my server I have this:
//my server
/.ssh
/www /*http://my-server.com/...*/
/app/
/bin/
/css/
/fonts/
/images/
/js/
/src/
/vendor/
/web/
/.htaccess
/.ovhconfig
/composer.json
/composer.lock
/composer.phar
Why my symfony application tagets the assets here?
Have you tried to use the Symfony command line routing debugger?
php app/console debug:router
That will output all the routes the symfony app knows about and you could try piping it into grep to see if you're trying to use the wrong path to hit the _console route.
php app/console debug:router | grep _console

Laravel 5.0 configuration file mail.php not loaded

I have a problem with the configuration in Laravel 5.0
I configured an environment local from an .env file. The machine is a homestead machine and i removed the APP_ENV from the Homestead.yaml just to be sure.
Environment is set to local and i confirmed by prompting $app->environment()
I added a few configuration files to the local config directory (local/filesystems.php, local/mail.php, local/services.php). The interesting thing is the filesystems.php gets loaded but the mail one not. If i dump the getConfigurationFiles() from Illuminate\Foundation\Bootstrap\LoadConfiguration i get
array:11 [▼
"app" => "/home/vagrant/Code/molkerei/config/app.php"
"auth" => "/home/vagrant/Code/molkerei/config/auth.php"
"cache" => "/home/vagrant/Code/molkerei/config/cache.php"
"compile" => "/home/vagrant/Code/molkerei/config/compile.php"
"database" => "/home/vagrant/Code/molkerei/config/database.php"
"filesystems" => "/home/vagrant/Code/molkerei/config/local/filesystems.php"
"mail" => "/home/vagrant/Code/molkerei/config/mail.php"
"services" => "/home/vagrant/Code/molkerei/config/services.php"
"queue" => "/home/vagrant/Code/molkerei/config/queue.php"
"session" => "/home/vagrant/Code/molkerei/config/session.php"
"view" => "/home/vagrant/Code/molkerei/config/view.php"
]
I already tried to clean the cache with php artisan cache:clear but there is not even a cache file (it is set to filesystem)
Any idea why the configuration is not loaded properly?
At the time of writing this answer - there are no more 'sub directories' for config like there used to be in L4 - You now have one main configuration folder.
You overwrite any default config with specific config from your '.env' file if required.
So in your app\config\mail.php file you would write:
'driver' => env('MAIL_DRIVER', 'mandrill'),
Which means it will use Mandrill by default - unless in your .env file you put
MAIL_DRIVER=smtp
which means on your homestead server it will now use SMTP to send the mail.
p.s. I do not know why filesystems loads the local config in your example - it is probably a bug.

Categories