I am using Laravel Forge with AWS EC2 Instance to build a CI/CD Pipeline for a SAAS Laravel project.
Error Attachment: https://i.stack.imgur.com/hsMdK.png
The configurations are fine but when it comes to a tenancy-based project I get this error.
(Stancl\Tenancy\Exceptions\NotASubdomainException
Hostname domain.com does not include a subdomain)
Note: I am using TenancyForLaravel package
I got it fixed in 2 steps.
It wasn't a server-side issue.
1st Step
The TenancyForLaravel package was making an impact, I need to add initializing code for sub-domains in my laravel project.
app/Providers/TenancyServiceProvider.php
public function boot() {
\Stancl\Tenancy\Middleware\InitializeTenancyBySubdomain::$onFail =
function () {
return redirect(env('CENTRAL_DOMAIN'));
};
}
2nd Step
In your laravel root folder
/config/tenancy.php
add your domain name in central_domain
'central_domains' => [
'127.0.0.1',
'localhost',
'domain.com',
],
Related
Let me start of with the fact that im new to laravel and english is not my main language so dont mind my grammer. I have a project that has a laravel api with a vue front-end. The Laravel web routing redirects everything to a single blade file that contains the vue app. this way i can use the vue routing. This is has all been working fine for a while now but now im trying to build for production and ive run into the following issue.
after using npm run build to build for production laravel puts /build/ to every route im using through vue. This is very logical given that it uses the build folder in the public directory like it should. But its ofcourse verry ugly for the users. Is there a way to remove the /build/ from the url? (appart from redirecting /build/ to / in the .htacces file on the server)
You can set the environment variables in .env file for javascript using VITE_ prefix as below:
Please add the new environment variable in .env file as below:
VITE_BASE_URL="/"
Made the router related changes in your Vue file as below:
const router = createRouter({
history: createWebHistory(import.meta.env.VITE_BASE_URL || '/'),
routes: [
.....
],
})
Problem from import.meta.env.BASE_URL in vitejs, in build mode this import.meta.env.BASE_URL result "/build/" and development mode result, is "/"
I don't know where to change this, but I fix this problem with
const router = createRouter({
history: createWebHistory("/"),
routes: [
{
......
}
]
})
and fix it
I am moving from local development with docker-compose to Gitpod.io, an remote dev environment. There I am using the exact same docker images and the same configuration. I am also using local domains (e.g. domain.test) on specific ports in order to address the different applications running on Gitpod. I've established an SSH tunnel, so localhost:port is mapped to Gitpod.
But now I have a strange behavior using subdomains on Laravel.
Opening http://foo.domain.test:8008/foobarius with the following code, results in a 404:
Route::name('foo')
->domain('foo.domain.test:8008')
->group(function() {
Route::get('foobarius', function() {
return "fooo";
});
});
Doing the same but removing the domain part works when opening http://foo.domain.test:8008/foobarius
Route::name('foo')
->group(function() {
Route::get('foobarius', function() {
return "fooo";
});
});
Having the endpoint registered and calling php artisan route:list gives me the following output:
Somehow Laravel seems to ignore the subdomain or does not find the right route within all registered routes.
My hosts file:
127.0.0.1 domain.test
127.0.0.1 foo.domain.test
There is no other docker application running.
I am using Laravel-8 as restful api. Also I am using Dingo Package. Initially the url was:
http://localhost:8888/myapp/server/public
And it was loading correctly.
However, I decided to remove public from the url. So I followed these steps:
Rename server.php in your Laravel root folder to index.php
Copy the .htaccess file from /public directory to your Laravel root folder.
When I tried to reload the url as:
http://localhost:8888/myapp/server
I got this error:
Unable to boot ApiServiceProvider, configure an API domain or prefix
C:\xampp\htdocs\myapp\server\vendor\dingo\api\src\Provider\DingoServiceProvider.php
protected function registerConfig()
{
$this->mergeConfigFrom(realpath(__DIR__.'/../../config/api.php'), 'api');
if (! $this->app->runningInConsole() && empty($this->config('prefix')) && empty($this->config('domain'))) {
throw new RuntimeException('Unable to boot ApiServiceProvider, configure an API domain or prefix.');
}
}
Even with:
http://localhost:8888/mygeapp/server/public/
The same error still applies
How do I resolve this?
Thanks
Please be sure to configure your IPI PREFIX in the env file
API_PREFIX=api
i am importing a live Laravel 4.2 Web application and setup it into my localhost for development.
in the Laravel 5 we usually find the .env file in the root dictionary but in Laravel 4.2 i couldn't be able to find .env and another component and their dictionaries are also different.
can anybody tell me how to import my laravel 4.2 web app into the local host step by step?
All of the configuration files for the Laravel framework are stored in the app/config directory 1. You have to set everything directly there or build an own .env.local.php file with default values like this:
<?php
//file: /.env.local.php
// return the configuration for the 'local' environment
return array(
'db_host' => '127.0.0.1',
'db_name' => 'DB_NAME', // specify database name
'db_user' => 'DB_USER', // specify database username
'db_pass' => 'DB_PASS', // specify database password
);
Our staging environment on a project uses the same domain AKA staging.mydomain.com. How do I get the Laravel database config to point to a different DB as the config switch is based on the hostname which is the same for staging. and www.?
You can update the detectEnvironment method to use a closure function and run your login in there to determine if your application is local or not.
update bootstrap/start.php like this:
$env = $app->detectEnvironment(function() {
return preg_match('/staging/', $_SERVER['HTTP_HOST']) ? 'staging' : 'production';
});
Now when you are visiting your laravel project from http://staging.xxx URL, it will detect it as staging environment.
Now, you can place the database config specific to staging env in here:
app/config/staging/database.php
This should do the trick.