Reputation: 440
I need to setup a development and production environment using subdomains with Laravel and Apache. For example:
dev.mydomain.com
app.mydomain.com
Where app is production and dev is development. Inside of my /var/www I have the folders dev.mydomain.com and app.mydomain.com. Inside of each of these folders I have identical Laravel projects (aside from the config files pointing to different subdomains and databases).
I wanted to separate the locations to be able to test on different databases and also to test out new development files before pushing to production (with little to no downtime). I am able to access either subdomain one at a time by temporarily removing the config of the other in my Apache config files, but this is cumbersome and it causes downtime for both applications.
My .htaccess files appear to be correct because I can view a test url on both subdomains (by using simple .html files). When I try to access the subdomains with laravel installed I am getting strange results like being able to connect to the dev database while in the app subdomain OR being able to log into the app env, but not being able to login into the dev environment or vice versa.
I have been searching around stackoverflow and googling to try to find a solution, but nothing has come up so far. I have mainly found tutorials on how to setup
detectEnvironment
with laravel like in the link here:
http://chrishayes.ca/blog/code/laravel-4-setting-utilizing-environments-environment-configuration
Does anybody have a solution for this or a better way of working with a dev/test environment in Laravel along side a production environment?
Upvotes: 0
Views: 360
Reputation: 111899
In bootstrap/start.php
what you can do is to set environment depending on used domain:
$env = $app->detectEnvironment(function(){
if (!isset($_SERVER['HTTP_HOST']) ||
$_SERVER['HTTP_HOST'] =='dev.mydomain.com') {
return 'dev';
}
return 'production';
});
The only problem here is with artisan
I believe - you will be able to use it only for one environment. In above code artisan will be used for dev environment (because if you use artisan $_SERVER['HTTP_HOST']
is not set and in above code for this dev
development is being chosen.
Upvotes: 0