shell_exec() not executing pdftotext command - php

I installed the required library and its working in terminal but not in my php file.
My code is :
$mypdf = shell_exec('/usr/local/bin/pdftotext test.pdf test.txt');
echo $mypdf;
If I execute this command /usr/local/bin/pdftotext test.pdf test.txt in terminal it works fine.
I also write my code this type :
shell_exec('/usr/local/bin/pdftotext test.pdf test.txt');
$mypdf = file_get_contents("test.txt");
echo $mypdf;
In Error Log the message is :
/usr/local/bin/pdftotext: /opt/lampp/lib/libgcc_s.so.1: version `GCC_4.2.0' not found (required by /usr/lib/i386-linux-gnu/libstdc++.so.6)

My guess would be that you're expecting $mypdf to contain the PDF document instead of the return value of the executed command. If you're trying to print out 'test.txt', then you'll need to load it up and print it.

Issue was: /usr/local/bin/pdftotext: /opt/lampp/lib/libgcc_s.so.1: version 'GCC_4.2.0' not found (required by /usr/lib/i386-linux-gnu/libstdc++.so.6)
And the solution was to rename /opt/lampp/lib/libgcc_s.so.1 to libgcc_s.so.1.bak and solves my problem. But confusion is that what was the issue in it :P

I think you have some trouble with a dependency. Check your error.log. Find out which file is missing and add it to the path environment variable of your php installation.

Related

How to run node module in php and display output?

I have a use case where i need to run a node module in php script and display it's output back on the page. Here's the steps I followed:
I have installed the module npm install -g md2gslides
I am using PHP's exec() for running the module
exec('node_modules/md2gslides/bin//md2gslides.js --version 2>&1', $output);
But it's not working. The error is below:
However, it runs in ubuntu's terminal without issues.
What is wrong here?
The error not because of php but because of the path.join() in line 33 of md2gslides.js
const STORED_CREDENTIALS_PATH = path.join(USER_HOME, '.md2googleslides', 'credentials.json');
It tries to find the credentials.json in users home directory. But I think it's unable to.
So I moved the file to node_modules/md2gslides/bin and modified path.join() as path.join(__dirname, '.md2googleslides', 'credentials.json')
This solved the issue.

yaml_emit_file() not working. Call to undefined function yaml_emit_file()

The php function yaml_emit_file() is not working. I have installed and included the php_yaml.dll in my php.ini file restarted the server but still when I use this function, I get this error (when I run composer):
Call to undefined function RS\composer\yaml_emit_file()
Okay so a little about the background:
PHP version 7.1.7 & Composer version 1.5.1
I am using this function in a ScriptHandler.php file which is invoked when Composer is run. In this script I have a function buildModuleList which is called on post-update-cmd event of Composer. Everything else in the code is working fine.
I am in doubt that maybe I am using this function in wrong context or something like that.
Here is the code snippet where I am using yaml_emit_file() (Providing this just for reference, tell me if am using it the wrong way!):
if (!$fs->exists($moduleListFile)) {
$fs->touch($root.'/profiles/thunder/modulelist.yml');
$fs->chmod($root . '/profiles/thunder/modulelist.yml', 0666);
if(!empty($moduleList)){
$createyml= yaml_emit_file($moduleListFile, $moduleList);
if (!$createyml){
$io->writeError('<error>Cannot create modulelist.yml</error>');
}
}
$io->write('Success: Created new modulelist.yml', $newline= TRUE);
}
else{
$fs->file_put_contents($moduleListFile, $installedPackage, FILE_APPEND);
$io->write('Success: Module entry in modulelist.yml', $newline= TRUE);
}
i hope this help someone i test it on
Windows 10
XAMPP v3.2.4
PHP 8.0.2
Download the latest YAML DLL Package from : https://pecl.php.net/package/yaml
Unzip the files
Move the php_yaml.dll file to xampp/php/ext folder
Open your php.ini in xampp/php add a new line extension=php_yaml.dll, save and exit
Restart your XAMPP Servers
make a PHP file put into
<?php
phpinfo();
?>
Search the string yaml on the page. If it says Enabled then your YAML Extension is working.

How to set php executable path php.validate.executablePath in vscode when php is set inside docker container?

I have a development environment based in docker.
Everytime that I open VSCode I get this message:
Cannot validate since no PHP executable is set. Use the setting
'php.validate.executablePath' to configure the PHP executable.
Somebody know how to set php.validate.executablePath in this case?
I have no idea how to do it.
Here is a screenshot.
Don't forget to escape \
You don't have to add it to the Path
For linux users:
if you don't have PHP installed then first download, then in terminal type
$ whereis php
and it will show path for php executable (It will be either in /usr/bin/php or usr/local/bin/php) which you can copy from terminal.
In VScode goto settings.json file and paste
php.validate.executablePath: /usr/bin/php
In my case using XAMPP is like this
"php.validate.executablePath": "C:/xampp/php/php.exe"
hope that answer your question
Sure, easy. Just follow what it's says.
Go to File> Preferences > Settings ... it will open the settings.json file.
add the following code:
{"php.validate.executablePath": "Here you put your PHP.exe path"}
You have to know where te PHP.exe file is in your computer, search in the php>bin folder.
Hope it works for you
I had the same problem but found the fix here.
In Windows:
Go To System Properties
Go To Advanced Tab
Click "Environment Variables"
Select Path
Add a new path that points to your php 7 executable:
My case, I'm using Laragon, so you should search where is your php.exe.
By VSCode just add.
"php.executablePath": "C:\\laragon\\bin\\php\\php-7.2.19-Win32-VC15-x64\\php.exe"
on settings.json.
VSCode
Linux Users:
Step 1:
In your terminal type
whereis php
In my case "php: /opt/lampp/bin/php"
Step 2:
{
"php.validate.executablePath": "/opt/lampp/bin/php"
}
Download PHP, in my case, I downloaded from here:
http://windows.php.net/download/
Copy and paste the files to a location on your computer, and set the path:
"php.validate.executablePath": "C:/php/php.exe"
"php.validate.executablePath": "C:/php/php.exe" wont work due to incorect escaping
try this;
"php.validate.executablePath": "C:\\php\\php.exe"
If you get this on windows in VS code click on the blue 'open settings' button. Near the bottom of the screen this opens there's a link to enter the settings, click this to open the settings.json file. Edit the file to look like this:
{
"php.executablePath" : "C:/php-7.4.2-nts-Win32-vc15-x64/php.exe",
"php.validate.executablePath" : "C:/php-7.4.2-nts-Win32-vc15-x64/php.exe"
}
where C:/php-7.4.2-nts-Win32-vc15-x64 is the path to your PHP dir
I don't know if this helps but I ran into the same problem with the extension PHP Intelephense in Visual Studio Code. What I did is read the instructions so the extension could work properly. So I disabled PHP Language Features by searching "#builtin PHP" in the extensions. Also, other (3rd party) PHP extensions that provide similar functionality should also be disabled for best results. Finally, I added glob patterns for non-standard PHP file extensions to the files.associations setting. For example: "files.associations": { "*.module": "PHP" }
Doing this made the error go away. I'm new to PHP too, let me know if this is the correct way of solving this problem with PHP Intelephense.
If you're using VScode and have installed Php through MAMP, the default path should be:
C:/MAMP/bin/php/php7.4.1/php.exe
/ not \
Regarding the docker-specific revision of the question, I found this thread in the VS Code PHP Intellisense git repo issue that explains how to create a wrapper script. It will involve mapping volumes, though, so take that into account.
https://github.com/felixfbecker/vscode-php-intellisense/issues/150#issuecomment-330374124
I have ubuntu and XAMPP.
The following worked for me.
Press CTRL + P
Type settings.json and hit ENTER.
Add the following line in settings.json
{
...
"php.validate.executablePath": "/opt/lampp/bin/php",
...
}
Make sure to proper syntax.
I simply used double forward slashes and it worked, like so:
"php.validate.executablePath": "C:\\xampp\\php\\php.exe",
Unix / Linux / Mac / WSL ,
Step 1 : Find PHP path
whereis php
Response will show you where your php directories are.
user#User:~$ whereis php
php: /usr/bin/php /usr/bin/php8.0 /usr/bin/php8.1 /usr/lib/php /etc/php /usr/share/php8.0-opcache
/usr/share/php8.0-xml /usr/share/php8.1-curl /usr/share/php8.1-opcache /usr/share/php8.0-gd
/usr/share/php7.0-gd /usr/share/php7.0-common /usr/share/php8.0-readline /usr/share/php8.0-mysql
/usr/share/php8.0-zip /usr/share/php8.1-mbstring /usr/share/php8.1-xml /usr/share/php8.0-mbstring
/usr/share/php8.0-common /usr/share/php8.0-curl /usr/share/php8.1-readline /usr/share/php8.1-common
/usr/share/man/man1/php.1.gz
Step 2 : Configure VS-Code
Go to -> "Preference -> Settings"
Search for -> "php path"
Then click -> "Edit in settings.json"
In my case I had multiple.So I chose the one I wanted from the available versions and my VS-Code looked like this
"php.validate.executablePath": "/usr/bin/php8.1",
IF using Laragon...Dont forget to change \ to /
"php.executablePath": "C:/laragon/bin/php/php-7.4.5-Win32-vc15-x64/php.exe",
Go to 'Preference' -> 'Settings'
Search for> php path
Then click Edit in settings.json
Then just put your directory with (DOUBLE Backslash).
Here is an example of mine:
C:\\php\\php.exe
Here is the format:
drive:\\folder_name\\php.exe
This should fix the problem.
php.validate.executablePath in laragon
In my case using laragon is like this
"php.validate.executablePath": "C:\\laragon\\bin\\php\\php-7.4.19-Win32-vc15-x64\\php.exe"
php-7.4.19-Win32-vc15-x64 : Note that this part of your file name may be different
I also had this error. I have installed Laragon and this addition in setting.json worked for me.
"php.executablePath":"C:/laragon/bin/php/php-7.2.19-Win32-VC15-x64/php.exe"
"php.validate.executablePath": "C:\xamp\php\php.exe"
this is working for this case
For Wampserver:
Inside settings.json
"php.validate.executablePath": "C:/wamp64/bin/php/php7.4.26/php.exe"
If php is inside a docker container and you don't need it or don't want to install it on you local system, you can create a php wrapper script like it is suggested here: https://github.com/felixfbecker/vscode-php-intellisense/issues/471
I prefer to use the remote container Microsoft extension on vscode and work inside the container itself.
I've used such solution:
First, create a php file inside /usr/local/bin/ and make it executable:
sudo touch /usr/local/bin/php
sudo chmod +x /usr/local/bin/php
Update content of it with:
docker exec $(docker ps --filter name=-app --format '{{.ID}}') php "$#"
So this will find a container with the name -app at the end. I'm using it along with the docker compose where I have php inside some container which has -app at the end of the name. You can check more about filter here.
And then update php.validate.executablePath with /usr/local/bin/php:
{
"php.validate.executablePath": "/usr/local/bin/php"
}
I also got this error message. The path to php.exe was already set in my System Environment Variables.
The error went away when I commented out "php.validate.executablePath": "c:/path/to/php7.2.10/php.exe", in the settings.json file in VSCode.

Cannot make command line tool for artisan in PHPStorm 10.0.1

I got this error message when I tried to make an alias for artisan:
[Settings | Tools | Command Line Tool Support ] -> add -> tool based on Symfony Console
Problem
Failed to parse output as xml: Error on line 4: Content is not allowed in prolog..
Command
C:\xampp\php\php.exe C:\xampp\htdocs\laratest\artisan list --xml
Output
[Symfony\Component\Console\Exception\RuntimeException]
The "--xml" option does not exist.
Ok, I know, what's the problem but I don't find any solution for this.
Thank you for the tips!
A temporal modification of the "artisan" file under the Laravel folder will do the trick. (Working on PhpStorm 10.0.3)
if( isset($argv[1]) && $argv[1] == 'list' &&
isset($argv[2]) && $argv[2] == '--xml' ) {
$argv[2] = '--format=xml';
$_SERVER['argv'] = $argv;
}
require __DIR__.'/bootstrap/autoload.php';
Now you can add the "artisan" command line tool support based on Symfony and remove the lines if you wish to.
For everybody affected, this is the commit which removed support for –xml: https://github.com/symfony/console/commit/6d6d9031b9148fed0e2aacb98ac23ce6168ba7ac
Just revert changes in ListCommand.php
it work in 2.7 version
There is no --xml option, you are getting this error when you running this command:
The "--xml" option does not exist.
So what you should do in this case is running:
php artisan help list
and you will get list of all available parameters
and now you will know you need to use:
php artisan list --format=xml
instead of:
php artisan list --xml
EDIT
I've verified it in PhpStorm 10.0.3
as Tool path you can paste in your case:
C:\xampp\php\php.exe C:\xampp\htdocs\laratest\artisan list --format=xml
and it will work
Update composer before add command line tool:
composer update

installing codeigniter sparks manager on windows

SOLVED, read bottom of post:
I'm trying to install the Sparks package manager on windows by following the official instructions.
Issuing this command:
php -r "$(curl -fsSL http://getsparks.org/go-sparks)"
results in this errormessage:
Parse error: syntax error, unexpected ':' in Command line code on line 1
If I only execute the curl command within the above line, i.e this:
curl -fsSL http://getsparks.org/go-sparks
it echoes out the php script located on the URL. So I think the problem is piping the curl output to PHP somehow fails. I've tried a couple of variants, using diffrent quotes etc but I'm at a loss.
MY SOLUTION
As DaveRandom pointed out, the instruction didn't apply to windows.
But instead of doing it the manual(normal) way, what I did was taking the output from curl, appending php script tags and executing it as a file with the php -f option.
Here is the output:
<?php
$zip = "http://getsparks.org/static/install/spark-manager-0.0.7.zip";
$loader = "http://getsparks.org/static/install/MY_Loader.php.txt";
if(!file_exists("application/core"))
{
echo "Can't find application/core. Currently this script only works with the default instance of Reactor. You may need to try a manual installation..\n";
exit;
}
echo "Pulling down spark manager from $zip ...\n";
copy($zip, "sparks.zip");
echo "Pulling down Loader class core extension from $loader ...\n";
copy($loader, "application/core/MY_Loader.php");
echo "Extracting zip package ...\n";
if(class_exists('ZipArchive'))
{
$zip = new ZipArchive;
if ($zip->open('sparks.zip') === TRUE)
{
$zip->extractTo('./tools');
$zip->close();
} else {
echo "Extraction failed .. exiting.\n";
exit;
}
} elseif(!!#`unzip`) {
`unzip sparks.zip -d ./tools`;
} else
{
echo "It seems you have no PHP zip library or `unzip` in your path. Use the manual installation.\n";
exit;
}
echo "Cleaning up ...\n";
#unlink('sparks.zip');
echo "Spark Manager has been installed successfully!\n";
echo "Try: `php tools/spark help`\n";
The instructions you linked do explicitly state;
In order to use this quick start option, you should be using OSX or some flavor of linux.
You need to follow the Normal Installation instructions for use on Windows.
You should execute the command php -r "$(curl -fsSL http://getsparks.org/go-sparks)" in your root application folder. Maybe you're executing this command at wrong folder.

Categories