Executing Php scripts in Airflow worker - php

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!!

Related

OVH CRON: How to execute a Symfony command?

How to execute a Symfony command with OVH cron?
I created a command on my symfony project:
php bin/console cron:test
I defined my Cron in the OVH table "Scheduled Tasks - Cron":
Command: cron/test.sh
Language: Other
test.sh is executable (chmod 700).
In test.sh I do not know what to write.
I tested several code found on the internet without success, including this one (with a php file):
OVH cron jobs / Symfony Command
I am using php 7.1.
What is the logic that applies to find this code? Thanks in advance for the help.
I got my answer. Thank you #Tomasz for your help.
phpinfo() showed me the way.
The solution:
#!/bin/bash
/usr/local/php7.1/bin/php /homez.ovhNumber/myWebsite/symphonyProject/bin/console cron:test
In command field you should be able to enter command you want to execute. But because you don't know from where it will be executed you have to specify full path to command for example:
php /var/www/my-project/bin/console cron:test
But, I'm not familiar with OVH Tools so if you need to create bash file which will be run by cron, then your file should like like this:
#!/bin/bash
php /var/www/my-project/bin/console cron:test
Here is the same principal with the full path to your bin/console file.

Impossible to access OVH API from Symfony command online

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

running a php script using ansible throws errors

I am trying to run a php script on a remote server using ansible.
Running the script with the ansible user (which ansible uses to login to the server) works perfectly. The ansible task however fails when there are include statements in my php script.
My php script lays in /srv/project
it tries to include includes/someLibrary.php
Everything works fine when running the script as any user with the correct access rights but when running it via an ansible task
- name: run script
shell: 'php /srv/project/script.php'
it fails with: failed to open stream: No such file or directory in /srv/project/includes/someLibrary.php
Running a very basic php script works nicely though.
I just found the solution to the problem.
The problem was that when I executed the script by hand, I connected to the server and cd'd into the /srv/project directory before calling php script.php PHPs include in this case looks in the current directory for the files I want to include. When ansible connects to the server it did not change the directory thus producing the no such file or directory error. The solution to this is simple as the shell module takes a chdir as an argument to change the directory to the one specified before running the command.
My ansible task now looks as follows:
- name: run script
shell: 'php /srv/project/script.php'
args:
chdir: '/srv/project'
Thanks everyone for your help!
Ansible runs under a non-interactive ssh session, and thus does not apply user environment settings (eg, .bashrc, .bash_profile). This is typically the cause of different behavior when running interactively vs. not. Check the difference between an interactive printenv and raw: printenv via Ansible, and you'll probably find what needs to be set (via an ansible task/play environment: block) to get things working.

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

using phps exec command to launch an application on the server

I'm attempting to run an application on the server, invoking it from PHP using the following code.
$application = "D:\\Program Files (x86)\\ScanBoy\\DM ScanBoy.exe";
exec($application);
Right now the application is 'run' however it crashes instantly. If I just run the application (by double clicking the exe) it runs and everything is fine.
When the application crashes the only error I get is
"{application name} has stopped working. Windows is checking for a
solution to the problem"
I have had this problem with running application via c# backend to a ASP.NET page. The solution there was to set the Working Directory. However in php / exec I am unaware of how to set this option.
Any help please?
You can either:
Use exec("cd myworkdir/ && D:\\Program Files (x86)\\ScanBoy\\DM ScanBoy.exe"); to change the working directory for that exec command (only)
Use the php chdir() function to change the working directory of the php process.
You can find chdir documentation here:
http://php.net/manual/en/function.chdir.php
You can chdir() to change current working directory

Categories