php - 当 app_dev 在子目录中时的 Symfony Apache 配置

标签 php symfony

我正在本地 windows 机器上运行 Symfony 3 应用程序。它由 XAMPP 服务器提供。当我访问我的本地 URL 时,该应用程序运行良好。问题是我似乎无法在开发环境中运行它。

Symfony 应用程序文件夹结构与我习惯的不同。 app_dev.php 位于 Intranet 文件夹中。

enter image description here

这是内网文件夹

enter image description here

我当前的 apache 配置文件如下所示:

<VirtualHost *:443>
    ServerName quebecenreseau.ca
    ServerAlias www.quebecenreseau.ca

    SSLEngine on
    SSLCertificateFile "crt/quebecenreseau.ca/server.crt"
    SSLCertificateKeyFile "crt/quebecenreseau.ca/server.key"

    DocumentRoot C:\xampp\htdocs\quebecenreseau
    <Directory C:\xampp\htdocs\quebecenreseau>
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

    # uncomment the following lines if you install assets as symlinks
    # or run into problems when compiling LESS/Sass/CoffeeScript assets
    # <Directory /var/www/project>
    #     Options FollowSymlinks
    # </Directory>

    ErrorLog C:\xampp\apache\logs\project_error.log
    CustomLog C:\xampp\apache\logs\project_access.log combined
</VirtualHost>

我不确定如何配置 VirtualHost block 以使开发环境同时在根目录和作为网站管理员的内网目录上运行。

如果我像这样更改 DocumentRoot 行:

DocumentRoot C:\xampp\htdocs\quebecenreseau\intranet\app_dev.php

我的应用 CSS 文件未加载,我的内部网在根级别提供服务。如何配置本地环境以加载 app_dev.php?另外,我的产品环境在 centos 服务器上,所以我真的不想弄乱产品环境。

如果您在根级别的 index.php 文件中徘徊,它是:

<?php

/**
 * Start session
 */

session_start();

/**
 * Load configuration and router
 */

require 'classes/Router.php';
require 'classes/Database.php';
require 'classes/Main.php';

/**
 * Load helpers
 */

require 'helpers/phpmailer/class.phpmailer.php';
require 'helpers/GUMP.php';
require 'helpers/MailChimp.php';


/**
 * Load models
 */

require 'models/Article.php';
require 'models/Formation.php';
require 'models/SAE.php';


/**
 * Load routes
 */

require 'router.php';


/**
 * Match requests
 */

$match = $router->match();

if( $match && is_callable( $match['target'] ) ) {
    // call function related to matched route
    call_user_func_array( $match['target'], $match['params'] );
} else {
    // no route was matched
    header( $_SERVER["SERVER_PROTOCOL"] . ' 404 Not Found');
}

最佳答案

尝试将 C:\xampp\htdocs\quebecenreseau 更改为 C:\xampp\htdocs\quebecenreseau\intranet\web。如果我没记错的话,文档根目录必须指向app.php和app_dev.php所在的文件夹。

更新:

好的。现在有点清楚了。您没有在产品中运行纯 Symfony 项目。有人从 Symfony 中获取了一些基本类,用于路由请求和处理数据库连接。

现在您实际上有两个项目。主文件夹中的普通 PHP 项目和 Intranet 文件夹中的 Symfony 项目。

那么让我们开始吧。首先,您必须知道,要使 Symfony 项目作为主应用程序正常运行,根文件夹必须是“web”文件夹。

所以:

  1. 在 quebecenreseau 文件夹中创建一个新的 Symfony 项目。
  2. 将现有 Assets 移动到新 Assets 文件夹
  3. 检查现有 Controller 是否需要进行一些调整才能显示 Assets 。

根据我从结构中看到的情况,您需要进行最少的更改才能使其正常工作。

关于php - 当 app_dev 在子目录中时的 Symfony Apache 配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53948241/

相关文章:

Symfony、nginx 和 "File not found."

symfony - Sonata User Admin - 自定义字段依赖

PHP、Mysql聊天应用程序。我不知道

php - 不能将标量值用作数组

php - MySQL 查询中的点 (.) 应该做什么?

css - 将类属性添加到 symfony 表单生成器行 div

php - FOSRestBundle 和 JMS Serializer,获取 JSON 时出错

javascript - 使用 jquery 获取循环内的特定文本框值

javascript - 从 <a> 标签内的按钮调用路由 laravel

php - Symfony 原则多对多完整性约束违规 : 1062 Duplicate entry