1

A web app which has been developed on a local apache (on Centos) works as intended and all routing works fine. However, when uploading the same identical project on a shared hosting, using the same path, and clearing the cache several times , the server is returning 404.

routing.yml:

app:
     resource: "@AppBundle/Controller/"
     type:     annotation

maya:
    resource: "@AppBundle/Controller/MayaController.php"
    type:     annotation

Furthermore, routing is specified on the controller method as:

/**
 * @Route("/maya/")
 */
public function initLoad()
{
    return $this->render(
        'base.html.twig');
}

Cache has been cleared by using the php app/console cache:clear --env prod command and rm -fr app/cache/*.

When accessing the web folder i.e www.mywebsite.com/my-site-folder/web/ a list of all the files inside the web folder are listed and when accessing www.mywebsite.com/my-site-folder/web/app.php the base template is being returned i.e as if www.mywebsite.com/my-site-folder/web/maya has been called.

Any suggestions on what the issue may be given it runs well on a local apache server on linux?

Thanks in advance!

William
  • 55
  • 1
  • 8
  • Also, sometimes when I clear the cache the error :Fatal error: Cannot redeclare class SessionHandlerInterface in /home/mywebsite/app/cache/prod/classes.php on line 71 This is rectified by running rm -fr for the cache folder. Could it be a PHP version mismatch? I am using symfony 2.8 – William Feb 20 '16 at 17:02
  • Try this `@Route("/maya/")` to `@Route("/maya")` – Imanali Mamadiev Feb 20 '16 at 17:20
  • Works when app.php is added in the url i.e: www.mywebsite.com/my-site-folder/web/app.php/maya works as intended. Still I find it strange why the app.php is required while locally on my apache it did not. Locally apache was running on prod mode. Thanks! – William Feb 20 '16 at 17:23
  • @William this is because .htaccess is either not uploaded on your server, .htaccess support is not enabled, or rewrite rules is not enabled. I suggest you contact your host and ask them if .htaccess support is enabled and if so, if rewrite rules are enabled as well. – ggirtsou Feb 20 '16 at 17:27

1 Answers1

1

After having read your comments, I see accessing your site via /web/app.php works, I suspect .htaccess is not parsed by the server. Pleas ensure

  • Symfony's .htaccess file is correctly uploaded in /web/ directory,
  • your host has not enabled .htaccess support,
  • or if .htaccess support is enabled, possible rewrite rules are disabled.

I suggest you check this with your host.

NOTE: the routing.yml you provided, already includes your MayaController.php:

app:
     resource: "@AppBundle/Controller/"
     type:     annotation

you don't need to separately reference this:

maya:
    resource: "@AppBundle/Controller/MayaController.php"
    type:     annotation
ggirtsou
  • 2,050
  • 2
  • 20
  • 33
  • Just found the answer here: http://stackoverflow.com/questions/16689822/symfony-htaccess-to-hide-app-php-or-app-dev-php . Thanks for pointing to the right direction! – William Feb 20 '16 at 17:49
  • @William no problem! out of curiosity, `.htaccess` didn't exist in your symfony distribution? – ggirtsou Feb 20 '16 at 17:53
  • nope. I used the symfony installer, creating a project version 2.8 – William Feb 20 '16 at 17:56
  • 1
    If you check [symfony's source code](https://github.com/symfony/symfony-standard/blob/2.8/web/.htaccess) on github for `2.8` branch you see `.htaccess` is already there. Did you upload files to your shared hosting server using FTP? Possibly your FTP client did not upload hidden files. – ggirtsou Feb 20 '16 at 18:19
  • Quite possibly yes, although I did the upload from a CentOS dist, in which I do not recall that hidden files were not shown/omitted but a possibility nonetheless. Thanks a lot for your assistance it sure helped me! – William Feb 22 '16 at 08:28