Using cpanel UAPI in from my php
Hi,
I've been searching for a way to create a subdomain from my php file possibly using a cpanel api. I'm sorry icould not locate a UAPI php library or the UAPI function in the cpanel documentation. Also I tried to use the method described in the below post
My problem when using the above library is that I'm getting access denied error. I've correctly given my cpanel username & password but still getting the error.
Could you please help me find a resolution. If the above library is outdated, could you redirect me to the latest UAPI usage example through PHP.
I'm using shared hosting.
Error as below: (example used for creating a database)
Client error: `POST
-
The function you're looking for is UAPI Functions - SubDomain::addsubdomain - Developer Documentation - cPanel Documentation I"m not sure why you wouldn't have been able to find this in the API documentation. I wouldn't suggest using 3rd party sites to get this information do you get the same result from the UAPI function? If so you may need to contact the provider to find out if there is some access that needs to be provided to you. 0 -
Thanks for the reply. Can this function directly declared in the php file without any libraries. Also could you plesse elaborate the first line as mention in the documentation $cpanel = new CPANEL(); // Connect to cPanel - only do this once.
Do we need to provide the connection details in the CPANEL() function eg: server, username, password Documentation doesn't mention this specifically. Sorry, I'm novice into using UAPI.0 -
Hey @theveil LiveAPI should help you achieve what you need to do if it is running locally on the server: Guide to the LiveAPI System - PHP Class - Developer Documentation - cPanel Documentation 0 -
Hey @cPanelTJ , Thanks for turning up. I have two question for you. I feel my previous question was not well answered. - Regarding the usage and declaration of the UAPI function directly in the php file. I'm still not clear on how this is achieved. Documentation do not state how the function connects to the cpanel (server, username,password etc...). I have tried copy paste the function as given in the documentation as there is nothing needed to customise othere than providing subdomain name and domain name. It didn't work.
- Regarding LiveAPI.
// Instantiate the CPANEL object.require_once "/usr/local/cpanel/php/cpanel.php";
I could not locate the file cpanel.php in my cpanel directory in the server.Can I still use the function? Also /usr/local/cpanel/php/cpanel.php, Is this the actual file path or should i need to check and make changes if necessary.
0 -
If you are running locally and therefore using LiveAPI PHP, then the API will be run for the account that executes the file. Server and username at that point do not need to be explicitly defined. I am assuming from the information you provided that you are a cPanel-level user, but let me know if you aren't. The LiveAPI PHP would look something like: [CODE=php]uapi( 'Subdomain', 'addsubdomain', array( 'domain' => 'mysubdomain', 'rootdomain' => 'mydomain.com', ) ); ?> 0 -
I have the same problem. Even this doesn't work :
Even the echo line did'n't process, just a blank page. It looks like the require once command cannot access the file. Should we place the cpanel.php in an other directory? The lowest directory I can access is the "/home/" directory Any help would be very appreciated.0 -
Hi @theveil and @Marcel Horsthuis Are you following the guidelines of the LiveAPI system? (source: instantiate the respective class's object. - File names must end with the appropriate file extension:
- PHP " .livephp or .live.php
- Perl " .livepl or .live.pl
- Ruby " .liverb or .live.rb
- Python " .livepy or .live.py
- CGI " .livecgi or .live.cgi
- Files, or symlinks to the relevant files, must exist in the /usr/local/cpanel/base/frontend/theme/ directory, where theme is the cPanel theme (paper_lantern or another valid theme on the server).
0 - File names must end with the appropriate file extension:
-
Hi @cPanelIT Thank you for pointing to this part of the documentation. I have done the steps described in the documentation. I made a test.live.php file and located it in the /usr/local/cpanel/base/frontend/paper_lantern/ directory How to link to this file in a php file in the public_html directory or via an url. Thanks in advance. 0 -
I'm not sure if linking from public_html, but in general the full path is: https://:2083/cpsess/frontend/paper_lantern//.live.php
. Most links within cPanel just use/frontend/paper_lantern//.live.php
.0 -
Thank you for the link I now get the error : Cannot find file cpanel.livephpChild failed to make LIVEAPI connection to cPanel. Any ideas? 0
Please sign in to leave a comment.
Comments
10 comments