2.9 KiB
2.9 KiB
Plesk Subscription Retriever
PHP script to connect to multiple Plesk servers via SSH and retrieve subscription information.
Requirements
- PHP 7.4+ with SSH2 extension
- SSH access to Plesk servers (root or admin user)
- Plesk CLI tools installed on remote servers (default on Plesk)
Installation
Install PHP SSH2 Extension
Ubuntu/Debian:
sudo apt-get install libssh2-1-dev
sudo pecl install ssh2
sudo systemctl restart php
CentOS/RHEL:
sudo yum install libssh2-devel
sudo pecl install ssh2
sudo systemctl restart php
Verify installation:
php -m | grep ssh2
Configuration
Edit plesk-subscriptions.php and update the $servers array:
$servers = [
'Blue' => [
'host' => 'blue.your-domain.com', // Server hostname or IP
'port' => 22,
'username' => 'root', // SSH username
'password' => 'your_secure_password', // SSH password
],
// ... add other servers
];
Using SSH Keys (Recommended)
For better security, use SSH key authentication:
- Generate SSH keys (if you don't have them):
ssh-keygen -t rsa -b 4096
- Copy public key to each Plesk server:
ssh-copy-id root@blue.your-domain.com
ssh-copy-id root@red.your-domain.com
ssh-copy-id root@purple.your-domain.com
ssh-copy-id root@orange.your-domain.com
- Update config in
plesk-subscriptions.php:
'Blue' => [
'host' => 'blue.your-domain.com',
'port' => 22,
'username' => 'root',
'pubkey_file' => '/home/rob/.ssh/id_rsa.pub',
'privkey_file' => '/home/rob/.ssh/id_rsa',
],
Usage
php plesk-subscriptions.php
Output
The script generates subscriptions.json with the following structure:
{
"generated_at": "2026-03-22T10:30:00+00:00",
"servers": [
{
"server_name": "Blue",
"host": "blue.your-domain.com",
"status": "success",
"error": null,
"subscriptions": [
{
"primary_domain": "example.com",
"additional_domains": ["shop.example.com"],
"aliases": ["www.example.com"]
}
]
}
],
"summary": {
"total_servers": 4,
"successful": 4,
"failed": 0,
"total_subscriptions": 15
}
}
Alternative: Plesk XML-RPC API
If you prefer using the Plesk API instead of SSH, see plesk-api-subscriptions.php.
Troubleshooting
SSH2 extension not found
php -m | grep ssh2
# If nothing shows, install the extension (see Installation section)
Authentication failed
- Verify SSH credentials
- Check SSH key permissions:
chmod 600 ~/.ssh/id_rsa - Ensure SSH access is allowed on the Plesk server
Plesk command not found
- Ensure you're connecting as root or a user with Plesk CLI access
- Verify Plesk is installed at
/usr/local/psa
Connection timeout
- Check firewall rules (port 22)
- Verify the server hostname/IP is correct