Useful CLI Commands for Plesk
Subscription/Site Management
Domain Aliases
To create a domain alias that only redirects to the main domain without creating
a new site, use the following domalias command:
plesk bin domalias --create aliasdomain.net -domain maindomain.net
See domalias: Domain Aliases for more information.
Sync PHP settings/hosting settings with the service plan
Symptoms
PHP settings or hosting settings defined in a Service Plan are not changed for subscription after successful synchronization with the service plan
Cause
Permissions Hosting settings management and Common PHP settings management are enabled in the service plan. According to Plesk documentation, Hosting settings management option allows owner managing subscription's web hosting settings. If this permission is granted, then the hosting parameters will not be synced. This means that PHP or Hosting settings on the subscription level have higher priority than on the service plan level.
Resolution
To make PHP settings to be synced with ones specified in the service plan:
- Login into Plesk and navigate to Service Plans > service_plan_name > Permissions tab
- Uncheck Hosting settings management, Common PHP settings management and PHP version and handler management

User Management
Create an Additional Administrator
PSA_PASSWORD="$password" plesk bin admin_alias \
--create $username \
-passwd '' \
-contact "$display_name" \
-comment "$comment" \
-email "$email"
See admin_alias: Additional Administrator Accounts for more information.
Server Configuration
Disable TLSv1 and TLSv1.1
# /usr/local/psa/bin/server_pref -s | grep ssl-protocols
ssl-protocols: TLSv1 TLSv1.1 TLSv1.2 TLSv1.3
/usr/local/psa/bin/server_pref -u -ssl-protocols "TLSv1.2 TLSv1.3"
# /usr/local/psa/bin/server_pref -s | grep ssl-protocols
ssl-protocols: TLSv1.2 TLSv1.3
## Other Commands
### Fail2Ban Management
```bash
# Show list of trusted IPs
plesk bin ip_ban -t
# Add additional IPs to the trusted list
plesk bin ip_ban --add-trusted "1.2.3.4 5.6.7.8 9.10.11.12"
# Show list of banned IPs
plesk bin ip_ban -b
# Unban an IP
plesk bin ip_ban --unban 1.2.3.4
See ip_ban: IP Address Banning (Fail2Ban) for more information.
Domain Management
Add www subdomain alias
To add a www variant (e.g.,
plesk bin domalias --create www.sub.example.net -domain sub.example.net
Update PHP-Handler for a subdomain or all subdomain
for site in $(plesk bin site --list); do
plesk bin site -u $site -php_handler_id plesk-php84-fpm-dedicated;
done
Redirect www to non-www
if ($host ~ ^www\.(.+)$) {
return 301 $scheme://$1$request_uri;
}
How to update the "Additional Nginx/Apache directives" field of all/several
domains in Plesk
Domain's additional Nginx/Apache directives are saved in files located in /var/www/vhosts/system/$fqdn/conf/:
vhost_nginx.conf: Additional Nginx directivesvhost_ssl.conf: Additional Apache directives for HTTPSvhost.conf: Additional Apache directives for HTTP
Just overwrite the files needed. Then, the subdomain/domain needs to be reconfigured and the respective webserver needs a reload of its config:
for domain in sub.example.org sub-r.example.org; do
install directive_template.conf -o root -g nginx -m 600 "/var/www/vhosts/system/${domain}/conf/vhost_nginx.conf"
plesk sbin httpdmng --reconfigure-domain "${domain}" -no-restart
done
service nginx reload
Maintenance Tasks
How to backup MariaDB databases via CLI
To find databases and dump it:
/usr/sbin/plesk db -e "show databases" | grep -v -E "^Database|information_schema|performance_schema|phpmyadmin|mysql|psa|roundcubemail|sys|apsc"
plesk db dump dbname > dbname.sql
To restore a dump:
MYSQL_PWD=`cat /etc/psa/.psa.shadow` mariadb -u admin < dbname.sql