Random Bright, Funny, Info, Deep Thoughts, AI Chats, and More

[
[
[

]
]
]

While there is no “bulk” button in the Google Search Console UI, you can automate this using the Google Site Verification API and the Search Console API. Since you mentioned you build pages in HTML/PHP and manage a Linux VPS, you can run a script to handle this.

Here is the high-level workflow to automate this:


1. Prerequisites & Setup

Before scripting, you need to enable the APIs in the Google Cloud Console:

  • Enable APIs: Search for and enable both the Site Verification API and the Google Search Console API.
  • Create Credentials: Create an OAuth 2.0 Client ID (Desktop app) or a Service Account.
    • Note: If using a Service Account, you must add that service account’s email as an “Owner” in Search Console for the properties you want to manage.
  • Scopes needed: * https://www.googleapis.com/auth/siteverification
    • https://www.googleapis.com/auth/webmasters

2. The Verification Logic

The process for each domain follows three distinct steps. You can iterate through your list of 50 domains using this logic:

Step A: Get the Token

Request a verification token for the domain.

  • Method: siteVerification.webresource.getToken
  • Verification Method: Use FILE (uploads an HTML file) or DNS_TXT (adds a DNS record). Since you use Hostinger, FILE is often easier to automate if you can programmatically upload a file to your sites via FTP/SSH.

Step B: Place the Token

  • HTML File: Create a file named google[unique_string].html with the content Google provides and upload it to the root directory of your site.
  • DNS: Use the Hostinger API to add a TXT record to the domain’s DNS zone.

Step C: Trigger Verification

Tell Google to check the domain.

  • Method: siteVerification.webresource.insert
  • Payload: Provide the site URL and the verification method used.

3. Automation Script (Python Example)

Using the google-api-python-client library, your core logic for the loop would look like this:

Python

from googleapiclient.discovery import build
# Initialize the service
service = build('siteVerification', 'v1', credentials=your_creds)
domains = ["example1.com", "example2.com", "..."]
for domain in domains:
# 1. Get the token
token_request = {
"verificationMethod": "FILE",
"site": {"identifier": f"https://{domain}/", "type": "SITE"}
}
token_response = service.webresource().getToken(body=token_request).execute()
token = token_response['token']
# 2. [Your Code Here] Upload 'token' as an HTML file to your server
# (e.g., using paramiko for SSH or an FTP library)
# 3. Verify
verify_request = {
"site": {"identifier": f"https://{domain}/", "type": "SITE"}
}
service.webresource().insert(verificationMethod="FILE", body=verify_request).execute()
print(f"Verified {domain}")

4. Hostinger Integration

To make this truly “bulk,” you can use the Hostinger API to fetch your list of 50 domains so you don’t have to type them manually.

  • Endpoint: GET /api/domains/v1/portfolio
  • DNS Automation: If you prefer DNS verification, you can use Hostinger’s POST /api/dns/v1/zones/{domain} to inject the TXT records programmatically.

Important Notes

  • Propogation: If using DNS verification, add a time.sleep(60) in your script to allow Hostinger’s DNS to update before asking Google to verify.
  • Limits: The Site Verification API has rate limits (usually 100 requests per 100 seconds), but for 50 domains, you shouldn’t hit them unless you run the script multiple times rapidly.

Would you like me to help you write a PHP script to handle the file upload portion, or a Python script that uses SSH to place the files on your VPS?

PHP

Since you prefer working in PHP, you can use the Google Cloud PHP Client to handle this. Because you have 50 domains, the most efficient way to “bulk” this is to have your script generate the verification files, upload them to your sites (via SFTP or by running the script locally on your VPS), and then notify Google.

Here is a streamlined approach to get this done.

1. Install the Google API Client

Run this on your VPS or local dev environment:

Bash

composer require google/apiclient

2. The PHP Verification Script

This script assumes you have a service-account.json file from the Google Cloud Console.

PHP

<?php
require_once 'vendor/autoload.php';
$client = new Google\Client();
$client->setAuthConfig('service-account.json');
$client->addScope('https://www.googleapis.com/auth/siteverification');
$client->addScope('https://www.googleapis.com/auth/webmasters');
$service = new Google\Service\SiteVerification($client);
$domains = [
'example1.com',
'example2.com',
// ... add all 50 here
];
foreach ($domains as $domain) {
try {
$siteUrl = "https://{$domain}/";
// STEP 1: Get the token (the filename and content Google wants)
$tokenRequest = new Google\Service\SiteVerification\SiteVerificationWebResourceGettokenRequest();
$site = new Google\Service\SiteVerification\SiteVerificationWebResourceGettokenRequestSite();
$site->setIdentifier($siteUrl);
$site->setType('SITE');
$tokenRequest->setSite($site);
$tokenRequest->setVerificationMethod('FILE');
$response = $service->webresource->getToken($tokenRequest);
$token = $response->getToken(); // This looks like "google-site-verification: google123.html"
// STEP 2: Create the file
// Extract filename from the token (usually everything after the colon)
preg_match('/google.*\.html/', $token, $matches);
$filename = $matches[0];
// Save the file locally so you can upload it to the sites
file_put_contents("./verifications/{$domain}_{$filename}", $token);
echo "Token generated for $domain: $filename\n";
/**
* STEP 3: Manual/Automated Upload
* You must move $filename to the root of $domain's web directory.
* Since you are on a VPS, you could use 'scp' or 'mv' commands here.
*/
// STEP 4: Tell Google to check it
$insertRequest = new Google\Service\SiteVerification\SiteVerificationWebResource();
$siteResource = new Google\Service\SiteVerification\SiteVerificationWebResourceSite();
$siteResource->setIdentifier($siteUrl);
$siteResource->setType('SITE');
$insertRequest->setSite($siteResource);
$service->webresource->insert('FILE', $insertRequest);
echo "Successfully verified $domain\n\n";
} catch (Exception $e) {
echo "Error with $domain: " . $e->getMessage() . "\n";
}
}

