Symfony - How to set from dev to prod? - php

I know that this is not the first post about this question, but I do it because others answers didn't solve my problem.
I tried the basic :
$kernel = new AppKernel('prod', true);
But this is not the good way to do it because I still have Symfony errors...
I don't know how to rewrite errors pages :
http://le-blog-etudiant.fr/blablabla
Do you know if this Symfony error is caused by the fact that my website is still in dev mode or because my error.html.twig page doesn't work ?
EDIT 1 :
I'm using app.php on my site, I set $kernel = new AppKernel('prod', false); and I did the command : php bin/console cache:clear --env=prod but it still display Symfony's errors

Because you need to do this :
$kernel = new AppKernel('prod', false);
Here is the constructor of AppKernel :
/**
* Constructor.
*
* #param string $environment The environment
* #param bool $debug Whether to enable debugging or not
*/
public function __construct($environment, $debug)

Permission denied here showing your problem http://le-blog-etudiant.fr
You have to give permission
chmod 777 -R var/cache
chmod 777 -R var/cache/*
Other problems then we will check...

Related

Laravel on App Engine Standard: The /srv/bootstrap/cache directory must be present and writable

I've been struggling with the Google App Engine Standard environment for a day now.
The error is as follows:
PHP Notice: Exception: The /srv/bootstrap/cache directory must be
present and writable. in
/srv/vendor/laravel/framework/src/Illuminate/Foundation/PackageManifest.php:168
I know that the /tmp folder is the only writable folder for the App Engine Standard environment. Therefore, my app.yaml have the following additional env_variables:
APP_STORAGE: "/tmp"
VIEW_COMPILED_PATH: "/tmp"
...my bootstrap/app.php contains this line:
$app->useStoragePath(env('APP_STORAGE', base_path() . '/tmp'));
...and my composer.json has these scripts to account for the change in configuration:
"post-autoload-dump": [
"Illuminate\\Foundation\\ComposerScripts::postAutoloadDump"
],
"post-install-cmd": [
"composer dump-autoload",
"php artisan config:clear",
"php artisan cache:clear",
"php artisan view:clear",
"php artisan cache:clear",
"php artisan regenerate:schoolCSS"
]
These are my drivers configured in app.yaml:
SESSION_DRIVER: database
BROADCAST_DRIVER: log
CACHE_DRIVER: database
QUEUE_DRIVER: sync
For some reason, I just can't seem to find a way to make the /tmp folder the folder where the cached views and config are put. Actually, I suspect that the ...:clear commands aren't even properly ran at all.
My application is just a blank white page now, regardless of the path. That's fair, as due to the unwritable cache, the views cannot be rendered and stored there.
The above configurations should match the tutorials for installing Laraval on Google App Engine Standard, such as this one: https://cloud.google.com/community/tutorials/run-laravel-on-appengine-standard.
In the cloud console, I've checked whether the /tmp folder exists, which is the case.
Anyways, all help is dearly appreciated. If you need more code snippets, just ask. I'll be happy to provide them.
I found a simple solution for this problem. The directory where the Laravel application lives on Google App Engine Standard is read-only. So you have to write the cache files to /tmp.
You can change the paths by simple adding this environment variables to your app.yaml
APP_SERVICES_CACHE: /tmp/services.php
APP_PACKAGES_CACHE: /tmp/packages.php
APP_CONFIG_CACHE: /tmp/config.php
APP_ROUTES_CACHE: /tmp/routes.php
Your app.yaml and bootstrap/app.php look good.
But there is one more thing that you need to do:
If you're on Laravel 6 or above, remove facade/ignition dependency:
composer remove --dev facade/ignition
OR
If you're on Laravel 5 or older, remove beyondcode/laravel-dump-server instead:
composer remove --dev beyondcode/laravel-dump-server
This is what the community doc that you mentioned has to say about this:
This is a fix for an error which happens as a result of Laravel's caching in bootstrap/cache/services.php.
Community tutorial on setting up Laravel in App Engine Standard Environment.
Before deploying try:
php artisan route:clear
php artisan view:clear
php artisan config:clear
php artisan cache:clear
php artisan optimize:clear
For me it was optimize:clear
Could this be related to the fact that in Illuminate\Foundation\Application.php the paths are resolved from $this->bootstrapPath() (which returns an absolute path) when executed normally but seem to be taken as is from the APP_CONFIG_CACHE variable and others when running tests ?
/**
* Get the path to the configuration cache file.
*
* #return string
*/
public function getCachedConfigPath()
{
return Env::get('APP_CONFIG_CACHE', $this->bootstrapPath().'/cache/config.php');
}
Replacing it like this seems to do the job on my side.
/**
* Get the path to the cached services.php file.
*
* #return string
*/
public function getCachedServicesPath()
{
return $this->basePath(Env::get('APP_SERVICES_CACHE', 'bootstrap/cache/services.php'));
}
/**
* Get the path to the cached packages.php file.
*
* #return string
*/
public function getCachedPackagesPath()
{
return $this->basePath(Env::get('APP_PACKAGES_CACHE', 'bootstrap/cache/packages.php'));
}
/**
* Get the path to the configuration cache file.
*
* #return string
*/
public function getCachedConfigPath()
{
return $this->basePath(Env::get('APP_CONFIG_CACHE', 'bootstrap/cache/config.php'));
}
/**
* Get the path to the routes cache file.
*
* #return string
*/
public function getCachedRoutesPath()
{
return $this->basePath(Env::get('APP_ROUTES_CACHE', 'bootstrap/cache/routes.php'));
}
/**
* Get the path to the events cache file.
*
* #return string
*/
public function getCachedEventsPath()
{
return $this->basePath(Env::get('APP_EVENTS_CACHE', 'bootstrap/cache/events.php'));
}
Then
give permission
sudo chmod -R 775 bootstrap/cache/
Run the bellow command
php artisan config:cache

