【问题标题】:Running an existing project under Symfony framework在 Symfony 框架下运行现有项目
【发布时间】:2017-01-08 11:38:36
【问题描述】:

我是 symfony 框架的新手,不擅长 php,我开始负责运行项目的现有备份。

为了联系它,我在本地虚拟机上运行了一个 debian 8 服务器。 为了确保我知道 symfony 是如何工作的,我决定运行 symfony 演示。 问题是我不确定我是否使用 apache2 很好地配置它,因为我已经按照 symfony 网站上的指南进行操作。

我已经在/var/www/html/symfony_demo下安装了symfony demo

这是我的可用网站

<VirtualHost *:80>
    ServerName domain.tld
    ServerAlias www.domain.tld

    DocumentRoot /var/www/symfony_demo/web
    <Directory /var/www/symfony_demo/web>
        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 /var/log/apache2/project_error.log
    CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>

我已经从symfony_demo 目录执行了php bin/console server:start

Web 服务器已启动并在默认 127.0.0.1:8000 上运行。

在更改为 sites-avaliable 之前尝试访问 apache2 默认的 index.html 时,在 :80 下一切正常。我的192.168.0.100 可以从浏览器访问。但是在更改配置并尝试访问192.168.0.100:8000 后,我无法连接。

我需要帮助解决此问题,因为我不知道从哪里寻找问题。问什么。

【问题讨论】:

  • 你有自己的 apache2 服务器,所以你不需要在 webserver 中构建。如果你去domain.tld/app_dev.php会发生什么?
  • 我杀死了网络服务器中的构建,因此尝试访问 192.168.0.100/app_dev.php 以 404 响应。
  • 好的,我实际上已经到达了app_dev.php,它打印了You are not allowed to access this file。检查 app_dev.php 以获取更多信息。从现在开始该怎么办?
  • app_dev.php 默认只在 localhost 上工作。

标签: php apache symfony


【解决方案1】:

/var/www/symfony_demo/web 目录中查看您的.htaccess 配置,并查看app.php 是否配置为DirectoryIndex。也许您需要将DirectoyIndex 添加到您的配置中,因为Apache 正在搜索index.htmlindex.php 而不是app.php

    DocumentRoot /var/www/symfony_demo/web
    <Directory /var/www/symfony_demo/web>
        DirectoryIndex app.php
        AllowOverride All
        Order Allow,Deny
        Allow from All
    </Directory>

【讨论】:

    【解决方案2】:

    从现在开始该怎么做?

    编辑 app_dev.php(如前所述是你的错误)

    // This check prevents access to debug front controllers that are deployed by accident to production servers.
    // Feel free to remove this, extend it, or make something more sophisticated.
    if (isset($_SERVER['HTTP_CLIENT_IP'])
        || isset($_SERVER['HTTP_X_FORWARDED_FOR'])
        || !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
    ) {
        header('HTTP/1.0 403 Forbidden');
        exit('You are not allowed to access this file. Check '.basename(__FILE__).' for more information.');
    }
    

    添加你的 ip 到

    || !in_array(@$_SERVER['REMOTE_ADDR'], array('127.0.0.1', 'fe80::1', '::1'))
    

    或评论整个区块

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-10
      • 1970-01-01
      • 1970-01-01
      • 2016-11-10
      • 1970-01-01
      相关资源
      最近更新 更多