3. Handling the “Bulk” Upload to Hostinger

Since you have 50 sites, manually uploading files is tedious. You have two main options:

  • Option A (The VPS Way): If your 50 domains are all hosted on the same VPS, you can modify the script to file_put_contents directly into each site’s public_html folder using their absolute paths (e.g., /home/user/domains/example.com/public_html/).
  • Option B (The Hostinger API): If they are on Hostinger shared hosting, you can use the Hostinger File Manager API (if available for your plan) or a simple PHP FTP loop using ftp_put() to distribute the files before the verification step in the script above.

4. Final Step: Add to Search Console

Verification only proves you own it; you still need to add it as a “Property.” Once verified, use the Search Console API (Google\Service\SearchConsole) to add the site:

PHP

$scService = new Google\Service\SearchConsole($client);
$siteEntry = new Google\Service\SearchConsole\WmxSite();
$scService->sites->add($siteUrl);

Would you like me to help you refine the loop to automatically move the files into your specific VPS directory structure?

Yes

Since you’re managing these on a Linux VPS, the most efficient way to handle 50 domains is to have your PHP script write the verification files directly to the respective directories.

To do this successfully, your VPS user needs write permissions for the web roots. Below is the refined logic to handle the token generation, file placement, and Search Console registration in one go.

Automated PHP Bulk Script

This script assumes a standard directory structure like /var/www/html/domain.com/public_html.

PHP

<?php
require_once 'vendor/autoload.php';
$client = new Google\Client();
$client->setAuthConfig('service-account.json');
$client->addScope([
'https://www.googleapis.com/auth/siteverification',
'https://www.googleapis.com/auth/webmasters' // Required for Search Console
]);
$verificationService = new Google\Service\SiteVerification($client);
$searchConsoleService = new Google\Service\SearchConsole($client);
// List of your 50 domains
$domains = [
'example1.com',
'example2.com',
// ...
];
foreach ($domains as $domain) {
try {
$siteUrl = "https://{$domain}/";
$webRoot = "/var/www/html/{$domain}/public_html/"; // Adjust to your VPS path
// 1. GET THE TOKEN
$tokenRequest = new Google\Service\SiteVerification\SiteVerificationWebResourceGettokenRequest();
$site = new Google\Service\SiteVerification\SiteVerificationWebResourceGettokenRequestSite();
$site->setIdentifier($siteUrl);
$site->setType('SITE');
$tokenRequest->setSite($site);
$tokenRequest->setVerificationMethod('FILE');
$response = $verificationService->webresource->getToken($tokenRequest);
$token = $response->getToken();
// 2. EXTRACT FILENAME AND CONTENT
// The token for FILE method is usually: "google-site-verification: google12345.html"
$parts = explode(': ', $token);
$filename = trim($parts[1]);
$content = $token; // The file content should be the full string Google provides
// 3. WRITE FILE DIRECTLY TO VPS DIRECTORY
$filePath = $webRoot . $filename;
if (file_put_contents($filePath, $content)) {
echo "Created $filename for $domain\n";
} else {
throw new Exception("Failed to write file to $webRoot. Check permissions.");
}
// 4. TRIGGER GOOGLE VERIFICATION
$insertRequest = new Google\Service\SiteVerification\SiteVerificationWebResource();
$siteResource = new Google\Service\SiteVerification\SiteVerificationWebResourceSite();
$siteResource->setIdentifier($siteUrl);
$siteResource->setType('SITE');
$insertRequest->setSite($siteResource);
$verificationService->webresource->insert('FILE', $insertRequest);
echo "Verified ownership for $domain\n";
// 5. ADD TO SEARCH CONSOLE
$searchConsoleService->sites->add($siteUrl);
echo "Successfully added $domain to Search Console\n\n";
} catch (Exception $e) {
echo "Error processing $domain: " . $e->getMessage() . "\n";
}
}

