Unable to execute shell script through php shell_exec - php

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

Related

Link php interpreter from Docker to bash somehow

I'm trying to use my docker php as an interpreter in my terminal. What I need:
I don't keep my dev envs on my host os. That's important to keep it isolated
It should be available as $php or $/usr/bin/env php
I'd like to be able to run something like phpcs in my vim. It requires that thingy above.
I've tried this:
alias php='docker-compose exec php php'
But it's not available through /usr/bin/env
/usr/bin/env tries to locate the executable via the $PATH variable, see https://unix.stackexchange.com/a/12749
So if you put your command in to a script called PHP and add it to your $PATH before other PHP executables, it might work.

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()

Ubuntu 18.04: Unable to create files using an executable which is made to run via a script

Using PHP's system/exec commands to run a script that in-turn makes an executable run, that executable when run directly via terminal generates 2 text files successfully but fails to do so when it is made to run using command in php, which is:
system("bash run.sh");
this run.sh contains command which executes an executable. contents of run.sh are:
#!/bin/bash
./op 2
where op is an executable file, which successfully creates two text files only when run using a terminal.

run php file from shell script in openwrt

I am trying to run a php file from shell script file or terminal in open-wrt platform. I have executed php files in crontab and those are running perfectly. i need to run a php file without putting it into crontab.I am trying it with the following command
chmod 777 /www/api/*
cd /www/api
php myphp.php
but it showing -ash: php: not found
I have also try it putting the following command on top of the script
#!/usr/bin/php
but it is not working. i could not figure out the problem!!!
You must install php-cli package, after you can run the script by
php-cli script.php

PHP shell_exec() SASS --update

I am trying to execute sass --update via PHP shell_exec() function and get an error:
H:\SERVER\htdocs\path\to\project>sass --style compressed --update sass\:deployment\css\ 'sass' is not recognized as an internal or external command, operable program or batch file.
If I run the same command from the cmd manually - it works fine. The current folder is correct - checked with the getcwd()
When you run the command sass in a shell, your computer has to find the executable program called sass somewhere on your computer. To do this, it looks through a series of folders called your PATH. Your PHP server is most likely running with a different PATH than your command prompt, and as such, is not able to find the executable.
To fix this: From your command prompt, where sass DOES work, run this command: which sass (on Windows, instead use where sass)
That will tell you the exact location of sass (for example, it might be /usr/bin/sass or something like that). Once you have that value, replace "sass" in your PHP code with that entire location.

Categories