Plesk bin site error when creating a domain from bash script - php

Im having an issue creating a domain on plesk, this command works fine when run through cli:
plesk bin site --create newdomain.com -webspace-name existingdomain.com -www-root /httpdocs
But when I add the same code above to a bash script (create_domain.sh) and try to run it with:
sudo bash create_domain.sh
I get the following error
An error occurred during domain creation: hosting update is failed: cObject->update() failed: Some fields are empty or contain an improper value. ('www_root' = ')
Anyone knows why this is happening?

This was because I was using windows to edit the bash file, I deleted it and rewrote it in nano and it worked

Related

shell_exec not working with ssh command in virtual machine

I have a script PHP that this has a command ssh with ls -la to list the files and directories. But when I run the script, it returns me error code 255 in addition to the following error message:
Could not create directory '/usr/sbin/.ssh'. ssh_askpass: exec(/usr/bin/ssh-`askpass): No such file or directory Host key verification failed.`
When I use sudo on the ssh command, it returns me another error, being the following:
sudo: no tty present and no askpass program specified
The authentication key is already inside the know_hosts file and when I run the same command inside the terminal, connecting via ssh, everything works perfectly. The key is inside the Downloads folder and her permission is 0644. I've tried several possible solutions, but none have been able to help me solve the problem.
Here is the code used:
$oldldpath = getenv('LD_LIBRARY_PATH');
putenv("LD_LIBRARY_PATH=");
var_dump(shell_exec("ssh -i $key_file user#ip \"ls -la ~\" 2>&1"));
putenv("LD_LIBRARY_PATH=$oldldpath");
Editing - Correcting a part of the problem
The problem Could not create directory '/usr/sbin/.ssh' has been fixed from the creation of the .ssh folder inside /usr/sbin. Now, when the script runs again, it returns the rest of the problem, which is as follows:
ssh_askpass: exec(/usr/bin/ssh-askpass): No such file or directory Host key verification failed.
Edit 2:
The above error was corrected with the installation of ssh_askpass, from the following code below:
sudo apt-get install ssh-askpass
However, after the corrections on the described errors, another error was generated, being the following:
No protocol specified Error: Can't open display: :0.0 Host key verification failed.

Copy remote file with rsync in php

I'm trying to execute with PHP a command (rsync) to copy folders and files from a remote server to a local folder.
This is the code I wrote in php. Command WORKS in SSH (local Terminal and remote with putty.exe), copying correctly the folders and the files.
But it doesn't work in PHP. What can I do? Do you know a better(secure/optimal) way to do this?
exec("echo superuserpassword | sudo -S sshpass -p 'sshremoteserverpassword' rsync -rvogp --chmod=ugo=rwX --chown=ftpuser:ftpuser -e ssh remoteserveruser#remoteserver.com:/path/files/folder /opt/lampp/htdocs/dowloadedfiles/", $output, $exit_code);
EDIT:
I had read this guide to create a link between my server and my local machine.
Now I can login with ssh in my remote machine without password.
I changed my command:
rsync -crahvP --chmod=ugo=rwX --chown=ftpuser:ftpuser remote.com:/path/to/remote/files /path/to/local/files/
This command works too in terminal, but when I send it with exec php command, it fails again, but I got another different error: 127.
As MarcoS told in his answer, I checked the error_log.
The messages are this:
ssh: relocation error: ssh: symbol EVP_des_cbc, version OPENSSL_1.0.0 not defined in file libcrypto.so.1.0.0 with link time reference
rsync: connection unexpectedly closed (0 bytes received so far) [Receiver]
rsync error: remote command not found (code 127) at io.c(226) [Receiver=3.1.1]
Well, after lot of try/error, I finished to cut the problem in the root:
I readed this guide (like the last one, but better explained) and I changed the php file that execute the rsync command to the remote server (where files are located) and run the rsync.php file there, and it worked perfectly.
To execute in the machine with the files (the files to copy and the rsync.php)
1.- ssh-keygen generates keys
ssh-keygen
Enter an empty passphrase and repeat empty passphrase again.
2.- ssh-copy-id copies public key to remote host
ssh-copy-id -i ~/.ssh/id_rsa.pub remoteserveraddressip(xxx.xxx.xxx.xxx)
The rsync.php file:
exec("rsync -crahvP /path/in/local/files/foldertocopy remoteuser#remoteserveraddress:/path/in/remote/destinationfolder/", $output, $exit_code);
After all of that, navigate to the rsync.php file and all must work. At least worked for me...
I suppose you are experiencing identity problems... :-)
On a cli, you are running the command as the logged-in user.
On PHP, you are running the command as the user your web server runs as (for example, apache often runs as www-data, or apache user...).
One possible solution I see (if the above is the problem real cause), is to add your user to web-server group...
I'd also suggest you to check the web-server error logs, to be sure about the real cause of the problem... :-)

CentOS Linux console command versus PHP exec(command)

I have a C program that I wrote called convert3to5, originally written for CentOS / Fedora 32bit system in early 2010. I am moving it to new CentOS 6.x 64bit system host.
From a CentOS Putty console I can run the convert3to5 command just fine; here is a sample of it running from my console:
[root#cloud convert3to5]# ls
CircleStar convert3to5 Convert3To5.txt test.tif
[root#cloud convert3to5]# ./convert3to5 /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif
TIFFReadDirectory: Warning, /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif: wrong data type 7 for "RichTIFFIPTC"; tag ignored. Image has an undefined fillorder - using default: MSB2LSB
The above is a normal completion of convert3to5 and I get a SV-DIS160217B.bmp that is placed in /var/www/webadmin/data/www/mydomain.com/uploads/ So running it from console works fine.
Question - I am attempting to run the same exact command from PHP using the exec(command, output, return) command as follows:
chdir($sv_path.$c3to5_path); //change our working directory to "/convert3to5" directory
$command = "./convert3to5 $targetFile 2>&1";
$result = exec($command, $output, $return);
// the output of the above command - is a .bmp file it will be placed in the same path as the input .tif file
I get the following $result:
ERROR: Unable to convert
/var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif to 5
color BMP file: Open file Error: Tiff_3_to_BMP_5_.lut!
My convert3to5 does need to open Tiff_3_to_BMP_5_.lut
Why does it find Tiff_3_to_BMP_5_.lut when I run convert3to5 from a console prompt but not from PHP exec(...) in both cases my pwd shows that I am in
[root#cloud convert3to5]# pwd
/var/www/webadmin/data/www/mydomain.com/myView/convert3to5
I have also verified pwd is correct from my PHP script after the
chdir($sv_path.$c3to5_path);
Tiff_3_to_BMP_5_.lut is in CircleStar directory - the path to CircleStar is /var/www/webadmin/data/www/mydomain.com/myView/convert3to5/CircleStar
Summary: ./convert3to5 works while PHP exec('convert3to5 ..) does not appear to work.
Can anyone suggest the difference and how to fix and/or debug?
Thanks
You're running the console from the convert3to5 directory, and I suspect your old C program used a relative path to the .lut file, possible relative to the .tif?
What if in the console example you did
cd ../..
./path/to/convert3to5/convert3to5 /var/www/webadmin/data/www/mydomain.com/uploads/SV-DIS160217B.tif
Might be related to $targetFile. Print that and see if it's the full path.
Finally, run
/full/path/to/convert3to5 fullTargetPath
If that works, then as a workaround, if you just do exec('/full/path/to/convert3to5 $fullTargetPath, ..) it should behave like the console.
Per my above comment to wonton:
From the console I was running as root (so fully privileged). I supposed my PHP script will run as the "apache" user on the server?
Here was the problem I believe: I looked at the CircleStar directory privileges where the Tiff_3_to_BMP_5_.lut file exists. CircleStar had rw-r--r-- (0644) when running as root from console this allowed my convert3to5 program to find and open Tiff_3_to_BMP_5_.lut file just fine. However not the PHP exec(...) once I changed the privilege on CircleStar to rwxr-xr-x (0755) PHP exec(...) ran fine!
So ultimately it was a permission issue.

PHP / Apache sh error permission denied on every request

I've got a recently setup server which is running Apache and PHP 5.3.9, every request made to the server results in an error in the error log file:
sh: line 0: cd: /root: Permission denied
The error is happening before any PHP code is executed so it must be something in the setup somewhere but it's a new box and is running a stock configuration.
What would cause this error?
EDIT:
Running on Amazon Linux (EC2) 2.6.35.14-97.44.amzn1.x86_64
It shouldn't be running any scripts, it's running PHP in mod_php mode, not CGI and the error is happening before and PHP code is executed
Could look like a script that does not have executable rights.
If you know which script it is, you can give it the rights by:
chmod +x /path/to/your/script.sh
As root or with sudo infront.
Edit:
Looking agin, it looks like your script is trying to cd to your /root folder.
Most likely the script is run by another user which does not have permission to cd to /root.
Only root has that
This is the AWSSDKforPHP doing this.
Inside /usr/share/pear/AWSSDKforPHP/sdk.class.php you will find:
$_ENV['HOME'] = `cd ~ && pwd`;
For some silly reason, it's trying to "cd" into /root. Change that line to the following:
$_ENV['HOME'] = "/var/www"; #`cd ~ && pwd`;
And it will go away.

gpg encryption failed: file open error

I have been going nuts with this..
I have gnupg installed on my CentOS server and I try to encrypt uploaded files (uploaded via a PHP page). On the server via the command line, it works perfectly. But via the php script, it fails with this error:
gpg: /path-to-my-file/my-file: encryption failed: file open error
The user apache (which I think is used to run the exec command) has read/write in the directory of the file.
The file is uploaded fine (I can see it afterward as I removed the deletion of the unencrypted file from my code) and can be deleted correctly via the php site.
the command I run is the following
/path-to-gpg/gpg --homedir=/path-to-my-home-gnupg/.gnupg -e -r therecipient#email the-unencrypted-file
Any idea how I could tackle this?
thanks
A few things to check:
Run system("ls " . escapeshellarg($file)) and check the result — is it file not found? Permission denied? That will help you debug.
Run system("whoami") to make sure PHP is running as who you think it is.
Run echo "<pre>ls " . escapeshellarg($file) . "</pre>" then copy+paste the command and run it from the shell to make sure that the path to the file is what you expected it to be.
Also, I believe CentOS runs SELinux by default… If you've got it installed, check the logs (in /var/log/) to see if SELinux is preventing Apache from executing GPG.
Try running the command with actual apache user privileges in verbose mode:
su apache -c /path-to-gpg/gpg -vv ...

Categories