Web Hosting Talk







View Full Version : Shell with PHP (Plesk), help...


Cameleon
04-19-2009, 12:08 AM
I need to use Plesk command line interface to create email account, and need to integrate it with PHP file executed with Apache.

So:

I want to run www.domain.com/create.php and php file need to execute command below

/usr/local/psa/bin/mail --create test@domain.com -mailbox true -passwd ****** -cp-access true -mbox_quota 10M

Is it possible to do ?

tickedon
04-19-2009, 03:41 AM
Yes, it depends on your PHP setup though.

You'll want to look at http://uk3.php.net/manual/en/function.exec.php and http://uk3.php.net/manual/en/function.shell-exec.php, although the functions are often disabled in PHP setups and might need enabling.

praveenkv1988
04-19-2009, 08:45 AM
Use the following functions.

exec() or system()

Cameleon
04-19-2009, 01:47 PM
I did, and i reenabled theem but still they are not executed with plesk command line utilities, some group problems?

Cameleon
04-19-2009, 03:13 PM
below is what i am trying to do:

system('/usr/local/psa/admin/bin/php -q /usr/local/psa/admin/plib/api-cli/mail.php', $output);

echo $output;


I can do many commands with system();
But wheen i try to execute one file it just doesn't work at all, output is 254

would be thankfull for any help;

cselzer
04-19-2009, 03:35 PM
below is what i am trying to do:

system('/usr/local/psa/admin/bin/php -q /usr/local/psa/admin/plib/api-cli/mail.php', $output);

echo $output;


I can do many commands with system();
But wheen i try to execute one file it just doesn't work at all, output is 254

would be thankfull for any help;

try:


$data = shell_exec("/usr/local/psa/admin/bin/php -q /usr/local/psa/admin/plib/api-cli/mail.php");
echo $data;



I'm assuming you're using php-cgi?

Cameleon
04-19-2009, 03:54 PM
nop i am not using php-cgi

yours shell_exec does not show anything :/

sasha
04-19-2009, 04:03 PM
The command you are trying to execute requires root access. In order to do it your webserver would have to run as root (or as some user account with appropriate privileges ). You should not be doing that. Better approach would be that your php script stores data some place safe (text file or event better, database so you can EAS_ENCTYPT that password) and then another script, which is croned to run every minute or so, checks for that data and act based on it.

praveenkv1988
04-19-2009, 04:25 PM
You can also use

exec('/usr/local/psa/admin/bin/php -q /usr/local/psa/admin/plib/api-cli/mail.php');

Run with root.

edboy
04-20-2009, 09:04 AM
I am also attempting to do something exactly like this, I wanted users to register at a website, and have an email address created for them upon registering.

I'm using Plesk 9.0, and want to do it in PHP.

What exactly is this command doing?
exec('/usr/local/psa/admin/bin/php -q /usr/local/psa/admin/plib/api-cli/mail.php');

I was thinking about using a cronjob like sasha mentioned, but wasn't sure which way would be the best.

praveenkv1988
04-20-2009, 11:36 AM
What exactly is this command doing?
exec('/usr/local/psa/admin/bin/php -q /usr/local/psa/admin/plib/api-cli/mail.php');

This is similar to system() and output the result.

Cameleon
04-20-2009, 12:29 PM
edboy we will have to write one script wich sets name+pass and second run by cron to get data from database or file...

runing this with exec, or system just doesnt seem to work anyhow

edboy
04-20-2009, 12:38 PM
This is similar to system() and output the result.

i know what the php is doing, i was just unsure as to what the command inside the "" was doing.

the way i understand it, you can't use the php to actually create the mailbox, you have to call an external command to do this, right?

Cameleon
04-21-2009, 07:40 PM
I don't quite follow you.

This command '' should execute mail.php file and create mailbox, but since mail.php need to be executed by root you can't do exec in this way.

praveenkv1988
04-21-2009, 11:52 PM
The command inside "" will make the file "mail.php" to execute. You can have write codes inside this file which will call the respective APIs for the the account creation.

Or if you know direct command line instructions, You can pass it to system() function.

edboy
04-22-2009, 08:37 AM
Alright, so I've decided to use a cron job to execute a php file.

I was going to set it up so when a user registered, the email address to be created for them went into a "que" and every minute the script would check the database table for new rows, and create the mailboxes.

My cron job looks like this:

/usr/bin/php -q /srv/www/vhosts/mydomain.com/httpdocs/create.php

and to start off I wanted to just create a static email address:

system('/usr/local/psa/bin/mail --create hello@mydomain.com -mailbox true -passwd newpassword', $create);

but my cron job returns an email saying:

sh: /mail: No such file or directory

I'm guessing that I have to change the directory back to /root to get to /usr/local/psa/bin/mail?

any suggestions?

thanks!

sasha
04-22-2009, 10:05 AM
That cron job - it has to run as root user

edboy
04-22-2009, 10:16 AM
That cron job - it has to run as root user

This cron job is running as root user

edboy
04-23-2009, 06:57 PM
Alright well i finally figured it out, so i figured i would share.

create a cron job under root to run:

/usr/bin/php -q /srv/www/vhosts/yourdomain.com/httpdocs/create.php

ssh into your server:
ssh root@yourdomain.com

edit your php.ini file to turn off safe mode so shell_exec() can run:

vi /etc/php5/cli/php.ini

in your create.php file:

shell_exec('/usr/local/psa/bin/mail --create emailaddress@yourdomain.com -mailbox true -passwd newpassword');

should work, worked for me!