symfony 4 changes are not taken into account

I have migrated a symfony 4 application from the production server to the server that I am using for tests, bothe servers are on wampserver . the application works fine on the test server but the problem is that when I make changes, they are not taken into account. every time I change a twig file the changes dont show up. I think that it is using the prod and dev variables but I am new in Symfony I am not sure how it works .apparently now the server is on prod mode and I want to change it to dev mode . the code for the vhosts file is

# Virtual Hosts
#
<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  SetEnv APP_ENV prod
  SetEnv APP_SECRET b33c77e602bc1bafb66f673c1e31aca3
  SetEnv DATABASE_URL mysql://[email protected]:3306/gpac
  DocumentRoot "${INSTALL_DIR}/www/gpac/public"
  <Directory "${INSTALL_DIR}/www/gpac/public/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

the public/index.php is

<?php

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/../vendor/autoload.php';

// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
    if (!class_exists(Dotenv::class)) {
        throw new \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.');
    }
    (new Dotenv())->load(__DIR__.'/../.env');
}

$env = $_SERVER['APP_ENV'] ?? 'dev';
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env));

if ($debug) {
    umask(0000);

    Debug::enable();
}

if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? false) {
    Request::setTrustedProxies(explode(',', $trustedProxies), Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
}

if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? false) {
    Request::setTrustedHosts(explode(',', $trustedHosts));
}

$kernel = new Kernel($env, $debug);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

when I run the php bin/console cache:clear --env=prod it gives an error because the .env file does not exist the code for config/services.yaml is

# Put parameters here that don't need to change on each machine where the app is deployed
# https://symfony.com/doc/current/best_practices/configuration.html#application-related-configuration
parameters:
    locale: 'fr'
    version: 1.0.0
    default_alert:
        council_meeting: 7 # days
        project_step: 7 # days
        resource_report: 1 # years
        resource_contract: 1 # month
        resource_capability: 1 # month

