PHP/Composer include and path-handling - php

i have got a local installation of xampp with wordpress.
xampp -> htdocs -> mywordpress -> composerproject
content of composerproject
I am using a wordpressplugin to include php in articles of wordpress like this
include('../composerproject/recanalyst/test.php');
Everything works fine on a local maschine with xampp an the same wordpress both are working with php 7.1.
But when i deploy the same on my webspace with following settings:
paths of webspace
define('ROOTPATH', __DIR__);
echo ROOTPATH;
require ROOTPATH . '/vendor/autoload.php';
use RecAnalyst\RecordedGame;
$filename = ROOTPATH . '/test.mgz';
$rec = new RecordedGame($filename);// This line 12 doesnt work
Error line 12
Uncaught Error: Class 'RecAnalyst\RecordedGame' not found in /var/www/vhosts/myhoster.net/httpdocs/recanalyst/test.php:12 Stack trace: #0
Composerproject on github:
enter link description here

Can be closed. My webhoster is running with php 7.1 but their cli was running with 5.3.3. So i had installed with putty an old version of composer without recognizing it. Changing the CLI to 7.1 was the solution.

Related

php Tesseract Error! The command "tesseract" was not found

I'm trying and failing to use tesseract php. I get this error:
Fatal error: Uncaught thiagoalessio\TesseractOCR\TesseractNotFoundException: Error! The command "tesseract" was not found. Make sure you have Tesseract OCR installed on your system: https://github.com/tesseract-ocr/tesseract
The current $PATH is C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Windows\System32\OpenSSH\;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR;C:\xampp\php;C:\ProgramData\ComposerSetup\bin;C:\Users\Peppe\AppData\Local\Microsoft\WindowsApps;C:\Users\Peppe\AppData\Roaming\Composer\vendor\bin in C:\Users\Peppe\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php:48 Stack trace: #0
C:\Users\Peppe\vendor\thiagoalessio\tesseract_ocr\src\TesseractOCR.php(26): thiagoalessio\TesseractOCR\FriendlyErrors::checkTesseractPresence('tesseract') #1 C:\xampp\htdocs\index.php(7): thiagoalessio\TesseractOCR\TesseractOCR->run() #2 {main} thrown in C:\Users\Peppe\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php on line 48
I'm using windows 10 with xampp installed in C:\xampp. php version 7.4
I installed tesseract.exe from https://github.com/UB-Mannheim/tesseract/wiki both x32 and x64
I used composer to install the https://github.com/thiagoalessio/tesseract-ocr-for-php and it gave no error.
<?php
require_once 'C:\Users\Peppe\vendor\autoload.php';
use thiagoalessio\TesseractOCR\TesseractOCR;
$ocr = new TesseractOCR("caption.jpg");
$content = $ocr->run();
echo $content;
?>
finally, the caption.jpg is in the htdocs folder, the main folder and same folder as index.php where the aforementioned code appears.
any solutions?
I found the answer:
the $PATH variable is taken from Windows. To set it right search for "system environment variables", click "environment variables", edit PATH and add the tesseract software folder, for example C:\Program Files\Tesseract-OCR
In my case I have to add new variable tesseract with full path C:\Program Files\Tesseract-OCR\tesseract.exe as showing in below screenshot
To install TESSERACT OCR and use it in PHP
You must perform the following steps:
(in my explanation, I assume you are on windows)
url src = https://tesseract-ocr.github.io/tessdoc/Installation.html
1- Download the TESSERACT software from URL:
https://github.com/UB-Mannheim/tesseract/wiki
2- From your composer, you must install:
url: https://packagist.org/packages/thiagoalessio/tesseract_ocr
composer require thiagoalessio/tesseract_ocr
3- Then, it is important to do things in the following order:
Your TESSERACT software (step 1) is installed in a directory
which will certainly be (it's up to you to check in your system)
folder = C:\Program Files\Tesseract-OCR
It is absolutely necessary to add this folder in the windows environment variables at the PATH level (user and system)
4- Then you restart your web environment (WAMP, LARAGON ...)
5- Verification that TESSERACT is operational.
Go to your CMD and write:
tesseract --version
Reply somethink like that :
tesseract v5.3.0.20221222
leptonica-1.78.0
libgif 5.1.4 : libjpeg 8d (libjpeg-turbo 1.5.3) : libpng 1.6.34 : libtiff 4.0.9 : zlib 1.2.11 : libwebp 0.6.1 : libopenjp2 2.3.0
Found AVX2
Found AVX
Found FMA
Found SSE4.1
Found libarchive 3.5.0 zlib/1.2.11 liblzma/5.2.3 bz2lib/1.0.6 liblz4/1.7.5 libzstd/1.4.5
Found libcurl/7.77.0-DEV Schannel zlib/1.2.11 zstd/1.4.5 libidn2/2.0.4 nghttp2/1.31.0
6- Operation test from a PHP script
uses an image on a white background with text
<?php
$app_class = 'thiagoalessio\TesseractOCR\TesseractOCR';
$file = 'C:/Users/admin/Desktop/im2.jpg';
$class = new ReflectionClass($app_class);
$infoImg = $class->newInstanceArgs();
$infoImg->lang('eng','jpn','spa','fr');
$infoImg->image($file);
$infoImg->withoutTempFiles();
$resultat = $infoImg->run();
var_dump($resultat);
?>

tesseract-php wrapper having a path error while running on localhost

So I am using the tesseract-php wrapper given here https://github.com/thiagoalessio/tesseract-ocr-for-php.
Here's what my php code looks like:
<?php
require_once "vendor/autoload.php";
use thiagoalessio\TesseractOCR\TesseractOCR;
echo (new TesseractOCR('image1.jpeg'))->run();
?>
On running via cmd, it works just fine. However, while trying to run on xampp server, I'm getting this error
Fatal error: Uncaught thiagoalessio\TesseractOCR\TesseractNotFoundException:
Error! The command "tesseract" was not found. Make sure you have Tesseract
OCR installed on your system: https://github.com/tesseract-ocr/tesseract The
current $PATH is C:\ProgramData\Oracle\Java\javapath;C:\Program Files
(x86)\Common Files\Intel\Shared Libraries\redist\intel64\compiler;C:\Program
Files (x86)\Intel\iCLS Client\;C:\Program Files\Intel\iCLS Client\;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files\Intel\Intel(R) Management Engine Components\DAL;C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files\Intel\Intel(R) Management Engine Components\IPT;C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common;C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program
Files\Java\jdk1.8.0_151\bin;C:\Program Files\Git\
in C:\xampp\htdocs\tesseract_project\vendor\thiagoalessio\tesseract_ocr\src\FriendlyErrors.php on line 42
I read a few answers here, and turns out adding this would help
$path = getenv('PATH');
putenv("PATH=$path:C:\Program Files (x86)\Tesseract-OCR");
However, there's no change, and I'm still getting the same error. Is there anything I'm doing wrong?
INSTALL TESSERACT IN YOUR SYSTEM THEN Define a custom location of the tesseract executable, if by any reason it is not present in the $PATH.
->executable('/path/to/tesseract')
->run();

OSX (El Capitan) - Homebrew Apache 2.4 + PHP-FPM + mongoDB - Service unavailable

UPDATE
I've tried using PhpMyAdmin with the same configuration and I've got the same error 503 Service Unavailable.
So it seems that it has nothing to do with the mongodb module but it's an Apache or PHP-FPM misconfiguration. In my opinion it's most probably the fcgi proxy which doesn't call php-fpm the proper way but I don't know what goes wrong.
Original question
I've been tearing my hair out for hours trying to find the a solution.
Config:
OSX (El Capitan)
homebrew Apache 2.4
php-fpm (5.5 or 7.0, I've tried both, same error!)
This works in index.php
<?php
echo phpinfo();
Php info
PHP Version 7.0.18
MongoDB extension version 1.2.8
I've tried calling a php in a subdirectory (I suspected that there is a problem with the proxy parameter) but it's working.
Conslusion so far:
apache is working
document root OK
default index OK (I've tried explicitly index.php anyway)
php-fpm is running
apache proxy to php-fpm working (see UPDATE above!)
Now the weird part
I change the contents of index.php to this:
<?php
require 'vendor/autoload.php';
$client = new MongoDB\Client("mongodb://localhost:3001");
The only composer module installed is mongodb/mongodb with composer require mongodb/mongodb
The result is simple 503 Service Unavailable
The parameter (mongodb://localhost:3001) in irrelevant I have the same error without any parameters or with intentionally bad parameters.
(But in case you're wondering I'm trying to connect to the mongodb of a local development instance of a Meter application that's the reason for port 3001. And the connection is working from external program /Robomongo/)
Currently I'm using Apache ProxyPassMatch but I've tried SetHandler method as well (see below). I've tried with php-fpm 5.5 and php-fpm 7.0 (both installed with homebrew)
Apache config:
ProxyPassMatch ^/(.*\.php)$ fcgi://127.0.0.1:9007/Users/myuser/Projects/test/$1
Or
<FilesMatch \.php$>
SetHandler "proxy:fcgi://127.0.0.1:9007"
</FilesMatch>
No error messages in Apache or php-fpm logs (even with loglevel debug) despite error logging is working (I've tried making a deliberate PHP syntax error and it generated the proper error message in php-fpm error log file)
e.g.
<?php
require 'vendor/autoload.php'; // include Composer's autoloader
$client = new MongoDB;
The error message is clearly shown so the error logging is fine
Fatal error: Uncaught Error: Class 'MongoDB' not found in
/Users/myuser/Projects/test/index.php:17 Stack trace: #0 {main} thrown in
/Users/myuser/Projects/test/index.php on line 17
I've tried connecting to a MySQL database with this code:
$mysqli = new mysqli("localhost", "user", "password", "dbname");
$res = $mysqli->query("SELECT * FROM table");
print_r($res);
It works like a charm.
Any help would be appreciated.
EDIT:
composer.json contents as requested by a comment
{
"require": {
"mongodb/mongodb": "^1.1"
}
}

How do I install wkhtmltophp on Laravel 4 running on Windows 8?

I have a WAMP server on Win 8 running Laravel 4 and I'm trying to get wkhtmltophp to work properly.
I ran the Windows installation program I downloaded from here (the 64-bit "Windows (MSVC 2013)").
I'd first installed it into C:\Program Files\wkhtmltopdf, then I tried installing it into the laravel /vendor directory under C:\Program Files (x86)\Apache Group\Apache2\htdocs\gitt\vendor\wkhtmltopdf
naturally I changed my folder to match under /app/config/local/laravel-pdf.php and in this file I have
return array(
//'bin' => '/usr/bin/wkhtmltopdf'
'bin' => base_path() . '/vendor/wkhtmltopdf/bin'
);
And every time I run the script, I get the error "proc_open(): CreateProcess failed, error code - 5"
Not sure what I'm missing. Another developer, on a Mac, was able to install it on his side, so laravel also has the /vendor/mikehaertl/phpwkhtmltopdf installed, so I changed line 92 to:
class WkHtmlToPdf
{
#protected $bin = '/usr/bin/wkhtmltopdf';
protected $bin = '/Program Files (x86)/Apache Group/Apache2/htdocs/gitt/vendor/wkhtmltopdf/bin/wkhtmltopdf.exe';
etc......
Still got the same error. I'm lost! Any help would be greatly appreciated! :)

PHP shell_exec() not working

I tend to use one of a programms that i installed on my vps server ,
the script which i made is work perfectly on my localhost , but it doesn't work on vps.
Here what i tried
$r = shell_exec('wkhtmltopdf http://monsite.ma/generate/15 /var/www/vhosts/monsite.ma/qr-u15.pdf');
// $r contain a null variable
Full path command also not working .
i have centos6.5 with php5.5 installed on my vps too .
and Windows7 with php5.5 on my localhost

Categories