This is what I had in perl - I just want to do the same now that I am converting to PHP.
-----snippet
#!/usr/bin/perl
#add user to system 🙂
$username = @ARGV[0];
$domain_name = @ARGV[1];
#add apache vhost
cp -f /usr/local/apache/conf/httpd.conf /usr/local/apache/conf/httpd.conf.last.bak;
undef $/;
open(CONF,"/usr/local/apache/conf/httpd.conf") || die("can't open httpd.conf: $!\n");
flock(CONF,2);
$httpdconf = <CONF>;
close(CONF);
$/ =1;
$newvhost .= "<VirtualHost 203.109.175.135>\n";
$newvhost .= " ServerAdmin webmaster@$domain_name\n";
$newvhost .= " DocumentRoot /home/$username/public_html\n";
$newvhost .= " ServerName $domain_name\n";
$newvhost .= " ServerAlias www.$domain_name\n";
$newvhost .= " ErrorLog /home/$username/logs/error_log\n";
$newvhost .= " CustomLog /home/$username/logs/access_log common\n";
$newvhost .= " User $username\n";
$newvhost .= " Group users\n";
$newvhost .= " Options Indexes Includes ExecCGI SymLinksIfOwnerMatch\n";
$newvhost .= "</VirtualHost>\n";
$newvhost .= "#EndVhostsConfig\n";
$httpdconf =~ s/#EndVhostsConfig/$newvhost/;
$newhttpdconf = $httpdconf;
open (NEWCONF,">/usr/local/apache/conf/httpd.conf") || die("Can't open httpd.conf for writing: $!\n");
flock(NEWCONF,2);
print NEWCONF "$newhttpdconf";
close (NEWCONF);
print "new vhost added.\n";
print "adduser.pl finished.\n\n";
print "System account, master email and Apache Vhost has been set-up.\n";
print "You should now do dns for this domain and add this account to the user database.\n";