Linux - ServerThis forum is for the discussion of Linux Software used in a server related context.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i would like to make something like creating subdomains on my Apache server.
it can only work, when i create a config file for every subdomains, or i add to httpd-vhosts something like this
<VirtualHost *:80>
ServerAdmin webmaster@dummy-host2.example.com
DocumentRoot "/www/docs/dummy-host2.example.com"
ServerName dummy-host2.example.com
ErrorLog "logs/dummy-host2.example.com-error_log"
CustomLog "logs/dummy-host2.example.com-access_log" common
</VirtualHost>
but what i have to do too, is, change the /etc/hosts file.
add something like, for example: 127.0.0.1 dummy-host2.example.com
the question is, how can i do this from some php script? when the user comes, wants to registrate himself -> by this registration i have to do those things written above, and he will have his subdomain. but, i cannot change /etc/hosts file, because it is owned by root, and php scripts are running under some apache user.
i dont know, if this is possible to make with suid and how is it possible...
pls, how can i do this?
you certainly don't want to be changing /etc/hosts, that's nuts. If you want subdomains then you need to be adding A records to your real DNS servers. are you expecting this local file change to magically work outside of the box? It's much simpler to use subdirectories, not subdomains.
thanks, but in fact, i really need to change /etc/hosts file
because this should work on locahost. i know about A records in DNS system, but i don't have any DNS system and i dont't need it in this case.
creating subdomains, like i described it, works fine. but only when i do it manually. i need to do it somehow automatic...by PHP for example
thanks, but in fact, i really need to change /etc/hosts file
because this should work on locahost. i know about A records in DNS system, but i don't have any DNS system and i dont't need it in this case.
creating subdomains, like i described it, works fine. but only when i do it manually. i need to do it somehow automatic...by PHP for example
There is a right and wrong way to do things. This is an example of the wrong way. Setting this up correctly using apache vhosts and dns is the right way.
Search for php file write and you'll come up with plenty of examples of how to open a file for writing and appending.
There is a right and wrong way to do things. This is an example of the wrong way.
No kidding. For the love of all that is good, don't modify your hosts file like this. You'll kill your system.
To dynamically provision new virtual hosts and such, this is not a "new" idea, this is already done. Look at ISPMan. The only reason not to bother with a setup like ISPMan is if you have very few virutal hosts / sub-domains to deal with ... In which case, why do you want to provision them dynamically?
i know, this way isn't really good, but i don't have any DNS system,like i said above. i need to use this system on my computer, on localhost. i have no acces to dns and won't have it so how could i do it with on localhost? -> everything has to run on localhost - on my computer -> registration, creating subdomains, accesing subdomains etc. but i cannot do everything manually so i need to makesome registrations scripts, and they has to change /etc/hosts file. or no?? or is there some another way, how to do this on localhost?
i know, this way isn't really good, but i don't have any DNS system,like i said above. i need to use this system on my computer, on localhost. i have no acces to dns and won't have it so how could i do it with on localhost? -> everything has to run on localhost - on my computer -> registration, creating subdomains, accesing subdomains etc. but i cannot do everything manually so i need to makesome registrations scripts, and they has to change /etc/hosts file. or no?? or is there some another way, how to do this on localhost?
... run a dns server with a private domain/lan domain using non-public ip addresses?
i don't think so. dns server has nothing to do with my computer. it's everything only about my localhost...
Why not run a dns server on your localhost? A dns server isn't some mystical server out on the internet, it's just another service like a web server or mail server.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.