Marco Ciaramella
Marco Ciaramella

Reputation: 228

web app in Symfony unreachable via APP_DOMAIN on local host

I deployed on my local machine a Symfony app. The following is the associated .env file

###> symfony/framework-bundle ###
APP_ENV=dev
APP_SECRET=******
APP_DOMAIN=myapp.test
API_DOMAIN=api.myapp.test

###> symfony/swiftmailer-bundle ###
# For Gmail as a transport, use: "gmail://username:password@localhost"
# For a generic SMTP server, use: "smtp://localhost:25?encryption=&auth_mode="
# Delivery is disabled by default via "null://localhost"
MAILER_URL=smtp://localhost:1025
###< symfony/swiftmailer-bundle ###

###> doctrine/doctrine-bundle ###
# Format described at http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#connecting-using-a-url
# For an SQLite database, use: "sqlite:///%kernel.project_dir%/var/data.db"
# Configure your db driver and server_version in config/packages/doctrine.yaml
DATABASE_URL=postgres://[email protected]:5432/myapp_dev
TEST_DATABASE_URL=postgres://[email protected]:5432/myapp_test
###< doctrine/doctrine-bundle ###

###> sentry/sentry-symfony ###
SENTRY_DSN=
###< sentry/sentry-symfony ###

......

I run the server with invoker

port=8000
command=bin/console server:run

Where bin/console is

#!/usr/bin/env php
<?php

use App\Kernel;
use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Component\Console\Input\ArgvInput;
use Symfony\Component\Debug\Debug;
use Symfony\Component\Dotenv\Dotenv;

set_time_limit(0);

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

if (!class_exists(Application::class)) {
    throw new \RuntimeException('You need to add "symfony/framework-bundle" as a Composer dependency.');
}

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');
}

$input = new ArgvInput();
$env = $input->getParameterOption(['--env', '-e'], $_SERVER['APP_ENV'] ?? 'dev', true);
$debug = (bool) ($_SERVER['APP_DEBUG'] ?? ('prod' !== $env)) && !$input->hasParameterOption('--no-debug', true);

if ($debug) {
    umask(0000);

    if (class_exists(Debug::class)) {
        Debug::enable();
    }
}

$kernel = new Kernel($env, $debug);
$application = new Application($kernel);
$application->run($input);

The problem is: I can reach the web app via 127.0.0.1:8000 but not via myapp.test. I need to reach via myapp.test. Why does it not work?

Upvotes: 0

Views: 481

Answers (1)

crazyman10123
crazyman10123

Reputation: 58

You need to modify your HOSTS file to register myapp.test as 127.0.0.1:8000 or you can use Symfony's Local Proxy

Upvotes: 0

Related Questions