Last active
April 30, 2023 23:35
-
-
Save yasinkuyu/1b149e4c2fdad523012ec5f191434233 to your computer and use it in GitHub Desktop.
Create a new domain using the DigitalOcean PHP API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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