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.
Related
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.
I am new to php static analyzers and have installed Kahlan via composer on one of my projects as the document instructed.
The document further says, With the Phan dependency installed, you can do analysis by running the following (once you create a configuration file).
./vendor/bin/phan
Now, where do Kahlan wants me to run the above command at?
I went to the window command prompt and enter the ./vendor/bin/phan and the cmd prompt says
'.' is not recognized as an internal or external command,
operable program or batch file.
What are you linking is a PHP script. To be able to run it in windows console, you have to install PHP language interpreter first. Get it on www.php.net
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
Hello i have a PHP script, and its added to cron, it is possible to execute from this script shell command (with exec() or something) without enabling it on php.ini? I don't want to enable exec on my site
It's called PHP CLI, check here
Usually when you install php, there's option to install php_cli too.
So long you can run php on shell prompt, then it can work.
Open bash (or other shell), try this:
php -v
If the version printed, then it's working.
Then you can
php -f phpfile
or put
#!/usr/bin/php
At the beginning of your php file as a line, and chmod +x file.php, and then
./file.php
#or
/path/to/file.php
to run it.
(Note /usr/bin/php is the usual place of php executable, it might change, eg in unix is ually /bin/php. Use whereis php to check its place.)
I'm trying to run composer on windows with wamp. I installed composer using the cmd prompt, and now I'm trying to run "composer update" for an SDK. However, when I type in "composer.phar update," windows asks what app I want to use to run this program. I want the command prompt to deal with it! How do I just run it through cmd, without this "what app" window coming up?
You have to set php.exe as your default application for phar files.
.phar stands for PHP Archive
Usually .phars take some arguments, so they are intended to be run from command prompt. Linux/BSD/OS X shell or Windows command prompt.
Linux .phar use case scenarios assume .phars are copied to some /bin and renamed to be without .phar extension, so you can use a php archive as if you would use any other linux command. So I recommend following way of doing the same thing with Windows:
Put all your .phar files to one directory like C:\php\phars
Add C:\php\phars to system environment variables (right-click my Computer -> Properties -> Advanced System Settings -> Environment variables)
Start the elevated command prompt (find command prompt in start menu then right-click and select Run as Administrator)
Type the following commands, replacing the path C:\phpdev\php\php542\php.exe with full path to your PHP executable:
ftype PHARFile=C:\phpdev\php\php542\php.exe "%1" %*
assoc .phar=PHARFile
set PATHEXT=%PATHEXT%;.PHAR
Next time your should be able just to run Windows console (keyboard Win+R and type cmd.exe) and type any of your .phar's like apigen.phar followed by any command and it will work
C:\Users\acosonic>apigen.phar help
Usage:
...
Arguments:
command The command to execute
command_name The command name (default: "help")
Options:
--xml To output help as XML
--format To output help in other formats (default: "txt")
--raw To output raw command help
--help (-h) Display this help message.
--quiet (-q) Do not output any message.
--version (-V) Display this application version.
Help:
The help command displays help for a given command:
php C:\phpdev\phars\apigen.phar help list
You can also output the help in other formats by using the --format option:
php C:\phpdev\phars\apigen.phar help --format=xml list
To display the list of available commands, please use the list command.
C:\Users\acosonic>
So this way lets you run .phar archives in a directory where you need to work, for example generating documentation in C:\myproject\controller without specifying full path to .phar as if you would if it's run without adding it to Windows path.
To explain what commands in step 4 did:
Created mapping HKCR.phar → HKCR\PHARFile
Created HKCR\PHARFile\shell\open\command = 'php.exe "%1" %*' [REG_EXPAND_SZ]
Extended HKCU\Environment\PATHEXT = '%PATHEXT%;.PHAR' [REG_EXPAND_SZ]
*.phar gets treated like binary/script, and *.phar execution works as long as a *.phar file is located anywhere in %PATH%.
One can wrap php *.phar with *.bat, then the filename will be the name of the CLI command:
#ECHO OFF
php "C:/Program Files/PHAR/phpDocumentor.phar" %*
One can also use such a wrap to pass along default arguments; eg. wp.bat:
#ECHO OFF
php "C:/Program Files/PHAR/wp-cli.phar" --path="D:/SDK/wordpress" %*
Where pattern %* will capture and forward CLI arguments, as it is supposed to.
Alike this one can run phar alike any other CLI command, in a terminal window.
Keep it simple. Instead of changing .phar's default program, which is not always easy in Windows, try just typing "php" in front of your command.
php composer.phar update