I'm a beginner with Symfony.
I have a Symfony 3.1 project. I put y project on my remote server. Everything works fine. Then I use SensioLabsInsight to check errors in my project. This analyse tool gives me those 2 warnings messages
:
"Exceptions should not be enabled in production" and "Symfony applications should not contain a config.php file"
Then my first question is how can I disable Exceptions in production ?
My second question is may I remove the config.php file in production (located in myBundle/web/config.php) ?
Then my first question is how can I disable Exceptions in production ?
As far as I can see when searching this on Google, I think it's because the second parameter passed to new AppKernel('prod', ...); is true, which enables debug mode. Set it to false. (same applies to debug settings in config_prod.yml).
My second question is may I remove the config.php file in production (located in myBundle/web/config.php) ?
Yes, also remove any front-controller (like app_dev.php) except from your production one. Remember: The standard edition is just a recommendation. Symfony doesn't force you any file or directory in the directory structure.
In the new Symfony version, there is a new var APP_DEBUG, which you send to Kernel in the second parameter.
Just add new var to your .env file
APP_DEBUG=false
return new Kernel($context['APP_ENV'], (bool) $context['APP_DEBUG']);
Related
I would like to setup a staging environment with the same configuration as the prod environment.
According to the docs, I proceed as follow:
I create a staging symlink that points on prod
configure the env in .env: APP_ENV=staging
clear the cache: php bin/console cache:clear
ask for an URL that does not exist to trigger a 404 error: http://localhost:8080/an-url-that-does-not-exists
When the APP_ENV=prod, my custom error page is render properly, but when APP_ENV=staging, the debug message NotFoundHttpException is rendered?
The profiler is not displayed.
What am I missing?
tldr;
Crate an .env.staging file and use it to set APP_DEBUG to 0. Debug mode and environment are set independently.
By default, unless you set it explicitly debug mode (APP_DEBUG) is set from the environment automagically.
This happens in the following steps:
In your front-controller (index.php, usually) you would find this line:
(new Dotenv())->bootEnv(dirname(__DIR__).'/.env');
And on DotEnv::bootEnv() you'll find this:
$debug = $_SERVER[$k] ?? !\in_array($_SERVER[$this->envKey], $this->prodEnvs, true);
This will compare your APP_ENV with an array of "environments" that DotEnv, considers "production-like". By default, this array includes only prod.
You could modify the instance of the DotEnv by calling setProdEnvs():
(new Dotenv())
->setProdEnvs(['prod', 'staging'])
->bootEnv(dirname(__DIR__).'/.env');
... but generally simply disabling debug mode on your .env file would be enough.
I'm trying to get a TYPO3 v8 system updated to TYPO3 v9, but when it comes to unit-testing, I got some errors. I was able to fix some of them on my own but this one here's a very difficult one for me, because unit-testing is somewhat new to me in general.
I already searched the web, the TYPO3 documentation (which seems like the important parts are missing?), asked some friends and tried some things on my own, but nothing helped.
$this->environmentMock = $this->createMock(Environment::class);
$this->environmentMock->expects($this->once())
->method("::isCli")
->will($this->returnValue(TRUE));
I'm expecting to manually override the static function ::isCli() that comes with the Environment class. If that's not possible, is there any other "workaround", like setting a protected variable or something like that?
Currently this is my error message:
Trying to configure method "::isCli" which cannot be configured because it does not exist, has not been specified, is final, or is static
Thanks in advance!
Update 1:
After using #susis tip, I get the following error when appending the code:
TypeError: Return value of TYPO3\CMS\Core\Core\Environment::getContext() must be an instance of TYPO3\CMS\Core\Core\ApplicationContext, null returned
Additional information: My project is just an extension folder with TYPO3 v9 sources required in its own composer.json. No web, no htdocs, just the extension folder.
Update 2:
Here's a full gist of my test file.
Update 3:
Even the debugger isn't helping me in this case, see attached screenshot:
xdebug phpstorm applicationcontext environment screenshot
Update 4:
I updated the gist, added the environment vars to the phpunit.xml file and added parent::setUp() to the top of the setUp() method but the error is still the same:
TypeError : Return value of TYPO3\CMS\Core\Core\Environment::getContext() must be an instance of TYPO3\CMS\Core\Core\ApplicationContext, null returned
/Users/xyz/my_redirect/public/typo3/sysext/core/Classes/Core/Environment.php:97
/Users/xyz/my_redirect/Tests/Unit/Hooks/RequestHandlerHookTest.php:41
Update 5:
I updated the gist and removed the environment settings from the phpunit.xml due to what I've seen that they didn't work either. At this moment, the test is working but I'm still not sure if it's done the right way. Thanks for your help!
You can initialize the Environment you want in your tests, for example with:
Environment::initialize(
Environment::getContext(),
true,
false,
Environment::getProjectPath(),
Environment::getPublicPath(),
Environment::getVarPath(),
Environment::getConfigPath(),
Environment::getBackendPath() . '/index.php',
Environment::isWindows() ? 'WINDOWS' : 'UNIX'
);
This is the same way as it is done in TYPO3 Core tests and allows you to customize the complete environment. If you are using the TYPO3 testing framework / UnitTestCase base classes, you can use the property protected $backupEnvironment = true; to make sure the environment is reset after your test.
For an example, you can have a look at the ResourceCompressorIntegrationTest
I know there are some questions almost identical but none of them seems to be my case.
I have a symfony 2.8.3 project that reads and imports data from an excel file into mysql database. Its all working nice on localhost but in the last 48 hours I've been trying to get it working on my server. Its a shared hosting, with no SSH access to the linux.
When I am trying to load it from the server I get this error: "You have requested a non-existent service "phpexcel"."
Looks like you want to use service from ExcelBundle. But that bundle is not loaded. Check if you have it added for production env.
$bundles = array(
// ...
new Liuggio\ExcelBundle\LiuggioExcelBundle(),
);
Don't forget to clear cache on production environment after any config (AppKernel.php also) change.
To clear cache run php app/console cache:clear. You can also add env parameter: --env=dev or --env=prod - depending on your env. If it don't help then just remove all content of app/cache/ directory (or var/cache/ in case of Symfony3 app)
Pawel answered correctly, but something is missing: after you add this line: new Liuggio\ExcelBundle\LiuggioExcelBundle(), to the AppKernel.php file, inside the $bundles array, don't forget to clear the cache: delete the file from app/cache/dev in case you're in developer mode or app/cache/prod in case on production mode.
How could i link Laravel log files to PaperTrial ?
According to this article :
http://mattstauffer.co/blog/laravel-forge-logging-with-papertrail#step-4-add-a-syslog-handler
I followed steps and reached to step 4 putting Syslog Monolog handler in the /app/route.php file ,went to PaperTrial dashboard but i didn't see any output.
Any help ? thanks.
For Laravel 5.1 after setting up the forge, you should add to bootstrap/app.php file the following code just before the return of the $app variable
$app->configureMonologUsing(function($monolog){
$monolog->pushHandler(new Monolog\Handler\SyslogHandler('papertrail'));
});
return $app;
The parameter (in this case 'papertrail') can be whatever you want to, this name will show on the papertail's event screen.
I have it working using the standard logging facility instead of Monolog. This way there is nothing extra to install. Just add this to rsyslogd's conf:
### Laravel Log
$InputFileName /path/to/vhost/dir/app/storage/logs/laravel.log
$InputFileTag laravel-errors-domain.com:
$InputFileStateFile state-laravel-errors-domain.com
$InputFileSeverity error
$InputRunFileMonitor
And make sure that this log gets included in the send action, if you are not sending everything.
Then issue
service rsyslog restart
From my experience using Laravel 5.2.* with Forge, Step 4 from that article is not necessary anymore. All you have to do after Step 3 is set your Environment .env settings in Forge to APP_LOG=syslog for each site you want to use with papertrail.
However, this means that Laravel will not log to laravel.log anymore in this environment. But, in other environments (e.g. dev environment) you could of course continue logging to laravel.log by simply not making any changes to the .env file there.
I have Zend Framework project running on Google App Engine. Everything works great, with the exception of one thing:
I can't set an environment variable to tell Zend that I'm in development mode
Any ideas?
(I'm using PHP 5.4 in Ubuntu)
What I've tried
(Obviously I don't want to set the variable through app.yaml... I can't set it through .htaccess because it's not used. I would rather not have to add any conditions in my code to possibly set the variable that way, either)
I'm using PHPStorm (IDE), which has a nice plugin for GAE. It even has an option in the project configurations for environment variables - except that it doesn't work. I'm setting the variable in PHPStorm (Edit Configurations > Google App Engine for PHP > Command Line > Environment Variables), but if I do a
getenv()
from code, it returns
boolean false
Why
My goal in all this is to dynamically load the development configurations for my project, particuarly so I can use MySQL locally, instead of connecting up to CloudSQL while developing and testing the apps.
The solution I'm going with, based on the comments by #tim-hoffman is the following little bit of logic on my /public/index.php file, placed before the APPLICATION_ENV constant is defined:
$env = getenv("SERVER_SOFTWARE");
if ($env !== false) {
if ((bool)preg_match("/development/", strtolower($env))) {
define("APPLICATION_ENV", "development");
}
}
In development mode, SERVER_SOFTWARE will return the string "Development/X.X" (version number), and in production, it'll be "Google App Engine/X.Y.Z"