skip to Main Content

i have a project that build on with Symfony 4.2. I want deploy this project to a shared hosting. But on symfony documentation, there is nothing about it clearly.

I deployed all my project into hosting under public_html.

But probably panel does not find the index.php. On cpanel, i can not change the document root.

current document root: public_html

project folder structure

my index.php under public folder.

   <?php

   use AppKernel;
   use SymfonyComponentDebugDebug;
   use SymfonyComponentHttpFoundationRequest;

   require dirname(__DIR__).'/config/bootstrap.php';

   if ($_SERVER['APP_DEBUG']) {
        umask(0000);

        Debug::enable();
   }

   if ($trustedProxies = $_SERVER['TRUSTED_PROXIES'] ?? 
        $_ENV['TRUSTED_PROXIES'] ?? false) {
        Request::setTrustedProxies(explode(',', $trustedProxies), 
  Request::HEADER_X_FORWARDED_ALL ^ Request::HEADER_X_FORWARDED_HOST);
   }

   if ($trustedHosts = $_SERVER['TRUSTED_HOSTS'] ?? 
       $_ENV['TRUSTED_HOSTS'] ?? false) {
            Request::setTrustedHosts([$trustedHosts]);
   }

   $kernel = new Kernel($_SERVER['APP_ENV'], (bool) 
   $_SERVER['APP_DEBUG']);
   $request = Request::createFromGlobals();
   $response = $kernel->handle($request);
   $response->send();
   $kernel->terminate($request, $response);

Can someone help me about this issue?

2

Answers


  1. I have a symfony4 application running under shared hosting ,so try this configuration in the .htaccess

    <IfModule mod_rewrite.c>
        Options +FollowSymLinks
        RewriteBase /
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ public/index.php [QSA,L]
    </IfModule>
    

    for assets try this in framework.yaml

        assets:
            base_path: '/public'
    
    Login or Signup to reply.
  2. People saying that symfony is not meant for this are just utterly wrong!

    Symfony does not state anything about how to host it, it is (almost) completely agnostic about it’s hosting platform. The only thing you need to do is forward your server requests to the public/index.php.

    I am hosting at OVH cloud, which is semi-private hosting. I got it working by pointing my domain names in the control panel to www/mysymfonyapp/public and add a .htaccess to the public directory:

    # mysymfonyapp/public/.htaccess:
    <IfModule mod_rewrite.c>
        Options +FollowSymLinks
        RewriteBase /
        RewriteEngine On
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php [QSA,L]
    </IfModule>
    

    Works like a charm!

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search