Symfony throws error but not 404 page

The problem is I see trace error pages in production mode, in Symfony app.
I have this in app.php:
$kernel = new AppKernel('prod', true);
And I have done:
php app/console cache:clear --env=prod
Ok, I was completely wrong! The purpose of the second parameter in $kernel = new AppKernel('prod', true); is to enable/disable the debug mode. You can read the doc here: https://symfony.com/doc/current/configuration/environments.html
The issue was solved by setting to false the debug mode.

composer install pass command line argument or parameter to bin/console

I'm trying to make my symfony 3.0 app capable to work with multiple kernel.
real aim : Multiple applications in one project
Generally everything is OK. I edited bin/console it's content exactly as the following. It works exactly and results what I need via php bin/console --app=api
But when I execute composer install bin/console throws the Exception naturally it doesn't knows about --app parameter. I want to make something like composer install --app=api and desired behaviour it would pass the parameter to bin/console I checked documentation and almost every pixel of the internet couldn't find a solution.
#!/usr/bin/env php
<?php
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Debug\Debug;
// if you don't want to setup permissions the proper way, just uncomment the following PHP line
// read http://symfony.com/doc/current/book/installation.html#configuration-and-setup for more information
//umask(0000);
set_time_limit(0);
/**
* #var Composer\Autoload\ClassLoader $loader
*/
$loader = require __DIR__.'/../apps/autoload.php';
$input = new ArgvInput();
$env = $input->getParameterOption(array('--env', '-e'), getenv('SYMFONY_ENV') ?: 'dev');
$app = $input->getParameterOption(array('--app', '-a'));
$debug = getenv('SYMFONY_DEBUG') !== '0' && !$input->hasParameterOption(array('--no-debug', '')) && $env !== 'prod';
if ($debug) {
Debug::enable();
}
switch ($app) {
case 'api':
$kernel = new ApiKernel($env, $debug);
break;
case 'frontend':
$kernel = new FrontendKernel($env, $debug);
break;
default:
throw new \InvalidArgumentException("[--app|-a=<app>] app: api|frontend");
break;
}
$application = new Application($kernel);
$application->getDefinition()->addOptions([
new InputOption('--app', '-a', InputOption::VALUE_REQUIRED, 'The application to operate in.'),
]);
$application->run($input);
You can use composer install --no-scripts to prevent automatically running app/console after installation.
Or you can remove the the bin/console commands from the scripts section in your composer.json altogether, which probably makes more sense. See https://github.com/symfony/symfony-standard/blob/master/composer.json#L33-L34
Or you can use environment variables instead of arguments.

Symfony2.3 production page blank 500

after working with my project on dev mod, i found some problems with prod on OVH.
it shows me a blank page ! i try to follow the issue on app.php and i found that the problem persist with the execution of $response = $kernel->handle($request); and it don't logging on prod.
so when i change the row on app.php : $kernel = new AppKernel('prod', false); with $kernel = new AppKernel('dev', false); it works well !!!
here's my app.php
<?php
/*
* This file is part of the Sonata package.
*
* (c) Thomas Rabaix <thomas.rabaix#sonata-project.org>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
umask(0000);
require_once __DIR__ . '/../app/bootstrap.php.cache';
require_once __DIR__ . '/../app/AppKernel.php';
//use Symfony\Component\HttpFoundation\Request;
// if you want to use the SonataPageBundle with multisite
// using different relative paths, you must change the request
// object to use the SiteRequest
use Sonata\PageBundle\Request\SiteRequest as Request;
$request = Request::createFromGlobals();
$kernel = new AppKernel('prod', false);
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);
EDIT :
in dev and prod local mode test it works well with
php app/console cache:clear --env=prod --no-debug
php app/console assets:install web_directory
php app/console assetic:dump web_directory
should i add or install php5 on my project ?
EDIT :
my project contains : sonata-project, fosUserBundle,etc...
EDIT
the problem was on config_prod.xml
doctrine:
orm:
entity_managers:
default:
metadata_cache_driver: apc
query_cache_driver: apc
result_cache_driver: apc
intil now after it return an error 500 ! why ? because of apc was not enabled !
so my question how to enable apc on OVH pro !
Go to web/config.php and comment ot the following lines:
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.');
}
That will enable the config.php to be called from "extern". Don't forget to remove the comments after you've checked everything.
If you have console access on the production server, enter the root directory of your project and call php app/check.php to run the checks on the console.

Symfony2 - prod environment doesn't work (page 404)

I have problem with my Symfony2 project. I created new bundle using console, but default controller is avalible only from dev environment level.
For
http://localhost/myproject/web/app_dev.php/hello/ZaqU
everything works fine, but for
http://localhost/myproject/web/app.php/hello/ZaqU
i'm redirecting on
http://localhost/myproject/web/hello/ZaqU
and then i getting only page 404.
This is new bundle and i didn't changed default files so I don't understand why it doesn't work. Files:
/* #FILE: app/AppKernel.php */
$bundles = array(
//...
new ZaqU\TestBundle\ZaqUTestBundle(),
);
.
/* #FILE: app/config/routing.yml */
ZaqU_test:
resource: "#ZaqUTestBundle/Resources/config/routing.yml"
prefix: /
Have you tried to clear your prod cache? Run the following command in the console:
./app/console cache:clear --env=prod
You might have not enabled the production environment in web/app.php. Change the false into true.
$kernel = new AppKernel('prod', true);
Hope this helps.
Cheers!

Categories