Impossible to access OVH API from Symfony command online - php

Here is my problem: I'm developing a Symfony project which accesses telephony and email data from OVH API. Since I'm working in local, I've never met any problems, the API connection was working and I could recover all data.
Yesterday I deployed my project online on an OVH hosting, and when I launch a command from the SSH panel, I get cURL error 7.
The problem doesn't come from the API because I call it in my Controller and I don't get any errors.
My command is :
(php/5.6/production/) ~/www $ php bin/console converseo:updateTelephony
And the error I get :
[GuzzleHttp\Exception\ConnectException]
cURL error 7: Failed to connect to 213.186.33.117: Network is unreachable (
see http://curl.haxx.se/libcurl/c/libcurl-errors.html)
I don't know why this command works on localhost and in my controller, but doesn't work online.

I've got a similar problem in the past with SSH.
I resolved it by creating a CRON task in OVH admin menu. This CRON task call myfile.sh.
Myfile.sh:
#!/bin/bash
cd /home/yourpath
/usr/local/php5.6/bin/php bin/console converseo:updateTelephony
It was ok for me because I needed to execute the command only sometimes in the day. I hope it will helps you.
If you need to launch this command in a specific moment, I think you will need to upgrade your hosting account(vps for example) and type the command directly on the server.

I resolved my problem by putting a PHP file into my www folder, which contains :
<?php
shell_exec("sh myfile.sh");
?>
And myfile.sh :
#!/bin/bash
cd /homez.myNumber/MyNameSite/www
/usr/local/php5.6/bin/php bin/console converseo:MyCommand --env=prod

Related

Executing Php scripts in Airflow worker

I am a newbie to Airflow. I am working on a project , where i need to execute a php script in Airflow worker node.I am using S3 bucket to fetch the said scripts , but when i trigger them using bash command , I get php command not found error.Also there is no operator to execute php scripts like the PythonOperator
{things I've tried so far but didn't work}:
tried installing php compiler/interpreter -> you need root privileges error
tried the same using sudo -> sudo command not found error
P.S. tbh I very close to punching my monitor , plwease help!!

Php exec returns unexpected result while direct call of command in terminal returns correct result (Laravel is used)

Can't solve the problem.
Briefly: I need to execute command on remote server via ssh.
I have two PCs from where I do that job. Ubuntu server - no problem. But from FreeBSD - problem.
Target server is under Freebsd too.
Access is via ssh keys, user - root. In my client Freebsd I can do ssh root#x.x.x.x without any password, so we make conclusion that this part is ok. Next. I run php artisan tinker (for those who don't know what is this - this is terminal for executing php code). There I do:
exec("ssh root#x.x.x.x whoami");
And I get 'root'. Work is correct. But I do the same via
dd(exec("ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -v root#x.x.x.x 2>&1"));
and I get:
"Permission denied (publickey,keyboard-interactive)."
For that command:
dd(exec("ssh -v root#91.222.216.24 whoami 2>&1"));
I get:
"Host key verification failed."
As I understand the only way is to use password, but why key auth fails?
How to fix that?
I've tried many options (read many articles on stackoverflow) and in some combination of code I've found that it looks like when command executed via exec another user (www) is used, not root. And I got errors like:
Could not create directory '/nonexistent/.ssh'.
As I understand the problem connected to user and its permissions. And it looks like there is no any user at all when sshing via exec.
Upd.
Right in terminal on client PC
php -r "echo(exec('whoami'));"
gives. 'root'.
But the same inside of controller in Laravel while using php exec
dd(exec('whoami'));
gives 'www'.
For some reasons in php (exec command) different user is used.
And yes, in Ubuntu, where I have no problems, I get the same user in both cases (I've checked just now), that's why everything is working there. So,.. the question is How to create ssh keys for another user, which is 'www' or should I change somehow user for php?

OpenTok learning-open-tok issue

I've been following the steps at this link: https://github.com/opentok/learning-opentok-php, and I can't get past the first step because I don't understand what I have to do on this part:
The run-demo file starts the PHP CLI development server (requires PHP >= 5.4) on port 8080. If you want to run your server on another port, edit the file. Finally, start the server using the run-demo script.
And then when i actually run the run-demo script and follow the link: http://localhost:8080/session i get this message on screen "You must run composer install in the sample app directory", and if i try to run the composer it doesent run.

Git pull “permission denied” when using shell_exec in PHP

I'm trying to make a hook on bitbucket, that executes a php file, and this file executes the pull command:
shell_exec('/usr/local/cpanel/3rdparty/bin/git pull');
The pull command works fine on the SSH console, but the PHP returns the error:
Permission denied (publickey). fatal: Could not read from remote
repository.
Please make sure you have the correct access rights and the repository
exists.
The command --version shows the path to git is right, whoiami returns the same user on both, so I don't know if it is a permission issue.
What can be going wrong?
Edit: An additional issue: the alias I added for git don't work on PHP, only the full path as above. Via terminal it works just fine. Maybe it's the same reason why the key don't work in php.
Edit 2: $PATH is different on both.
When you run this command within a PHP script you are not running the command as yourself:
shell_exec('/usr/local/cpanel/3rdparty/bin/git pull');
The reason it works from the terminal console is you run the command as yourself from the console. But on a web server, you are not the user running the command. Remember: When you run PHP on a web server, it is a an Apache module. Meaning the web server user—which could be www-data, root or even apache on some systems—is running the PHP script which then runs the shell_exec command.
So it would never work as you have it setup. Perhaps you can kludge something together that would allow a key-pair to be used by the web server for these purposes, but that seems like a security risk waiting to happen.

Where to start with running a command line in PHP with CPanel hosting

I'm having a look at some PayPal scripts/code examples and a lot of them need a php script running via the command line.
I've never had to run anything from a command line in PHP before so don't know where to start at all. I don't know if I'm using the correct search terms as Google hasn't helped me answer.
Do I need to use a different application or is there something in cPanel I can use?
I get this error:
INSTALLATION ERROR: Please cd to the /home/site_name/public_html/site and run install.php
Use SSH to access the server via the terminal:
http://docs.cpanel.net/twiki/bin/view/11_30/CpanelDocs/ShellAccess
There's instructions on how to connect via PuTTY, then you can go to the directory where the PHP script is run it like:
php myPHPScript.php
If your cPanel has the option to turn on SSH, do it. Then SSH into the server and run the commands -
cd /home/site_name/public_html/site
php install.php

Categories