Crucial Setup Steps

  • Service Account Permissions: When you create the Service Account in the Google Cloud Console, it acts as its own “user.” For the script to add sites to your main Search Console account, you must log in to the Search Console UI and add the Service Account email as an Owner for at least one property, or manage them entirely under the Service Account.
  • Directory Permissions: If your PHP script is running as www-data but your website files are owned by nathan, the script might fail to write the .html file. You may need to run:sudo chown -R www-data:www-data /var/www/html/ (or your specific path) before running the script.
  • The “Double-Check”: Since you mentioned you use Hostinger, ensure your VPS firewall (or Hostinger’s external firewall) allows Google’s bot to crawl the site for that HTML file.

Verifying Results

Once the script finishes, you can check the status of your properties directly in the Search Console dashboard.

Would you like me to help you write a separate PHP snippet to fetch all 50 domain names from your Hostinger account automatically so you don’t have to type the array manually?

Yes

To automate fetching your 50 domains from Hostinger, you can use the Hostinger API Portfolio endpoint. This eliminates the need to manually update your domain array in the script.

1. Get your Hostinger API Token

  1. Log in to your Hostinger hPanel.
  2. Go to Account -> API Tokens.
  3. Create a new token (ensure it has permissions for “Domains”).

2. Refined PHP Script

This version first fetches your live domain list from Hostinger and then proceeds with the Google verification and Search Console setup.

PHP

<?php
require_once 'vendor/autoload.php';
// --- CONFIGURATION ---
$hostingerApiToken = 'YOUR_HOSTINGER_API_TOKEN';
$googleServiceAccountFile = 'service-account.json';
$baseWebPath = '/var/www/html/'; // Base directory for your sites
// --- INITIALIZE GOOGLE SERVICES ---
$client = new Google\Client();
$client->setAuthConfig($googleServiceAccountFile);
$client->addScope([
'https://www.googleapis.com/auth/siteverification',
'https://www.googleapis.com/auth/webmasters'
]);
$verificationService = new Google\Service\SiteVerification($client);
$searchConsoleService = new Google\Service\SearchConsole($client);
// --- STEP 1: FETCH DOMAINS FROM HOSTINGER ---
echo "Fetching domain list from Hostinger...\n";
$ch = curl_init('https://developers.hostinger.com/api/domains/v1/portfolio');
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Authorization: Bearer $hostingerApiToken",
"Accept: application/json"
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$domainData = json_decode($response, true);
curl_close($ch);
if (!isset($domainData['data'])) {
die("Failed to fetch domains. Check your Hostinger API token.\n");
}
// Extract domain names into an array
$domains = array_map(fn($item) => $item['domain'], $domainData['data']);
echo "Found " . count($domains) . " domains.\n\n";
// --- STEP 2: LOOP AND VERIFY ---
foreach ($domains as $domain) {
try {
$siteUrl = "https://{$domain}/";
// Adjust this path logic to match how your folders are named
$webRoot = $baseWebPath . $domain . "/public_html/";
// A. Get Token from Google
$tokenRequest = new Google\Service\SiteVerification\SiteVerificationWebResourceGettokenRequest();
$site = new Google\Service\SiteVerification\SiteVerificationWebResourceGettokenRequestSite();
$site->setIdentifier($siteUrl);
$site->setType('SITE');
$tokenRequest->setSite($site);
$tokenRequest->setVerificationMethod('FILE');
$tokenResponse = $verificationService->webresource->getToken($tokenRequest);
$tokenString = $tokenResponse->getToken(); // format: "google-site-verification: google123.html"
// B. Write File to VPS
$filename = trim(explode(': ', $tokenString)[1]);
$filePath = $webRoot . $filename;
if (!is_dir($webRoot)) {
echo "Skipping $domain: Directory $webRoot does not exist.\n";
continue;
}
if (file_put_contents($filePath, $tokenString)) {
echo "Uploaded verification file to $domain\n";
} else {
throw new Exception("Permission denied writing to $webRoot");
}
// C. Verify Ownership
$insertRequest = new Google\Service\SiteVerification\SiteVerificationWebResource();
$siteResource = new Google\Service\SiteVerification\SiteVerificationWebResourceSite();
$siteResource->setIdentifier($siteUrl);
$siteResource->setType('SITE');
$insertRequest->setSite($siteResource);
$verificationService->webresource->insert('FILE', $insertRequest);
echo "Verified $domain with Google\n";
// D. Add to Search Console
$searchConsoleService->sites->add($siteUrl);
echo "Successfully added $domain to Search Console\n\n";
} catch (Exception $e) {
echo "Error on $domain: " . $e->getMessage() . "\n";
}
}

Tips for your VPS setup:

  • Path Naming: My script assumes folders are named exactly like the domain (e.g., example.com). If your folders use a different convention, adjust the $webRoot line.
  • File Owner: Since you mentioned creating pages in HTML/PHP, ensure the user running this script has sudo or write access to those directories. You can run the script as the web user: sudo -u www-data php script.php.
  • Rate Limits: Hostinger and Google both have rate limits. With 50 domains, you are well within the safe zone, but adding a usleep(500000); (half-second) at the end of the loop can prevent any “Too Many Requests” errors.

Discover more from NathanLegakis.com

Subscribe to get the latest posts sent to your email.

Leave a Reply

Discover more from NathanLegakis.com

Subscribe now to keep reading and get access to the full archive.

Continue reading