Create subdomains for php
I try but the page is blank or generates error message IPv4/IPv6 address
// http://www.linode.com/api/
// Create a domain record
$api_key = "MY_API";
$domain_id = 9485;
$subdomain = $_GET['subdomain'];
$json_url = 'https://api.linode.com/?api_key=' .
$api_key .
'&api_action=batch&api_requestArray=[{' .
'"api_action": "domain.resource.create",' .
'"domainid": ' . $domain_id . ', ' .
'"Name": "' . $subdomain . '", "Type":"A", "TTL_sec":0' .
'}]';
$json_file = file_get_contents($json_url,0,null,null);
$data = json_decode($json_file, true);
print_r($data);
Even if I can, I'll have to run a script to enable the new site created, where do not know if exec () you can run it on apache …
Look:
A friend gave me a script to adapt but do not know in which directory to let these scripts. He did not specify that.
#!/usr/bin/php
readName()
->readPath()
->create();
break;
case 'deletar':
$vhost->readName()
->delete();
break;
default:
die("\n" . 'Erro: Ação inválida!' . "\n\n");
}
vhost.php
name;
}
public function readName()
{
$this->name = readline("\n" . 'Digite o nome do VirtualHost: ');
return $this;
}
public function readPath()
{
$this->path = readline("\n" . 'Digite o caminho da pasta web do VirtualHost: ');
if ( ! is_dir($this->path) )
die ("\n" . 'Erro: O caminho informado não é um diretório válido.' . "\n\n");
return $this;
}
public function create()
{
$vhostFile = fopen('/etc/apache2/sites-available/' . $this->name, 'w');
fwrite($vhostFile, $this->getStructure());
$this->enable();
exec('sudo -u username google-chrome http://' . $this->name);
exit("\n" . 'VirtualHost criado!' . "\n\n");
}
private function getStructure()
{
return "
<virtualhost *:80="">DocumentRoot $this->path
ServerName $this->name
# This should be omitted in the production environment
SetEnv APPLICATION_ENV development
<directory $this-="">path>
Options Indexes MultiViews FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all</directory></virtualhost>
";
}
private function enable()
{
$hostsFile = fopen('/etc/hosts', 'a');
fwrite($hostsFile, "\n" . '127.0.0.1 ' . $this->name);
exec('a2ensite ' . $this->name);
exec('service apache2 reload');
}
public function delete()
{
if ( unlink('/etc/apache2/sites-available/' . $this->name) ) {
$this->disable();
exit("\n" . 'VirtualHost deletado!' . "\n\n");
} else
die("\n" . 'Erro: Este VirtualHost não existe!' . "\n\n");
}
private function disable()
{
exec('a2dissite ' . $this->name);
exec('service apache2 reload');
}
}
1 Reply
[user@hostname ~]$ dig mail.yahoo.com +short
login.yahoo.com.
login-global.lgg1.b.yahoo.com.
login.lga1.b.yahoo.com.
66.163.169.186
^ Valid ip address. Remember you can setup a * (wildcard) record for A records.