139 lines
2.9 KiB
Markdown
139 lines
2.9 KiB
Markdown
# 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:**
|
|
```bash
|
|
sudo apt-get install libssh2-1-dev
|
|
sudo pecl install ssh2
|
|
sudo systemctl restart php
|
|
```
|
|
|
|
**CentOS/RHEL:**
|
|
```bash
|
|
sudo yum install libssh2-devel
|
|
sudo pecl install ssh2
|
|
sudo systemctl restart php
|
|
```
|
|
|
|
**Verify installation:**
|
|
```bash
|
|
php -m | grep ssh2
|
|
```
|
|
|
|
## Configuration
|
|
|
|
Edit `plesk-subscriptions.php` and update the `$servers` array:
|
|
|
|
```php
|
|
$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:
|
|
|
|
1. Generate SSH keys (if you don't have them):
|
|
```bash
|
|
ssh-keygen -t rsa -b 4096
|
|
```
|
|
|
|
2. Copy public key to each Plesk server:
|
|
```bash
|
|
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
|
|
```
|
|
|
|
3. Update config in `plesk-subscriptions.php`:
|
|
```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
|
|
|
|
```bash
|
|
php plesk-subscriptions.php
|
|
```
|
|
|
|
## Output
|
|
|
|
The script generates `subscriptions.json` with the following structure:
|
|
|
|
```json
|
|
{
|
|
"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
|
|
```bash
|
|
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
|