Pre/Post Installation Scripts for Plesk
If you want to execute some scripts before or after Plesk installation, type or paste them into the Pre-installation script and Post-installation script fields respectively when creating Plesk configuration. The option enables pre-post hooks upon Plesk deployment. Pre-installation script is run before invoking Plesk installer. Post-installation script is run after Plesk has been installed, configured, and the license has been installed (if integration with licensing system is enabled). A full list of installation steps can be seen in the Customer Control Panel.
Note: Pre- and post-installation scripts are run with administrative privileges.
See code sample how to deploy the application in Plesk once the installation has been done.
For Linux Plesk installation it can be any script, the only requirement is the first line must have the path to interpreter of the script. Look on the first line #!/usr/bin/php
in the example 1.
Example 1. Installing WordPress package in Plesk in the post-script of Linux Plesk installation:
#!/usr/bin/php <?php $url = "https://127.0.0.1:8443/enterprise/control/agent.php"; $key = exec("/usr/local/psa/bin/secret_key --create -ip-address 127.0.0.1 -description \"test\""); $headers = array("KEY: {$key}", "Content-Type: text/xml"); $ch = curl_init(); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_INTERFACE, "127.0.0.1"); $packet = <<<EOP <?xml version="1.0" encoding="UTF-8"?> <packet version="1.6.2.0"> <aps> <download-package> <package> <name>WordPress</name> </package> </download-package> </aps> </packet> EOP; curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $packet); $retval = curl_exec($ch); curl_close($ch);
For Windows Plesk installation it can be a Windows batch script. In the example 2, we are calling Plesk utility to create a user. The scripts are run in VM, where Plesk is installed, so you don’t need to pass any context.
Example 2. Creating a user in Windows Plesk installation:
"%programfiles(x86)%\Parallels\Plesk\bin\user" --create mary@example.com -owner admin -passwd Sample123 -cname Mary -role webmaster