I am developing a webhosting hosting controlpanel with codeigniter. So far so good. :)
Now I am working on a solution creating virtual hosts. My shell script that creates the virtual host works, so my first thought was to fire that script in a cronjob let say every 15 minutes. That should work.
But not every 15 minutes there won't be a new virtual host to create. So, I think it's to much to reload the apache config every 15 minutes.
By the way, on the codeigniter side it just make a simple textfile with the values that belongs by that new virtual host.
So, is there a save solution to do it in realtime? My gues is, that the only way to do it realtime to use shell_exec(), but that's not a save way.
I must say that my shell scipting is very novice so maybe there is a way to trigger a if or else statement to choose to create a virtual host or just do nothing. But how can i do that? Then i don't need to do it in realtime.
This is my shell script:
#!/bin/bash
vhroot='/etc/apache2/sites-available/'
NEW_DOMAINS="/home/domain.txt"
cat ${NEW_DOMAINS} | \
while read domain user email
do
echo "<VirtualHost *:80>
ServerName "$domain"
ServerAlias www."$domain"
ServerAdmin "$email"
DocumentRoot /home/"$user"/domains/"$domain"/public_html
</VirtualHost>" > $vhroot/$domain
#mkdir /home/$user/domains/domain
#mkdir /home/$user/domains/$domain/public_html
#chown -R $user.$user /home/$user/domains/$domain
echo "111.21.111.111 $domain" >> host.txt
#a2ensite $hostname
done
echo "" > /home/domain.txt
# /etc/init.d/apache2 reload
I hope someone has a simple but effective solution for this problem.