LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices


Reply
  Search this Thread
Old 03-08-2009, 10:02 AM   #1
sparky87
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Rep: Reputation: 0
Apache -> /etc/hosts


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?

thanks for answers
 
Old 03-08-2009, 10:16 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417

Rep: Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985Reputation: 1985
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.
 
Old 03-08-2009, 10:40 AM   #3
sparky87
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Original Poster
Rep: Reputation: 0
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
 
Old 03-09-2009, 11:17 AM   #4
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by sparky87 View Post
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.
 
Old 03-09-2009, 11:40 AM   #5
archangel_617b
Member
 
Registered: Sep 2003
Location: GMT -08:00
Distribution: Ubuntu, RHEL/CentOS, Fedora
Posts: 234

Rep: Reputation: 42
Quote:
Originally Posted by rweaver View Post
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?

- Arch
 
Old 03-09-2009, 03:18 PM   #6
sparky87
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Original Poster
Rep: Reputation: 0
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?
 
Old 03-09-2009, 04:20 PM   #7
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by sparky87 View Post
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?
 
Old 03-09-2009, 04:27 PM   #8
sparky87
LQ Newbie
 
Registered: Mar 2009
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by rweaver View Post
... 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...
 
Old 03-12-2009, 08:35 AM   #9
rweaver
Senior Member
 
Registered: Dec 2008
Location: Louisville, OH
Distribution: Debian, CentOS, Slackware, RHEL, Gentoo
Posts: 1,833

Rep: Reputation: 167Reputation: 167
Quote:
Originally Posted by sparky87 View Post
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
apache + virtual hosts bambeklis Linux - Server 2 05-26-2008 03:40 PM
apache hosts Henster Linux - Software 1 07-24-2005 05:24 AM
apache virtual hosts Red Squirrel Linux - Software 4 06-20-2004 09:05 AM
Apache/Virtual Hosts Help C-Squared Linux - General 9 08-04-2003 12:45 PM
Apache Virtual Hosts quozt Linux - Networking 1 07-29-2003 05:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Server

All times are GMT -5. The time now is 11:41 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration