PHP run curl with exec not working - php

When I run my curl command in the command prompt it works fine, but
when I run it in my PHP file using exec it doesn't execute, can
somebody tell me why that is ? In the error log file it says,
"'curl' is not recognized as an internal or external command "
I checked my php configurations, curl is enabled there.

From what you write I guess you use windows so:
It can be executed from cmd.exe when you are exact directory where curl is installed but as other suggested if you want to have access to it globally you will need add curl.exe to your PATH variable.
Despite this, there is better way to use CURL in PHP than using exec. A whole module is available. You can go to this site and check it. To install php curl on windows you'll probably need to install an extension.
Notice from manual:
In order to enable this module on a Windows environment, libeay32.dll and ssleay32.dll must be present in your PATH. You don't need libcurl.dll from the cURL site.
Check this site as well.
Good luck

you probably do not have the path set. Set the environment path (add curl executable bin to the path) and then restart the command prompt. it should work

In your PHP script,
either use the full path to curl (which you can find out using which curl on the commandline),
or use the cURL API that is available in PHP. This is the preferred method because not all hosts have exec enabled for PHP.

Related

VsCode php.validate.executablePath, after insalled XAMPP

i'm trying to set the certain path for the php extension in my vscode (using linux)
i started installing the XAMPP
and after it..i tried to use the extension writing some php scripts(php extension INTELLISENSE and DEBUG), but the extension is not working properly and it's showing that error:
Cannot validate since /usr/bin/php is not a valid php executable. Use the setting 'php.validate.executablePath' to configure the PHP executable.
i tried to set it using que path which is provided by vscode documentation, but it's still no working.
Can anyone help me !! please!!!
I found a solution, typing in terminal
'whereis php'
that returns the absolute path for set it in the vscode extension
/opt/lampp/bin/php
Then, setting the path in the follow line
php.validate.executablePath: "/opt/lampp/bin/php",
So, I hope this solution is helping someone behind the screen.
Php path in windows
Typing in terminal
where php
And it'll gives the path as (in my case)
C:\xampp\php\php.exe
Just extending the answer by #Reinaldo Duguet with a ton of thanks to him !
If you are using Xampp, the PHP path can be found by running the local server and then typing localhost in the browser. This will open the Xampp dashboard. Click on phpinfo() and there you will get the exact path shown as
Configuration File (php.ini) Path = /opt/lampp/etc
Please note that the path may very as per the PHP installation in your system. So you may have to use the respective path shown with above ways.
Then, to let VSCode know this path, open settings in VSCode and search for "PHP debug" and click on the PHP > Debug:Executable Path setting
Add the following line at the first place after "{" telling VSCode where PHP is installed in the system.
"php.validate.executablePath": "/opt/lampp/etc",
If you are using Xampp, the PHP path can be found by running the local server and then typing
the correct version C:/xampp/php/php.exe
XAMPP isn't the best option for linux and i wouldn't recommend it.
Assuming this is not the problem, here is how to do :
find php executable
whereis php
Check your vscode installation. You want to make sure it's not using flatpak (it runs in a container and it would mess up everything)
go in vscode settings, search for php and set "php.debug.executablePath": "/your path/php"
If it still doesn't work, this might be a permission problem. Then :
copy the php executable in your user folder
sudo cp original_path/php /your_user_folder/php
add permissions
sudo chmod 777 /your_user_folder/php
If none of above worked, at this point, you may want to use a VM.
I just wanted to add a possibility here that ended up being my issue in case it helps someone else in the future. My issue was that I was using a Debian based distro and installed VSCode through the software app which relies on Snap apparently. Snap runs the programs in a sandbox and prevents them from seeing other locations on the computer. My solution was that I uninstalled the shop version and installed VScode manually via downloading directly from the website. After that, everything works as expected.

Php commands are not outputing result in windows

I have wamp install on my computer and IIS. All the websites are running well but then any command I type using php is not working :
php -v
php composer install
I would say it is the path variable (I am on windows) but the path is set correctly and it would generate an error of not finding php command. When I run those command I simply don't get any result.
What might be the problem, I am still searching but have not found any clue.
php -h
: return result with all the help information but php -a does nothing too.
After doing some research I found that this problem happens when I activate an extension by remove ; in php.ini whenever I leave php.ini without activating any extension everything works.
Check if the path contains php, also using the cd command, move to the location of the file and run the command you want to execute. If it works, you're sure the problem is the windows path.
I have fixed the issue. To see if the problem was with php.ini, I replaced the content of my php.ini with the php.ini-production file which made the php function well but almost all the extensions were desactivated.
As I was analysing I noticed wamp had many php extensions activated but in my php.ini residing under C:\wamp64\bin\php\php7.3.5 none of these extensions were activated following the path the file used by wamp I found it was using the phpForApache.ini via a link php.ini file inside C:\wamp64\bin\apache\apache2.4.39\bin
Since the wamp php configuration was working well, I just copied the content of that phpFOrApache.ini content in my php.ini after saving ... everything started working.

Accessing FFMPEG installed above public_html webspace

On a shared server with ffmpeg installed above the webspace. Example: /home/username/ffmpeg/ffmpeg which is the full address all the way down to the executable.
The problem is that php cannot find ffmpeg using the -verson option. We tried using mod rewrite to a php file in the public_html webspace which then includes the ffmpeg address above the webspace. But that did not work.
I have never dealt with ffmpeg installed this way, its always been installed in /usr/bin/ or /usr/local/bin .
is there a htaccess or php ini command to tell php where ffmpeg is installed?
how does php suppose to access ffmpeg installed in this way, it is installed as an alias?
Thanks so much :)
As php and ffmpeg are separate things, there's no guarantee that your host will allow php to run ffmpeg, however here are some things you can try:
You can check if web server's user (which php runs as) can "see" any ffmpeg executables in its path by running:
<?php echo shell_exec("which ffmpeg"); ?>
If the output is empty, ffmpeg isn't in the path of the web server's user. In this case you still might be able to run it, if you know the path of the executable.
Also if you run:
<?php phpinfo(); ?>
That will tell you if php is running in safe mode. If it is, your web host may have locked down php's ability to do potentially dangerous things such as executing shell commands.
Change Permission of binaries files (ffmpeg.exe and ffprobe.exe) to 0744.
See image sample here:

Append to the Apache Environment Path

I have a web accessible PHP script that is using a shell command to drop PDFs to text. I installed Poppler, and am using pdftotext, via MacPorts. I am able to run the command successfully from the CL, and when supplying the full path within the PHP script to '/opt/local/bin/pdftotext'. So, I know that my $PATH is correct and the permissions are sufficient, yet I am still getting an exit status of 127: Command Not Found, when attempting to do simply 'pdftotext' in the exec().
I have tried the answers from How do I add paths to the Apache PATH variable? and http://lists.apple.com/archives/macos-x-server/2008/Sep/msg00433.html. I modified both the /etc/paths and /etc/profile, and added /etc/paths.d/macports all pointing to '/opt/local/bin'. setenv, apache_setenv, etc all had no effect also.
I am using a MAMP (1.9 I think) install for my local development, OSX 10.6, PHP 5.3.5, all a little behind I know :-) ... my $PATH is modified to point to the MAMP bin/php
/etc/paths.d/macports will influence on PATH variable for macports, not for the Apache. You probably need to add /etc/parhs.d/apache (or else) to do what you need.
Edit: also check this and this threads for solutions. It is somewhat outdated but still can help.

Call nbtstat command from PHP (64-bit OS)

I'm trying to call the nbtstat command from PHP using shell_exec(). Apparently that doesn't work because I'm using a 64-bit system.
echo shell_exec("nbtstat");
I've done some research and it seems that the problem is caused by the fact that Windows 64-bit defaults to \Windows\SysWOW64 as System32 folder. But nbtstat is located in the normal \Windows\System32 folder.
In normal applications you can call Wow64DisableWow64FsRedirection to disable this redirection, but I haven't managed to find this in PHP yet.
Is there a way to actually call these commands from PHP within a 64-bit Operating System?
Add "\Windows\Sysnative" to the end of your environment path.
What you need to do is to grant the IUSR_<machinename> user Read & Execute / Read permissions not on the C:\WINDOWS\SysWOW64\nbtstat.exe file, but instead on the C:\WINDOWS\SYSTEM32\nbtstat.exe file.

Categories