59
loading...
This website collects cookies to deliver better user experience
php artisan serve
,http://127.0.0.1:8000 // or http://127.0.0.1:8081 etc
Admin
, so we should have something like admin.site.com/
, right ?host
file so we can point our subdomain names to the default IP address.etc
folder, then inside that folder look for the file named, hosts
.hosts
file then open it up with a text editor (I will recommend vscode or anyother text editor that lets you edit the file with an interface to enter your password incase that file requires a super or an admin user permissions)hosts
file, you should see something like this :site
to 127.0.0.1
and same thing for admin.site
to 127.0.0.1
127.0.0.1 site
127.0.0.1 admin.site
httpd-vhosts.conf
and httpd.conf
httpd-vhosts.conf
in this path opt\lamp\etc\extra\httpd-vhosts.conf
//for site (root domain)
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/opt/lampp/htdocs/laravel/siteproject/public"
ServerName site
ServerAlias *.site
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
<Directory "/opt/lampp/htdocs/laravel/siteproject/public">
Require all granted
</Directory>
</VirtualHost>
//for admin.site (subdomain)
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot "/opt/lampp/htdocs/laravel/siteproject/public"
ServerName admin.site
ServerAlias www.admin.site
ErrorLog "logs/dummy-host.example.com-error_log"
CustomLog "logs/dummy-host.example.com-access_log" common
<Directory "/opt/lampp/htdocs/laravel/siteproject/public">
Require all granted
</Directory>
</VirtualHost>
DocumentRoot
variable or section in side the virtualHost tag should point to the specific folder where your laravel project is; and yes, even to the public
folder of your laravel projec too"/opt/lampp/htdocs/laravel/siteproject/public"
ServerName
refers to the domains we want to use.httpd.conf
. The likely path should be,opt\lamp\etc\httpd.conf
# Include etc/extra/httpd-vhosts.conf
# Virtual hosts
Include etc/extra/httpd-vhosts.conf
sudo /opt/lampp/lampp restart
. So restart your xammp in your preferred way.web.php
file :Route::domain('admin.explore')->group(function () {
Route::get('/', function () {
return "I will only trigger when domain is admin.explore.";
});
});
Route::get('/', function () {
return view('welcome');
});
In order to ensure your subdomain routes are reachable, you should register subdomain routes before registering root domain routes. This will prevent root domain routes from overwriting subdomain routes which have the same URI path.
//Rooot Domain route(s)
Route::get('/', function () {
return view('welcome');
});
//Sub Domain route(s)
Route::domain('admin.site')->group(function () {
Route::get('/', function () {
return "I will only trigger when domain is admin.site.";
});
});
//Sub Domain route(s)
Route::domain('admin.site')->group(function () {
Route::get('/', function () {
return "I will only trigger when domain is admin.site.";
});
});
//Root Domain route(s)
Route::get('/', function () {
return view('welcome');
});