0

I am using the Symfony framework. I assigned the public folder to my subdomain project.mypage.com Now I only see a blank page. If I instead assign the root folder of Symfony to my subdomain and go to project.mypage.com/public then I see my website! This is strange...

This is my index.php in the public folder:

<?php

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/../vendor/autoload.php';

// The check is to ensure we don't use .env in production
if (!isset($_SERVER['APP_ENV'])) {
    if (!class_exists(Dotenv::class)) {
        throw new \RuntimeException('APP_ENV environment variable is not defined. You need to define environment variables for configuration or add "symfony/dotenv" as a Composer dependency to load variables from a .env file.');
    }
    (new Dotenv())->load(__DIR__.'/../.env');
}

$env = $_SERVER['APP_ENV'] ?? 'dev';
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env));

if ($debug) {
    umask(0000);

    Debug::enable();
}

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

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

$kernel = new Kernel($env, $debug);
$request = Request::createFromGlobals();
$response = $kernel->handle($request);
$response->send();
$kernel->terminate($request, $response);

This is the last entry in my dev.log:

[2018-06-05 15:36:42] request.INFO: Matched route "_wdt". {"route":"_wdt","route_parameters":{"_controller":"web_profiler.controller.profiler:toolbarAction","token":"28c9ba","_route":"_wdt"},"request_uri":"http://project.mypage.com/public/_wdt/38c9ba","method":"GET"} []
peace_love
  • 6,229
  • 11
  • 69
  • 157
  • If you are clueless, trying echoing any value before and after your require('autoload') file, to check if the file is getting included or not. – 5eeker Jun 06 '18 at 06:30
  • @5eeker I echo before and after `require("autoload")`. I get a blank page. But If I delete the code after until the end of the document, then I see the echoed values – peace_love Jun 06 '18 at 06:42
  • I also tried to write `ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);` at the beginning of the index.php. But the page is still blank – peace_love Jun 06 '18 at 06:47
  • do echo('123);exit; before require, if it echoes... try echo('123'); require(); echo ("after"); exit; I think the issue is with your require ('autoload'); – 5eeker Jun 06 '18 at 06:52
  • @5eeker I am also cofused. But the "exit" is not working. I have a blank page. Only when I remove the code after the echo, then I see "123" – peace_love Jun 06 '18 at 06:55
  • Try commenting your require(); you will see errors. – 5eeker Jun 06 '18 at 06:55
  • Possible duplicate of [PHP's white screen of death](https://stackoverflow.com/questions/1475297/phps-white-screen-of-death) – CBroe Jun 06 '18 at 07:29

1 Answers1

1

I think the issue is with your require statement. Check where is your vendor folder.

For ex: If your code file (below) is on the same directory level as vendor, you will not have to use '..' in require.

use App\Kernel;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;
use Symfony\Component\HttpFoundation\Request;

require __DIR__.'/vendor/autoload.php';

Vice versa, if it is two or more levels inside a directory add the '../..' like so

5eeker
  • 1,016
  • 1
  • 9
  • 30
  • I echoed `__DIR__`. It is `...www/project/public` – peace_love Jun 06 '18 at 07:00
  • The vendor folder is in the root, this means in the same level then public www/project/vendor – peace_love Jun 06 '18 at 07:01
  • yeah, if it is in the same level remove the two .. (dots) and / (backslash) it should work, check the require statement in my answer – 5eeker Jun 06 '18 at 07:02
  • I removed it, as recommended, but still a blank page :'( – peace_love Jun 06 '18 at 07:04
  • Maybe I should not assign my website to the public folder... Because it works when I assign it to the root folder and go to project.mypage.com/public – peace_love Jun 06 '18 at 07:08
  • You haven't done that, symfony reads the public directory at start to serve pages do that and check please – 5eeker Jun 06 '18 at 07:10
  • 1
    Ok, I found a working solution. I do not know if this is the best. I assigned the domain to the root folder. There I created a .htaccess file with this content `RewriteEngine on RewriteCond %{HTTP_HOST} ^mypage.com$ [NC,OR] RewriteCond %{HTTP_HOST} ^project.mypage.com$ RewriteCond %{REQUEST_URI} !public/ RewriteRule (.*) /public/$1 [L]` Now everyting is working fine – peace_love Jun 06 '18 at 07:15