owncloud cron execution within docker - php

Im using php-apache image to create an owncloud installation. I want to use a system cronjob to execute cron.php, therefore I run:
RUN echo "*/3 * * * * php -f /var/www/html/cron.php >> /oc_data/cron.log" > /cron.conf \
&& crontab -u www-data /cron.conf
The entrypoint script starts cron with:
cron -f
It gets executed but the owncloud.log shows following message:
"app":"cron","message":"Failed to connect to the database: An exception occured in driver: could not find driver"
Fun thing is, if I enter the docker container and execute the command I use for the cronjob, it works. And php --ini shows all php conf.d extensions including mysql.so and pdo_mysql.so.
I also tried to add the cron.conf file as user root with the same result.
Any ideas, what is happening here?

Please use the correct folder to keep your cron files: "/etc/cron.d/", use COPY to copy the cron file to inside container and "cron -f" in CMD parameter instead ENTRYPOINT.

OK, ALWAYS use absolute paths!!
path of the php command using the bash in the docker container was different to the one cron used.
use which php to get the correct path and add it to the cronjob.

Related

unable to create files from linux library via php

I have an application in php that works on the docker. I would like to send a command from php code to container that should create files (some_dir/certs/cert.crt etc.). This command i run like this (by system/exec/shell_exec or symfony/process)
system("traefik-certs-dumper file --source acme.json --dest some_dir --version v2");
When php run this code then directory has been created but not files, also i don't have any error.
This command works when i make it from terminal via docker exec but not from php. This is probably some permission problem between php and docker container, but i don't know how can i set it.
I'm trying to set in docker file this, but not working:
RUN chmod 777 /go/bin/traefik-certs-dumper
RUN usermod -u 1000 www-data
also standard command works like this:
system("mkdir -p some_dir_1234");
system("touch some_dir_1234/some_file_1234");
How can I allow an installed library to create files?
I finally was able to find a solution. In a separate container, I had a process supervisor running, who saw this file, because it was mounted to the main application directory also. What had to be done was to mount the file to the main container and the supervisor container.
Try
exec("traefik-certs-dumper file --source acme.json --dest some_dir --version v2");
intead of system()

Unable to execute shell script through php shell_exec

I have a binary file whose path is mentioned in the .bashrc file, I am able to execute it through command line. I copied the command to run the binary file into a bash(test.sh) file.
I am trying to execute this test.sh file through Php using the command
<php
shell_exec("test.sh")
?>
This says that command not found.
Maybe, your webserver configuration forbid execution of system commands.
Check your php.ini "disable_functions" section. If you see there something like below, this is the reason.
disable_functions=exec,passthru,shell_exec,system
I'm trying to execute docker command in that runApp.sh file
Remember, you script executes INSIDE docker container. It doesn't have access to the mother system.
If you want to execute docker commands inside docker container, your need docker in docker

How to run laravel cronjob in local linux system?

I have a cronjob with name changeflag. I can use following terminal command to execute this cronjob in local.
php artisan changeflag
In hosting server, I can easily set the execution of console command with cron job.
Is it possible to run above command periodically in local system in Linux automatically as in server ?
or
We have to execute above command through terminal for every test ?
I am using LAMP.
Any help is appreciated.
if you want to add your project's cron jobs in crontab, just add them in crontab file:
change editor to nano (optional)
setenv EDITOR nano
open crontab file
crontab -e
add this line
* * * * * php /path-to-your-project/artisan schedule:run >> /dev/null 2>&1
replace path-to-your-project with the real path and the cron will be executed automatically.
If this doesn't work, replace php with full php path. To find the whole path just type in command line which php.
For more info read the docs

PowerBI CLI node: No such file or directory

I am trying to build PHP wrapper for PowerBI. I installed PowerBI Cli (https://github.com/Microsoft/PowerBI-Cli) on my local and when I run any PowerBI Cli command on my terminal, it is working well. It is working well even when I run the commands using the _www user (sudo -u _www powerbi config)
However, when I run them through PHP using either shell_exec or Symphony's Process Component (https://symfony.com/doc/current/components/process.html), I am getting the following exception:
env: node: No such file or directory.
I am facing this issue on Mac Sierra. The commands are working well on Linux using the PHP exec()
Try linking,
"ln -s /path/where/command/is stored/ /to/path/where u want to exec/"
Sometimes the program are stored in usr/local/bin/program meanwhile as per default you are executing in usr/bin/program
And then in shell use the new path you have set.
Example for linking suppose if you have path for command,
/usr/bin/powerbi then with above command you can link new path usr/powerbi after that you can use new path in exec or shell command.
Try using the full path rather than the command. Without knowing your exact path I can't tell you exactly what to do but it would be something like this:
$output = shell_exec("sudo -u _www /path/path/powerbi config");
var_dump($output);
Edit:
Or, change directories first. So using my example above, it would be:
$output = shell_exec("cd /path/path/powerbi; sudo -u _www powerbi config");

SuiteCRM Database Scheduler

I installed SuiteCRM and while trying to run the code below for for the Scheduler...
php.exe -f cron.php
I get the error:
Call to undefined function mysqli_connect()
Can anyone help?
Have you checked the mysqli PHP extension is installed? try viewing the phpinfo, either from a php phpifno(); or from the command line php -i.
If this wasn't installed it would effect the whole installation rather than just the scheduler.
Looks like your command line PHP ( PHP CLI ) refers to seperte location than your PHP.
Get path of php.ini for your command line and then uncomment this line.
extension=mysqli
The cron.php is run from the scheduler, but sometimes I have to run the code to make sure is working properly.
php cron.php all -F -vvv
where
the “all” command will execute all the tasks
The “-F” option forces all the tasks to be executed.
The “-vvv” option sets the output verbosity level to maximum.
If I need to edit my web server user's crontab file, I use this command:
sudo crontab -e -u username
If I need to find out the username the cron job is running on, I use the browser
domain.com/get_current_user.php
assuming I already created the get_current_user.php file.

Categories