Create Your First Extension

Prerequisite

To start building Plesk extensions, you need a server with Plesk installed. If you don't have one, install it following the steps here.

Step 1: Create and Install Extension

Plesk extension is a ZIP archive which contains a specifically organized directory structure and a file with meta information describing the software.

Note: If you would like to examine the structure of a dummy extension, check out our "Hello world" sample extension here.

A quick way to create an extension is to call the extension command-line utility (learn more about it here):

plesk bin extension --create hello-world

This call will create the necessary file structure on your Plesk server. All paths are shown after the utility finishes executing:

The extension was successfully created.
The path to extension's entry points: /usr/local/psa/admin/htdocs/modules/hello-world/
The path to PHP classes: /usr/local/psa/admin/plib/modules/hello-world/
The path to installation scripts: /usr/local/psa/admin/plib/modules/hello-world/scripts/
The path to the directory with run-time data: /usr/local/psa/var/modules/hello-world/

Here you can see the paths where the extension files are deployed. Read more about the way extension files are organized here.

After the template structure is deployed, you need to register the extension on the Plesk server using the following command:

plesk bin extension --register hello-world

As a result, the new extension will be displayed in the list of extensions on the Extensions screen of the Plesk user interface:

Framework

Extensions are written in PHP, and their organization uses Zend framework practices to a large extent, for example, the implementation of MVC and forms construction. Although using these practices is not, strictly speaking, required, it is strongly recommended. Because at least some knowledge of PHP is mandatory for writing extensions, we assume that the readers of this document are somewhat familiar with this programming language. If you haven't written PHP applications before, you can still use the document, but you might need to read some PHP-specific topics (which are beyond the document scope) to develop your extension.

Step 2: Implement controller

In the extension template out of the box there is one controller: /usr/local/psa/admin/plib/modules/hello-world/controllers/IndexController.php with template action.

So let's pass some data from controller to view. In our case, we access the currently logged in user using pm_Session:

class IndexController extends pm_Controller_Action
{
	public function indexAction()
	{
		$this->view->name = pm_Session::getClient()->getProperty('pname');
	}
}
Step 3: Implement view

Also, in the extension template out of the box there is view for this sample controller: /usr/local/psa/admin/plib/modules/hello-world/views/scripts/index/index.phtml

It is supposed to display the following message in view:

Hello, <?php echo $this->name; ?>!

You can visit the extension's index page and see that the message is displayed:

Step 4: Pack extension

Before you can start distributing your extension, you need to package it. You can do it using the extension command line utility:

plesk bin extension --pack hello-world

If successful, the output should look like this:

The extension was successfully exported to /root/hello-world-1.0-1.zip

Now you can download this archive.

Step 5: Remove unused files and directories

In scope of the extension template, several features were created just to allow us to start development faster, but not all of them are used. It is recommended to check them and remove those that are not used. In the sample extension, none of the installation scripts are used, so you can remove the plib/scripts directory safely.

Step 6: Add icons and screenshots

To publish an extension in the extension catalog, it needs icons and screenshots (read more about certification requirements here). For this purpose, you need to create the following directories and files:

  • _meta
    • icons
      • 32x32.png - 32x32 pixel icon
      • 64x64.png - 64x64 pixel icon
    • screenshots (up to 3 screenshots, 1024x768 resolution)
      • 1.png
      • 2.png
Step 7: Update the meta file

Before the publication, you need to update the meta file with the correct name, description, vendor name and website address, the supported Plesk version, and so on:

<?xml version="1.0" encoding="UTF-8"?>
<module>
   <id>hello-world</id>
   <name>Hello World extension</name>
   <description>Sample extension to display "Hello, World!"</description>
   <version>1.0</version>
   <release>1</release>
   <vendor>Plesk</vendor>
   <url>https://www.plesk.com</url>
   <plesk_min_version>11.0</plesk_min_version>
</module>

For more details about meta.xml, read here.

Step 8: Pass certification

Now you can send your extension for certification and to be published in the extension catalog. For more information about the publication process, visit: https://ext.plesk.com/help.

 

Leave your feedback on this topic here

If you have questions or need support, please visit the Plesk forum or contact your hosting provider.
The comments below are for feedback on the documentation only. No timely answers or help will be provided.