没有考虑symfony 4的更改

时间:2018-10-19 18:52:55

标签: php symfony vhosts

我已经将 symfony 4应用程序从生产服务器迁移到了我用于测试的服务器,这两个服务器都位于wampserver上。该应用程序在测试服务器上可以正常工作,但是问题是当我进行更改时,没有考虑到它们。每次我更改树枝文件时,更改都不会显示。我认为它正在使用prod和dev变量,但是我是Symfony的新手,我不确定它如何工作。显然现在服务器处于prod模式,我想将其更改为dev模式。 vhosts文件的代码是

# Virtual Hosts
#
<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  SetEnv APP_ENV prod
  SetEnv APP_SECRET b33c77e602bc1bafb66f673c1e31aca3
  SetEnv DATABASE_URL mysql://root@127.0.0.1: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>

public / index.php是

<?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);

当我运行 php bin /控制台缓存:clear --env = prod 时,由于.env文件不存在,它给出了一个错误 config / services.yaml的代码是

# 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

2 个答案:

答案 0 :(得分:0)

您可以尝试在VirtualHost文件中将“ SetEnv APP_ENV prod”更改为“ SetEnv APP_ENV dev”。

# Virtual Hosts
#
<VirtualHost *:80>
  ServerName localhost
  ServerAlias localhost
  SetEnv APP_ENV dev #<-------------------------------------- here
  SetEnv APP_SECRET b33c77e602bc1bafb66f673c1e31aca3
  SetEnv DATABASE_URL mysql://root@127.0.0.1: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>

答案 1 :(得分:0)

对于 symfony4控制台,在.htaccess webserver 中给出的环境变量无效。因此您需要向环境变量提供命令。

您应该运行以下命令清除生产环境中的缓存

APP_ENV=prod php bin/console cache:clear

如果您从Windows cmd运行命令,则可能需要像这样运行:

set APP_ENV=prod php bin/console cache:clear