Auto Install API

From Softaculous Wiki
Jump to: navigation, search

Overview

If you wish to automate the installation of Scripts using a different software e.g. a billing system like WHMCS you can do that in Softaculous as there is an API Class which enables us to do so.


API Class

You can find the API Class in your Softaculous folder e.g. in cPanel its located here : /usr/local/cpanel/whostmgr/docroot/cgi/softaculous/sdk/installapi.php


Understanding the API

The API is a simple class which will pass the data to Softaculous to install a script. Here is a sample example to install a script :

<?php
 
@set_time_limit(100);
 
$new = new Soft_Install();
$new->login = 'http://user:password@domain.com:2082/frontend/x3/softaculous/index.live.php';
$new->data['softdomain'] = 'domain.com'; // OPTIONAL - By Default the primary domain will be used
$new->data['softdirectory'] = 'folder'; // OPTIONAL - By default it will be installed in the /public_html folder
$new->data['admin_pass'] = 'qwerty';
$new->data['admin_email'] = 'admin@domain.com';
$res = $new->install(26); // Will install WordPress
 
if($res == 'installed'){
	echo 'Installed';
}else{
	echo $res; // A serialized array of error will be returned
}

As you may see this will install WordPress.
Lets go through the Code :

Initializing and Authentication

$new = new Soft_Install();
$new->login = 'http://user:password@domain.com:2082/frontend/x3/softaculous/index.live.php';

This will load the Class in $new and we are setting the LOGIN URL as without authentication you will not be able to access Softaculous. The code here is an example to Auto Install in cPanel. cPanel allows User Authentication via the URL itself and many other panels also.

http://user:password@domain.com:2082

Installing scripts as ROOT

You can install a script for your user as ROOT. You will have to modify your login URL as follows :

$new = new Soft_Install();
$new->login = 'https://user:ROOT_PASSWORD@domain.com:2083/frontend/x3/softaculous/index.live.php';

The above code will allow you to install a script as ROOT for your users.

If your panel has some different method, you must first implement that code and then proceed.

NOTE : This is the URL which is used to install ANY Script. Hence it is very important to install any script.

Dont send emails

If you want no emails to be sent by Softaculous on the installation of a script please pass the &noemail=1& in the login url. e.g :

$new->login = 'http://user:password@domain.com:2082/frontend/x3/softaculous/index.live.php?&noemail=1&';


Data Fields

Softaculous will expect you to submit the data fields as it shows during the installation of Scripts. Now most scripts have common fields like Admin Username and Password and stuff like that. The values that you pass for the fields in this API Call will replace the default ones shown in Softaculous. If you dont specify any field the default value is used by Softaculous.

$new->data['softdomain'] = 'domain.com'; // OPTIONAL - By Default the primary domain will be used
$new->data['softdirectory'] = 'folder'; // OPTIONAL - By default it will be installed in the /public_html folder
$new->data['admin_pass'] = 'qwerty';
$new->data['admin_email'] = 'admin@domain.com';
$res = $new->install(26); // Will install WordPress

The above code is just setting the Domain, Folder to install in, Admin Password and Admin Email.
The field names for each script can be obtained by viewing the SOURCE in the browser while installing a Script in Softaculous.
The line $res = $new->install(26); will start the installation process and $res will have the result that is obtained.


Return Values

if($res == 'installed'){
	echo 'Installed';
}else{
	echo $res; // A serialized array of error will be returned
}

On a successful install $res will have the value installed
On error a SERIALIZED PHP ARRAY is returned with the error details.

Custom Scripts

If you have made Custom Script packages and would like to use this API to install it just copy the cscripts.php from your server and place it next to this file.
Thats it!! You can now install the Custom Scripts.

Overwrite Files

If you wish to install the software even if the files exists you need to uncomment following line in the file installapi.php

$new->data['overwrite_existing'] = true;

Support

You can always ask us if you have any queries. The support department can be accessed from here : https://www.softaculous.net/support/