Multiple domains, multiple databases with only one script

Hello all,

i need create multiple (sub)domains on one server (linux) but.. i want all domains read same script location (for example /var/script/index.php...)

lets say :


when u come to u get login page where u can chose (sub) domains, and when u chose sub domain, enter user and password then click on login button u will be redirected to selected domain, you will be using db_one config and u will be logged in (if all info are good - user, pass).

so my final question is :
is this posible to have one script and using this one script in multiple domains/subdomains and how ?


PS. sorry for my bad english :S
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sebastian TalmonSystem Engineer Datacenter SolutionsCommented:

based on your path (var/script) is it correct that you have your own webserver, and do not need a solution for shared hosting?

In the apache-config, you could allow the use of symlinks in linux  (set SymLinksIfOwnerMatch to on). Based on this, you could create symlinks in all three homedirs to this central file. PHP takes this file just as if it was duplicated for all three domains, with  require_once('') or something similar you could include code that is different for the three domains (i.e. the database parameters)
Monis MontherSystem ArchitectCommented:
Configure Virtual Hosts under your apache

Leave the main virtual host with your index.php scripts

Configure Redirects for the others

Each one of those is a topic that you need to search for on google, I advice starting with the Apache official documentation

This is for version 2.2

Sebastian TalmonSystem Engineer Datacenter SolutionsCommented:

does the user has to choose which subdomain he wants to connect to BEFORE the login, or is there a need for an option-field in the login-form itself?

If you have to choose in the login-form, then you will have to do the login on the main domain (www) and do a redirect after login - but then it gets a little bit complex as you have to transfer the session between two domains/vhosts (from the main site which checks the login, to the target domain where the content is)

If you could live with having only links to the three subdomain on the main site, and do the login on each subdomain, it is much easier as the login-session remains in only one domain  (sharing the php-code for login-script between the three subdomains could be made with symlinks as mentioned before)

Marshall2056Author Commented:
well i want something similar to egroupware
before u login u choose for domain or u can type like username@domain.ext
then script will redirect to domain.ext and check db for username and password on this domain
but egroupware using one database ..i will use one database for one domain

aka domain name = one.domain.ext  db name = one.domain.ext

Sebastian TalmonSystem Engineer Datacenter SolutionsCommented:


i think the only thing that will work is:
(given all domains are subdomains of one main domain, otherwise cookies could not be shared)

* login-form on www.domain.ext,   target of form also www.domain.ext
* www.domain.ext  only opens a session, with session_save_path in a shared directory between the domains, and with cookie-path  .domain.ext  (take care of the dot before the domain!)
* after setting the cookie/open a session, write username/password as session-variables, and redirect to the subdomain
* on first page of subdomain, use the same session, and check the user/password-session-variables against the corresponding database
* grant rights to the user if user/pass is correct


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.