【问题标题】:Symfony doesn't load a pageSymfony 不加载页面
【发布时间】:2019-02-05 12:13:18
【问题描述】:

我刚刚在我的Ubuntu Server 中配置了Symfony 3.4.15 并且欢迎页面可以工作,但是当我想使用控制器创建一个新页面(例如/home)时它不起作用:

找不到

在此服务器上找不到请求的 URL /home。 Apache/2.4.18 (Ubuntu) 服务器在 167.99.90.60 端口 80

我按照 Symfony 文档中的所有步骤进行操作,但它不起作用...

我读到这个问题是由我的 Apache2 配置引起的,但我不知道如何解决它。

我的 Ubuntu 服务器中安装了 LAMP。

apache2的配置是这样的:

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /usr/share>
        AllowOverride None
        Require all granted
</Directory>

<Directory /var/www/my-project/public>
        Options FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

#<Directory /srv/>
#       Options Indexes FollowSymLinks
#       AllowOverride None
#       Require all granted
#</Directory>

这是我的虚拟主机文件配置:

<VirtualHost *:80>
        # The ServerName directive sets the request scheme, hostname $
        # the server uses to identify itself. This is used when creat$
        # redirection URLs. In the context of virtual hosts, the Serv$
        # specifies what hostname must appear in the request's Host: $
        # match this virtual host. For the default virtual host (this$
        # value is not decisive as it is used as a last resort host r$
        # However, you must set it for any further virtual host expli$
        #ServerName www.example.com

        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/my-project/public

        # Available loglevels: trace8, ..., trace1, debug, info, noti$
        # error, crit, alert, emerg.
        # It is also possible to configure the loglevel for particular
        # modules, e.g.
        #LogLevel info ssl:warn

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        # For most configuration files from conf-available/, which are
        # enabled or disabled at a global level, it is possible to
        # include a line for only one particular virtual host. For ex$
        # following line enables the CGI configuration for this host $
        # after it has been globally disabled with "a2disconf".
        #Include conf-available/serve-cgi-bin.conf
</VirtualHost>

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

有什么想法吗?

【问题讨论】:

  • 我建议将您的配置与symfony.com/doc/current/setup/web_server_configuration.html 中推荐的配置进行比较。例如,它错过了所需的重写规则。
  • 哦,如果您使用 Symfony Flex 引导您的应用程序,安装 Apache 包(运行 composer require symfony/apache-pack)也可以解决您的问题。

标签: symfony ubuntu server apache2 lamp


【解决方案1】:

问题是我忘记在 de /public 文件夹中创建 .htaccess 文件。

【讨论】:

    【解决方案2】:

    我最好的猜测是你没有启用 url 覆盖。

    您是否尝试过使用 Symfony 开发服务器?

    确保您的 apache 配置文件中有类似 hthis 的内容(通常在 /etc/apache2/apache2.conf 中):

    <Directory /var/www/>
        Options -Indexes +FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    

    【讨论】:

    • 不,我没有尝试过 Symfony 开发服务器。这是个好主意吗?我试过这个stackoverflow.com/questions/869092/… 和你所说的关于 apache2 配置文件的内容,但不起作用...... :(
    • 是的,Symfony 测试服务器会在开发过程中为您省去很多麻烦。只需在您的应用程序目录中运行 php bin/console server:start 并转到 localhost:8000 symfony.com/doc/current/setup/built_in_web_server.html 还要确保检查您的 apache 配置文件。
    • 正如您在我的新编辑中看到的那样,我尝试更改 apache 配置文件但仍然无法正常工作...
    • 您是否检查过它是否在此之后启用? stackoverflow.com/questions/7337724/…您也可以发布您的虚拟主机配置,有更多信息也无妨。
    • 我用我的 VirtualHost 文件配置更新了这个问题 :)
    猜你喜欢
    • 2019-05-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多