We are working on our first site with Symfony. In development, everything works. But when we are on production, nothing works!
Trying to use app_dev.php, we see:
Parse error: syntax error, unexpected 'const' (T_CONST), expecting
variable (T_VARIABLE)" in AbstractProxyFactory.php (line 72), script
of Doctrine (in composer.json, we ask for Doctrine > 2.5)
What does that mean?
Clear the cache for the production environment.
bin/console cache:clear --env=prod
Switch to the production environment with composer during deployment.
composer install --no-dev --optimize-autoloader
Related
Compile Error: Declaration of App\DataFixtures\AppFixtures::load(Doctrine\Common\Persistence\ObjectManager $manager) must be compatible with Doctrine\Common\DataFixtures\FixtureInterface:
:load(Doctrine\Persistence\ObjectManager $manager)
The above error is coming when I run composer install or bin/console (anything)
I have a working project but had to transfer to a new server. The main differences are apache version and php version (formerly 7.3.16 now 7.3.22)
I have tried:
*composer dump-autoload
*checked php dependancies
*confirmed .env settings
rm -rf vendor/ and reinstall
*dev and prod environments in .env
Yes, #indra you are right, since Doctrine 2.1.2 the Doctrine/Common was removed so any repos/fixtures using those failed. After updating them all in app, it worked.
I am deploying Symfony 4 project on production.
Created .env file with a content:
APP_ENV=prod
APP_DEBUG=0
Run composer:
$ composer install --no-dev --optimize-autoloader
Getting error:
Script cache:clear returned with error code 255
!! PHP Fatal error: Uncaught RuntimeException:
APP_ENV environment variable is not defined.
You need to define environment variables for
configuration or add "symfony/dotenv" as a Composer
dependency to load variables from a .env file. in
/var/www/symfony4_project/bin/console:20
!! Stack trace:
!! #0 {main}
!! thrown in /var/www/symfony4_project/bin/console on line 20
!!
Script #auto-scripts was called via post-install-cmd
Symfony documentation about deployment and environment setting is very narrow and foggy.
It is not clear where I should set the production environments.
From https://symfony.com/doc/current/configuration.html
sentence "If you decide to set real environment variables on production, the .env files will not be loaded if Symfony detects that a real APP_ENV environment variable exists and is set to prod."
Where should I look for this real APP_ENV existence?
As I found on stackoverflow and github, there are many questions realated, but not so many answers.
Thanks for help.
you need to install symfony/dotenv composer package to load your .env file.
Take a look to the official documentation https://symfony.com/doc/current/components/dotenv.html
The Dotenv Component parses .env files to make environment variables accessible.
Run composer require symfony/dotenv this should work.
If you've got this error in prod since Flex 1.2 in 2019 and you don't want to use .env file but the environment variables of your system :
It's because of changes :
https://symfony.com/blog/new-in-symfony-flex-1-2 :
Please read Improved the handling of .env files on blog
In order :
You have to push your .env on git, but only this .env file
Developpers will create .env.local to override .env file for dev
symfony/dotenv is in require-dev section of composer.json
When you want to deploy :
Get the git repo (without /vendors, of course)
Run composer dump-env prod --empty to generate a .env.local.php file
Install your dependencies via composer install --no-dev [Other prod args]
You can now enjoy your prod env without symfony/dotenv composant installed.
I need a little bit more information to solve your problem.
First of all - just to be sure: did you add the dotenv dependency to your composer as hinted in your debug message: composer require symfony/dotenv
Also, what kind of symfony installation is it? Just a basic symfony/skeleton?
In generall if you just installed a basic symfony/sekleton or website-skeleton changing the value of APP_ENV in .env should work! But we'll work that out.
Please verify that you installed dotenv and provide the information I am looking for.
I am trying to install assets on my sylius project, and I am facing problem :
COMMAND: php app/console sylius:install:assets
ERROR AFTER EXECUTING COMMAND: This command terminated with a permission error
I found solution of a problem, before you guys try to install assets be sure to clear cache, but you might get into a trouble with memory, so edit your
app/console file and add ini_set('memory_limit','-1');
and after that run cache clear, and install assets and everything will be fine :)
I have a Symfony 2 project that I have moved to a new server.
When I go to load the new website I get the following error:
PHP Fatal error: Class 'Doctrine\\Common\\Annotations\\AnnotationRegistry' not found in /var/www/corpsite/corpsite/app/autoload.php on line 61
Im very new to Symfony so any help is appreciated!
Moving a Symfony2 instance can lead to issues with the autoloading,
you should run:
composer.phar dump-autoload --optimize
(the optimize option is for PROD ONLY, and you will get a boost bonus).
Don't forgot also to clear the SF2 cache:
app/console cache:clear --env=prod --no-debug
or...
rm -rf app/cache/*
The error can also be from non existing vendors, composer install is the answer then.
I'm working with symfony2 and while migrating from Beta2 version to the current one I messed up with some environment configuration.
My trouble here is when I run
php app/console --env
I get the following error
[InvalidArgumentException]
The file "MyWebRoute\symfony-standard\app/config/config_.yml" does not exist.
How should I get this working?
What should the proper configuration be?
That is b/c you have to specify your environment.
Available by default are "prod" and "dev".
So if you want to have console do something regarding your development environment you do
./console --env=dev [...]
The error message stems from console trying to load the appropriate configuration file, which is config_dev.yml for "dev" and config_prod.yml for "prod" and config_.yml for ""; but that one doesn't exist.