services:
    # default configuration for services in *this* file
    _defaults:
        autowire: true      # Automatically injects dependencies in your services.
        autoconfigure: true # Automatically registers your services as commands, event subscribers, etc.
        public: false       # Allows optimizing the container by removing unused services; this also means
                            # fetching services directly from the container via $container->get() won't work.
                            # The best practice is to be explicit about your dependencies anyway.

    # makes classes in src/ available to be used as services
    # this creates a service per class whose id is the fully-qualified class name
    App\:
        resource: '../src/*'
        exclude: '../src/{Entity,Migrations,Tests,Kernel.php}'

    # controllers are imported separately to make sure services can be injected
    # as action arguments even if you don't extend any base controller class
    App\Controller\:
        resource: '../src/Controller'
        tags: ['controller.service_arguments']

    # add more service definitions when explicit configuration is needed
    # please note that last definitions always *replace* previous ones

    activity:
        class: App\Service\ActivityLogger
        public: true
        arguments: ['@doctrine.orm.entity_manager', '@security.token_storage', '@request_stack']

    process:
        class: App\Service\ProcessProvider
        public: true
        arguments: ['%kernel.project_dir%']

    App\Listener\LoginListener:
        arguments: ['@activity']
        tags:
            - { name: kernel.event_subscriber }

    dpolac.twig_lambda.extension:
        class: DPolac\TwigLambda\LambdaExtension
        tags: [ { name: twig.extension } ]

    # ---------------------
    # Sonata Admin Services
    # ---------------------

    app.admin.user:
        public: true
        class: App\Admin\UserAdmin
        arguments: [~, App\Entity\User, App\Controller\UserAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: admin, label: class.User }

    app.admin.user_function:
        public: true
        class: App\Admin\UserFunctionAdmin
        arguments: [~, App\Entity\UserFunction, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, group: admin, label: class.UserFunction }

    app.admin.skill_matrix:
        class: App\Admin\SkillMatrixAdmin
        arguments: [~, App\Entity\SkillMatrix, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.SkillMatrix }

    app.admin.skill_matrix_category:
        class: App\Admin\SkillMatrixCategoryAdmin
        arguments: [~, App\Entity\SkillMatrixCategory, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, group: skill, label: class.SkillMatrixCategory }
        calls:
            - [ setTemplate, [list, 'CRUD/Skill/list.html.twig']]

    app.admin.client:
        class: App\Admin\ClientAdmin
        arguments: [~, App\Entity\Client, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, group: project, label: class.Client }
        calls:
            - [addChild, ['@app.admin.client_site']]

    app.admin.client_site:
        class: App\Admin\ClientSiteAdmin
        arguments: [~, App\Entity\ClientSite, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ClientSite}

    app.admin.client_numbers:
        class: App\Admin\ClientNumbersAdmin
        arguments: [~, App\Entity\ClientNumbers, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ClientNumbers}

    app.admin.resource:
        class: App\Admin\ResourceAdmin
        arguments: [~, App\Entity\Resource, SonataAdminBundle:CRUD, '@doctrine.orm.entity_manager']
        tags:
            - { name: sonata.admin, manager_type: orm, group: rc, label: class.Resource }
        public: true
        calls:
            - [ setTemplate, [show, 'CRUD/Resource/show.html.twig']]
            - [addChild, ['@app.admin.resource_capability']]
            - [addChild, ['@app.admin.resource_contract']]
            - [addChild, ['@app.admin.resource_education']]
            - [addChild, ['@app.admin.resource_experience']]
            - [addChild, ['@app.admin.resource_lang']]
            - [addChild, ['@app.admin.resource_report']]

    app.admin.council:
        public: true
        class: App\Admin\CouncilAdmin
        arguments: [~, App\Entity\Council, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, group: council, label: class.Council }
        calls:
            - [ setTemplate, [list, 'CRUD/Council/list.html.twig']]

    app.admin.council_meeting:
        class: App\Admin\CouncilMeetingAdmin
        arguments: [~, App\Entity\CouncilMeeting, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, group: council, label: class.CouncilMeeting }
        public: true

    app.admin.resource_capability:
        class: App\Admin\ResourceCapabilityAdmin
        arguments: [~, App\Entity\ResourceCapability, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm , label: class.ResourceCapability}
        public: true

    app.admin.resource_contract:
        class: App\Admin\ResourceContractAdmin
        arguments: [~, App\Entity\ResourceContract, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ResourceContract}
        public: true

    app.admin.resource_education:
        class: App\Admin\ResourceEducationAdmin
        arguments: [~, App\Entity\ResourceEducation, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm , label: class.ResourceEducation}
        public: true

    app.admin.resource_experience:
        class: App\Admin\ResourceExperienceAdmin
        arguments: [~, App\Entity\ResourceExperience, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm , label: class.ResourceExperience}
        public: true

    app.admin.resource_lang:
        class: App\Admin\ResourceLangAdmin
        arguments: [~, App\Entity\ResourceLang, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ResourceLang}
        public: true

    app.admin.project:
        class: App\Admin\ProjectAdmin
        arguments: [~, App\Entity\Project, App\Controller\ProjectAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: project, label: class.Project }
        public: true
        calls:
            - [setTemplate, ['list', 'CRUD/Project\list.html.twig']]
            - [setTemplate, ['show', 'CRUD/Project\show.html.twig']]
            - [setTemplate, ['edit', 'CRUD/Project\edit.html.twig']]
            - [addChild, ['@app.admin.project_eval']]
            - [addChild, ['@app.admin.project_status']]
            - [addChild, ['@app.admin.project_alert']]

    app.admin.project_status:
        class: App\Admin\ProjectStatusAdmin
        arguments: [~, App\Entity\ProjectStatus, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ProjectStatus }
        public: true

    app.admin.project_eval:
        class: App\Admin\ProjectEvalAdmin
        arguments: [~, App\Entity\ProjectEval, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ProjectEval }
        public: true
        calls:
            - [addChild, ['@app.admin.project_step']]
            - [addChild, ['@app.admin.project_staff']]

    app.admin.project_staff:
        class: App\Admin\ProjectStaffAdmin
        arguments: [~, App\Entity\ProjectStaff, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ProjectStaff }
        public: true

    app.admin.project_step:
        class: App\Admin\ProjectStepAdmin
        arguments: [~, App\Entity\ProjectStep, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ProjectStep }
        public: true

    app.admin.activity:
        class: App\Admin\ActivityAdmin
        arguments: [~, App\Entity\Activity, App\Controller\ActivityAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: admin, label: class.Activity }
        public: true

    app.admin.project_alert:
        class: App\Admin\ProjectAlertAdmin
        arguments: [~, App\Entity\ProjectAlert, App\Controller\ProjectAlertAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ProjectAlert }
        public: true

    app.admin.report_qual_theo:
        class: App\Admin\ReportQualTheoAdmin
        arguments: [~, App\Entity\ReportQualTheo, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, group: frc, label: class.ReportQualTheo }
        public: true

    app.admin.report_qual_prat:
        class: App\Admin\ReportQualPratAdmin
        arguments: [~, App\Entity\ReportQualPrat, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, group: frc, label: class.ReportQualPrat }
        public: true

    app.admin.resource_report:
        class: App\Admin\ResourceReportAdmin
        arguments: [~, App\Entity\ResourceReport, App\Controller\ResourceReportAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, group: frc, label: class.ResourceReport }
        public: true
        calls:
            - [addChild, ['@app.admin.resource_report_education']]
            - [addChild, ['@app.admin.resource_report_forum']]
            - [addChild, ['@app.admin.resource_report_project']]

    app.admin.resource_report_education:
        class: App\Admin\ResourceReportEducationAdmin
        arguments: [~, App\Entity\ResourceReportEducation, App\Controller\ResourceReportEducationAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ResourceReportEducation }
        public: true

    app.admin.resource_report_forum:
        class: App\Admin\ResourceReportForumAdmin
        arguments: [~, App\Entity\ResourceReportForum, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ResourceReportForum }
        public: true

    app.admin.resource_report_project:
        class: App\Admin\ResourceReportProjectAdmin
        arguments: [~, App\Entity\ResourceReportProject, App\Controller\ResourceReportProjectAdminController]
        tags:
            - { name: sonata.admin, manager_type: orm, label: class.ResourceReportProject }
        public: true
        calls:
          - ['setTemplate', ['list', 'CRUD/ReportResourceProject\list.html.twig']]

    app.admin.report_council:
        class: App\Admin\ReportCouncilAdmin
        arguments: [~, App\Entity\ReportCouncil, SonataAdminBundle:CRUD]
        tags:
            - { name: sonata.admin, manager_type: orm, group: frc, label: class.ReportCouncil }
        public: true
728x90

2 Answers symfony 4 changes are not taken into account

You could try changing the 'SetEnv APP_ENV prod' to 'SetEnv APP_ENV dev' in your VirtualHost file.

# Virtual Hosts
#
<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  SetEnv APP_ENV dev #<-------------------------------------- here
  SetEnv APP_SECRET b33c77e602bc1bafb66f673c1e31aca3
  SetEnv DATABASE_URL mysql://[email protected]:3306/gpac
  DocumentRoot "${INSTALL_DIR}/www/gpac/public"
  <Directory "${INSTALL_DIR}/www/gpac/public/">
    Options +Indexes +Includes +FollowSymLinks +MultiViews
    AllowOverride All
    Require all granted
  </Directory>
</VirtualHost>

5 months ago

For symfony4 console the environment variables given in .htaccess or in webserver has no effect. so you need to provide the environment variable with the command.

You should run following command to clear cache in production

APP_ENV=prod php bin/console cache:clear

If you are running command from windows cmd then you may need to run like:

set APP_ENV=prod php bin/console cache:clear

5 months ago