首页 > 解决方案 > 我无法让我的索引页面显示在我的 cloudways symfony 应用程序上

问题描述

我将 CloudWays 托管用于我的 Web 应用程序。我正在尝试让我的索引页正常工作。示例:www.mysite.com 或 www.mysite.com 指向我的索引或主页。运行后我设置了以下控制器composer require annotations

<?php

namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class HomeController extends AbstractController
{

     /**
      * @Route("/", name="main")
      */

    public function index()
    {

        return $this->render('main/index.html.twig', ['controller_name' => 'HomeController',]);

    }
}

我遵循了官方 Symfony 4 路由文档,它定义了这个示例代码(https://symfony.com/doc/4.1/routing.html):

// src/Controller/BlogController.php
namespace App\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Routing\Annotation\Route;

class BlogController extends AbstractController
{
    /**
     * Matches /blog exactly
     *
     * @Route("/blog", name="blog_list")
     */
    public function list()
    {
        // ...
    }
}

我的项目结构如下:

/projectfolder
---- /public_html
     ---- /bin
          /config
          ----/dev
              framework.yaml
          annotations.yaml
          /public
          ----/assets
              /css
              /js
              .htaccess
              index.php
          /src
          ----/Controller
              ----HomeController.php
              Kernal.php
          /templates
          ----/main
              ----index.html.twig
              base.html.twig
          /var
          /vendor
          .env
          .swp
           composer.json
           composer.lock
           symfony.lock

当我输入网址 www.mysite.com 时,我收到 403 Forbidden 错误。

Forbidden
You don't have permission to access this resource.

Apache/2.4.25 (Debian) Server at www.mysite.om Port 80

当我输入网址 www.mysite.com/public 时,它可以正常工作并完美显示我的网站。

如何解决此问题,以便我的索引位于 www.mysite.com 而不是 www.mysite.com/public

谷歌域名图片: 在此处输入图像描述

标签: phphtmlsymfony4cloudways

解决方案


我弄清楚了问题所在。为了解决我的问题,我需要执行以下操作:

步骤 1) 导航到 Cloudways 服务器应用程序设置面板。

在此处输入图像描述

步骤 2) 将 webroot 更改为您的公共文件在项目中的任何位置。

在此处输入图像描述

如果您不知道公共文件的位置,您可以通过提供的终端连接到 apache 服务器并使用cd命令导航到目录来查找。或者通过 ftps 连接来导航到所需的目录。

这样做后www.mysite.com应该把你带到你的index/home page. 在研究了为什么会发生这种情况后,我发现它index.php是我最初的根文件夹的下一层。为了解决这个问题,我需要将我的根文件夹带到所在的正确层index.php


推荐阅读