• Our team is looking to connect with folks who use email services provided by Plesk, or a premium service. If you'd like to be part of the discovery process and share your experiences, we invite you to complete this short screening survey. If your responses match the persona we are looking for, you'll receive a link to schedule a call at your convenience. We look forward to hearing from you!
  • We are looking for U.S.-based freelancer or agency working with SEO or WordPress for a quick 30-min interviews to gather feedback on XOVI, a successful German SEO tool we’re looking to launch in the U.S.
    If you qualify and participate, you’ll receive a $30 Amazon gift card as a thank-you. Please apply here. Thanks for helping shape a better SEO product for agencies!
  • The BIND DNS server has already been deprecated and removed from Plesk for Windows.
    If a Plesk for Windows server is still using BIND, the upgrade to Plesk Obsidian 18.0.70 will be unavailable until the administrator switches the DNS server to Microsoft DNS. We strongly recommend transitioning to Microsoft DNS within the next 6 weeks, before the Plesk 18.0.70 release.
  • The Horde component is removed from Plesk Installer. We recommend switching to another webmail software supported in Plesk.

Resolved Rsync in PHP script

CMRP

New Pleskian
Hello,

I have an issue with a PHP script that execute a SH file.

My PHP script :
$output = shell_exec('sh api/fichier_bash.sh');
echo "$output";

My SH file :
#!/bin/bash

/usr/bin/rsync -e ssh -avzru --delete-after /absolute_path/sound.wav root@IP:/absolute path

echo "Hello"

If i go to my php web page, it print "Hello" but the file dosen't send in my remote server.
I didn't see in plesk the sudoers file to give permission for the apache user to execute a rsync command.

Anybody have an idea about this script?

Regards,
CMRP
 
Because i think the rsync command cannot execute by apache user.

How i could execute this command in bach file via php?

NB : if i execute the bash file in root with command line, it works perfectly.

Regards,
CMRP
 
as root:
su - your_apache_user
then cd to the directory of the script and try it
if you get a permission error, put sudo before the rsync
btw, how are you authenticating against the remote server? Do you have the private key in ~your_apache_user/.ssh ?
 
Yes i use a public/private key between the two server.

In fact, i think the sudo module is install by defaut with plesk.
But it's not the case.

Here is the solution :
1) Install sudo (yum install sudo)
2) Add in /etc/sudoers this two line :
your_user ALL = NOPASSWD: /aboslute/path/to/your/bashfile.sh : it's need to authroize php to launch your sh script
your_user ALL = NOPASSWD: /usr/bin/rsync : it's need to authorize php to run this command.

Finally use this in your php script : exec("sudo/path/script.sh)

Thank you for you're help.

Regards,
CMRP
 
Keep in mind though that this completely obliterates the security won by privilege separation as rsync run with root rights can read and overwrite any file on the system.
 
I know but i didn't find other solution.
If you have it, i'm interest.

The sudo file need two thing : the permission to use rsync command and permission to execute the bash file.
In my bash file the path is put in the script and no depend about a variable.

Regards,
CMRP
 
If the script already runs with root rights, there should be no need to enable rsync too. That should only be needed if the script was run as user and had `sudo rsync` in it.

Make sure the script is not writable by the user. Neither the file itself nor the directory (hierarchy).
 
Back
Top