Skip to content

Instantly share code, notes, and snippets.

@yasinkuyu
Last active April 30, 2023 23:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yasinkuyu/1b149e4c2fdad523012ec5f191434233 to your computer and use it in GitHub Desktop.
Save yasinkuyu/1b149e4c2fdad523012ec5f191434233 to your computer and use it in GitHub Desktop.
Create a new domain using the DigitalOcean PHP API
<?php
// DigitalOcean API https://cloud.digitalocean.com/settings/applications
require_once 'vendor/autoload.php';
$url = "yasin.com";
$ip = "XX.XX.XX.XXX";
$client = new DigitalOceanV2\Client();
$client->authenticate('dop_v1_XXXX');
$domain = $client->domain();
$domain->create($url, $ip);
$domainRecord = $client->domainRecord();
$domainRecords = $domainRecord->getAll($url);
// Delete default records
foreach($domainRecords as $rec)
{
if($rec->type == "NS"){
$domainRecord->remove($url, $rec->id);
}
}
$domainRecord->create($url, 'A', 'ns1', '173.245.XXX');
$domainRecord->create($url, 'A', 'ns2', '173.245.XXX');
$domainRecord->create($url, 'A', 'ns3', '198.41.XXX');
$domainRecord->create($url, 'A', 'www', $ip);
$domainRecord->create($url, 'NS', '@', "ns1.$url.");
$domainRecord->create($url, 'NS', '@', "ns2.$url.");
$domainRecord->create($url, 'NS', '@', "ns3.$url.");
$domainRecord->create($url, 'MX', '@', 'mail.yandex.net.', '10' );
$domainRecord->create($url, 'TXT', '@', "v=spf1 a mx ip4:$ip ~all");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment