Automatic/Push Button site folder/vhost creation in Linux via CI/PHP |
[eluser]Devon Lambert[/eluser]
I realize that what I propose here may seem a little far fetched, but please hear me out. I am hoping that someone out there knows a way to create a One Push button scenario whereby a site is created from within a CI/PHP created backend, with appropriate info being sent to your Database, meanwhile, on the server side of things (assuming Apache), your folder structure is automatically put into place, and then the final, and most difficult for me, the appropriate vhost addition is made to your Servers host file. I've been able to tackle the vast majority of this, all except the vhost addition. The whole scenario MUST be possible as Cpanel has the ability to do this for you, therefore I believe that there must be some script that is able to replicate Cpanel's capabilities. The reason for this is that I am creating a multi - site dashboard that runs on CI. I would love to not have to leave this dashboard, drop to the command line to create a new addition to my Host file every time I want to add a new site in the backend. So... any takers? :-) ** UPDATE ** Think I may have found what I'm looking for: http://httpd.apache.org/docs/2.0/vhosts/mass.html May be useful to some one else as well.
[eluser]n0xie[/eluser]
You can just write a bash script, then call that from within PHP. This is my addsite.sh I call when starting a new project which takes care of vhost and hosts file: Code: #!/bin/bash
[eluser]Devon Lambert[/eluser]
[quote author="n0xie" date="1274364339"]You can just write a bash script, then call that from within PHP. This is my addsite.sh I call when starting a new project which takes care of vhost and hosts file[/quote] Hey Noxie, Does this code actually make an addition to the existing vhost/host files OR does it create a new vhost/host file for each site? Pardon my stupidity on this one, I only ask because I do not see where the actual site/domain is being defined? i.e. How do you tell the script that your adding www.mygreatnewsite.com to the file and also how does it know that this new site is supposed to reference the same ip address as every other site already on file? Thanks again for this, I'm sure once I figure it out it will be immensely useful.
[eluser]Devon Lambert[/eluser]
A php version of the following would be nice! http://travisonrails.com/2009/08/10/ruby...host-entry
[eluser]n0xie[/eluser]
[quote author="Devon Lambert" date="1274390710"][quote author="n0xie" date="1274364339"]You can just write a bash script, then call that from within PHP. This is my addsite.sh I call when starting a new project which takes care of vhost and hosts file[/quote] Hey Noxie, Does this code actually make an addition to the existing vhost/host files OR does it create a new vhost/host file for each site? [/quote] It creates a new vhost for every file. Quote:i.e. How do you tell the script that your adding www.mygreatnewsite.com to the fileIt accepts a parameter, which is the name of the site. In my case ./addsite www.mygreatnewsite.com, creates www.mygreatnewsite.com. It copies my template vhost file then replaces all instances of the word 'site' with the actual site name. Quote:how does it know that this new site is supposed to reference the same ip address as every other site already on file?I don't really understand the question: you tell your vhosts what url belongs to it and apache takes care of the rest. The ip part is usually done using dns.
[eluser]Devon Lambert[/eluser]
Ok I think I understand. I will have multiple sites that need to live on the same server, same ip, etc... So I would not want a separate vhost file for each site. What I want is to update the current vhost file for each new site that is added. I hope this makes sense, as I'm still trying to wrap my brain around this whole virtual host scripting idea. Thanks again Noxie.
[eluser]n0xie[/eluser]
[quote author="Devon Lambert" date="1274476439"] I will have multiple sites that need to live on the same server, same ip, etc... So I would not want a separate vhost file for each site.[/quote] Why not?
[eluser]Devon Lambert[/eluser]
I guess I never realized that you could use multiple vhost files? Again, my knowledge of the server environment is touchy at best. I like to keep as much knowledge on hand to make my way around, but scripting, hosts/vhosts, etc... are definitely not my strong points.
[eluser]Kamarg[/eluser]
[quote author="Devon Lambert" date="1274391841"]A php version of the following would be nice! http://travisonrails.com/2009/08/10/ruby...host-entry[/quote] Untested but a quick attempt at translation without much error checking. Code: <?php Edit: Noticed I still had Ruby comments instead of PHP comments.
[eluser]Devon Lambert[/eluser]
[quote author="Kamarg" date="1274497364"][quote author="Devon Lambert" date="1274391841"]A php version of the following would be nice! http://travisonrails.com/2009/08/10/ruby...host-entry[/quote] Untested but a quick attempt at translation without much error checking. [/quote] Gotta love the CI community! You guys are the shiznit. Which basically means that you rock. :-) Thanks to both Noxie and Kamarg. I have enough to go on here guys. I'll try to get this implemented over the weekend, wish me luck. |
Welcome Guest, Not a member yet? Register Sign In |