I use CloudWays hosting for my web app. I am trying to get my index page to work. Example: www.mysite.com or www.mysite.com to point to my index or home page. I have set up the following controller after running composer require annotations
<?php
namespace AppController;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentRoutingAnnotationRoute;
class HomeController extends AbstractController
{
/**
* @Route("/", name="main")
*/
public function index()
{
return $this->render('main/index.html.twig', ['controller_name' => 'HomeController',]);
}
}
I followed the official Symfony 4 documentation for routing which defines this example code(https://symfony.com/doc/4.1/routing.html):
// src/Controller/BlogController.php
namespace AppController;
use SymfonyBundleFrameworkBundleControllerAbstractController;
use SymfonyComponentRoutingAnnotationRoute;
class BlogController extends AbstractController
{
/**
* Matches /blog exactly
*
* @Route("/blog", name="blog_list")
*/
public function list()
{
// ...
}
}
My project structure is as follows:
/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
When I enter the url www.mysite.com I get a 403 Forbidden error.
Forbidden
You don't have permission to access this resource.
Apache/2.4.25 (Debian) Server at www.mysite.om Port 80
When I enter the url www.mysite.com/public it works and displays my site perfectly.
How can i fix this issue so my index is at www.mysite.com and not www.mysite.com/public
2
Answers
I figured out what the issue was. In order to fix my issue I needed to do the following:
Step 1) Navigate to the Cloudways server application settings panel.
Step 2) Change webroot to wherever your public files are located in your project.
If you do not know where your public files are located you can find out by connecting to the apache server through the provided terminal and using the
cd
command to navigate to the directory. Or connect with an ftps connection to navigate to the needed directory.After doing this
www.mysite.com
should bring you to yourindex/home page
. After researching as to why this happens I found out that theindex.php
is one layer down from what my root folder was at first. In order to fix this I needed to bring my root folder to the correct layer whereindex.php
was located.Since CloudWays seems to be a shared hosting site that uses
Apache server
you may need anApache pack
. Run commandcomposer require symfony/apache-pack
in your console and upload your project files again to see if it helped.