laravel-snappy: file was not created - php

At the moment, I'm trying to trace where this issue arose from given that nothing major was changed.
But at the moment I currently use laravel-snappy to generate pdfs, I haven't had an issue until now when I am all of a sudden receiving the following errors:
The file 'C:\Users\ADMINI~1\AppData\Local\Temp\knp_snappy5a7d3011c11883.41249127.pdf' was not created (command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf" --lowquality --images --enable-javascript --javascript-delay "10" "C:\Users\ADMINI~1\AppData\Local\Temp\knp_snappy5a7d3011b9a179.91650543.html" "C:\Users\ADMINI~1\AppData\Local\Temp\knp_snappy5a7d3011c11883.41249127.pdf").
Unfortunately, it doesn't tell me why it wasn't created. At this point in time, the error handler points to this specific line where it is returning this error:
if (!$this->fileExists($output)) {
throw new \RuntimeException(sprintf(
'The file \'%s\' was not created (command: %s).',
$output, $command
));
}
This line comes from this file: vendor\knplabs\knp-snappy\src\Knp\Snappy\AbstractGenerator.php
My wkhtmltopdf binary is located in the correct place, and nothing has changed in response to the setup of these files. And yes, at the moment these files are hosted and served on a Windows Server platform.
My config for the snappy:
<?php
return array(
'pdf' => array(
'enabled' => true,
'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf"',
'timeout' => false,
'options' => array(),
'env' => array(),
),
'image' => array(
'enabled' => true,
'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage"',
'timeout' => false,
'options' => array(),
'env' => array(),
),
);
My files are being generated as such through my controller:
public function downloadPDF(Shipment $shipment) {
$shipment_details = $shipment->shipment_details;
$shipment->print_date = Carbon::now();
$shipment->save();
$pdf = PDF::loadView('shipments.pdf', compact('shipment','shipment_details'))
->setOption('images', true)
->setOption('enable-javascript', true)
->setOption('javascript-delay', 10);
return $pdf->download('shipment'.$shipment->uuid.'.pdf');
$shipment->print_date = Carbon::now();
$shipment->save();
}

Posting this in case someone else googling has the same problem, and they don't like the accepted answer of "just do it in Linux"
For me it was because Visual C++ 2013 wasn't installed - running the file in the command line gave me errors about missing dlls that were included in the redist.

The easiest way to get around this is to exec a raw command, wkhtmltopdf does not have the same command line parameter on Linux/Windows, this means that the snappy wrapper only works with amd64 and fail when it's used with a 64bit windows executable.
exec("C:/path/to/wkhtmltopdf.exe path/to/my.html destination/for/my.pdf");
since this solution is terrible and that wkhtmltopdf functionality are limited on windows, I strongly recommend you to deploy with docker, or to just develop under Linux. Or else you won't be able to use multiples functionality like pdf footer, pdf encoding utf-8 and much more...
Here's a tutorial on how to use docker compose for laravel!

Related

PHP CLI corrupts executed file

Problem description
Sometimes after running PHP CLI, the primary executed PHP file is erased. It's simply gone.
The file is missing / corrupted. Undelete (Netbeans History - revert delete) still shows the file, but it is not possible to recover it. It is also not possible to replace / reinstate the file with the identical filename.
Trial and error attempts
The issue occurs on (3) different computers, all Windows 10 or Windows 11.
I've used different versions of PHP (php-7.3.10-Win32-VC15-x64, php-8.1.4-Win32-vs16-x64).
The code is not doing any file IO at all. It uses a React event loop, listening to a websocket - "server_worklistobserver.php":
<?php
require __DIR__ . '/vendor/autoload.php';
$context = array(
'tls' => array(
'local_cert' => "certificate.crt",
'local_pk' => "certificate.key",
'allow_self_signed' => true, // Set to false in production
'verify_peer' => false
)
);
// Set up websocket server
$loop = React\EventLoop\Factory::create();
$application = new Ratchet\App('my.domain.com', 8443, 'tls://0.0.0.0', $loop, $context);
// Set up controller component
$controller = new WorklistObserver();
$application->route('/checkworklist', $controller, array('*'));
$application->run();
die('-server stopped-');
The disappearance happens when the PHP execution is cancelled. Either by Ctrl-Break, or when run as a service, a service stop/restart.
Execution is started by: php.exe server_worklistobserver.php in a dos-box (cmd).
Using administrator permissions has no effect. Performing a harddisk scan has no effect; there are no issues found. The issue is rather persistent, but not regular; it seems to happen by chance.
Associated PHP files are left intact.
The issue has never occurred on the Apache driven PHP execution.
Please help
What could I do different? Does have anyone have a similar experience? I can't find anything alike on the internet...
Thanks in advance.
Thanks so much, Chris! Indeed, I found the entries in the quarantaine of my virusscanner. I've added an exception rule and don't expect to have this happen again.

Cannot read credentials from /.aws/credentials - PHP script call AWS-SDK

I've looked at every answer on here and it seems my problem is a little different or there hasn't been a proper solution. I'm doing the following in my PHP file:
use Aws\Route53\Route53Client;
$client = Route53Client::factory(array(
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2013-04-01'
));
Getting this error:
Fatal error: Uncaught Aws\Exception\CredentialsException: Cannot read credentials from /.aws/credentials
Seems like the easy fix would be ensure that the HOME directory is the right one. Indeed it already is. Files are readable and my ec2-user is already the owner. Key and Secret is already installed in the 'credentials' file. Profile name is already set to 'default.' Tried to copy /.aws to other directories such as the root, /home, etc and changed permissions, chmod, all the above. Still nothing.
Then I tried to hard-code the credentials (I know -- not recommended) just to give it a little kick, and it completely ignores that I did this:
$client = Route53Client::factory(array(
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2013-04-01',
'credentials' => [
'key' => $key,
'secret' => $secret,
]
));
As a last resort, I even tried including the CredentialProvider class, and passing this into my array -- still nothing:
'credentials' => CredentialProvider::ini('default', '/home/ec2-user/.aws/credentials'),
What on earth am I doing wrong?
Just remove 'profile' => 'default', and you should work fine
$client = Route53Client::factory(array(
'region' => 'us-east-1',
'version' => 'latest',
'credentials' => [
'key' => $key,
'secret' => $secret,
]
));
Running on AWS Centos 7, I tried everything (chmod/chown /root /home/user, env, bashrc, etc) to get the /.aws/credentials to work outside the apache /var/www directory. The SDK reported that it could not read the credentials file.
I looked at PHP to see if I could set/override the HOME variable and it still did not read the credentials file until I placed the .aws folder in the '/var/www' folder and set the HOME variable in my php file like so:
<%php
putenv('HOME=/var/www');
//ZIP File SDK Install requires aws-autoloader
require 'aws-autoloader.php'; //Your php code below
Facing this issue, here was my exact approach:
PHP version : 7.2.24 AWS PHP SDK version: 3.180.4
First copy your existing aws folder to your root home directory
sudo cp -r ~/.aws /
Then your code should look like:
$client = Route53Client::factory(array(
'profile' => 'default',
'region' => 'us-east-1',
'version' => '2013-04-01'
));
In my case, it was interesting to realize that the PHP SDK looks for the credentials file in the root folder and not in the current users's home directory. That's the most feasible reason why my approach worked.
However, you want to find a more general place for your local configs and use the following approach to load it.
$path = '/my/config/folder/.aws/credentials';
$provider = CredentialProvider::ini('default', $path);
$provider = CredentialProvider::memoize($provider);
$client = Route53Client::factory(array(
'region' => 'us-east-1',
'version' => '2013-04-01',
'credentials' => $provider
));
Hopefully this throws more light into the AWS PHP community. It's really important to get this configuration right to build secure PHP applications
Here is what I ended up doing for purposes of this question, although EJ's answer above is actually the right answer. Hopefully this helps someone to get their credentials file to be read:
use Aws\Credentials\CredentialProvider;
use Aws\Route53\Route53Client;
$profile = 'default';
$path = '/var/www/html/.aws/credentials';
$provider = CredentialProvider::ini($profile, $path);
$provider = CredentialProvider::memoize($provider);
$client = Route53Client::factory(array(
'region' => 'us-east-1',
'version' => '2013-04-01',
'credentials' => $provider
));
Not sure what you are doing wrong, but I'd suggest bypassing the problem altogether and assigning an EC2 Instance role to the vm in question and then you won't have to worry about it; it's a better/more secure solution.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/iam-roles-for-amazon-ec2.html
I think the AWS manual is a bit confusing.
I created the .aws directory at the filesystem root (/), not in the /root or /home dir, and everything worked.
/.aws/credentials
I upgraded from PHP 8.0 to PHP 8.1 and PHP suddenly complained it couldn't find the credential file. The xdebug error trace showed me the expected location, which was one level below my public html directory. I don't know why it changed, but I simply ran this command in that directory:
ln -s /.aws/ .aws
The symlink I created works fine to provide the credentials. I'm back up and running.
check the permission of .aws/* files using "ls -l"
Change the permission to grand read or grant all permision "sudo chmod 777 .aws/*"
rerun the code

No valid ext_emconf.php file found for package in TYPO3 7.6

I want to install an extension via direct upload in Extension Manager. But allways i get the Message "No valid ext_emconf.php file found for package ...". Somebody out there that can help with this problem?
<?php
$EM_CONF[$_EXTKEY] = array (
'title' => 'Interfrog Themeconfiguration',
'description' => 'contains all themeconfiguration tables config,color,font,colorshemes without an existing theme',
'category' => 'misc',
'author' => 'Interfrog',
'author_email' => 'info#interfrog.de',
'author_company' => 'Interfrog Produktion GmbH',
'state' => 'beta',
'uploadfolder' => true,
'createDirs' => NULL,
'clearCacheOnLoad' => true,
'version' => '2.3.1',
'constraints' => array(
'depends' => array(
'extbase' => '7.6',
'fluid' => '7.6',
'typo3' => '7.6',
),
'conflicts' => array(
),
'suggests' => array(
),
),
'autoload' => array(
'psr-4' => array('Interfrog\\IfThemeconfiguration\\' => 'Classes')
),
);
?>
Dependencies must have both upper and lower boundaries defined.
Technically your line 'extbase' => '7.6', has no value at all.
Do you want to restrict from 7.6 upwards?
Or restrict to a maximum of 7.6?
What's 7.6 after all?
7.6.9970970?
7.6.0?
You see, there is no valuable information that can be pulled from this.
This is why you need to provide specific boundaries like this for example:
'extbase' => '7.6.15-7.6.99'
PSA:
Be extremely careful with loose upper bounds. We see people going 7.6.0-9.99.99.
Unless you own some magic crystal ball that can foretell the future, it's better to raise the dependency constraints once you actually tested them.
At our last Usergroup we figured out the reason. We found out that the problem arises when zipping the extension locally on Mac OSX command line. All files looses its access rights and properties that causes the effect that the ext_emconf.php can't be found during the install process. If you download the zip from an installed live system everything is fine.
We doesn't work out the correct command on Mac OSX command line. It would be awesome if someone can work out the right command for zipping on command line.
Regarding the issue on a Mac
The problem is not (only) the hidden MAC_OS folders. The issue is, that OS X does not put the content of chosen Typo3-Extension-Folder into the archive but the folder as single root element itself. Then Typo3 cannot find the files. You must go into the extension folder and run then the zip command.
Example: We are in my working directory which is named output. The extension folder is called jfmulticontent_3.0.0-dev_201810051125. Then you would have to run:
BOB-NB2:output bob$ cd jfmulticontent_3.0.0-dev_201810051125/
BOB-NB2:jfmulticontent_3.0.0-dev_201810051125 bob$ zip -r -X ../jfmulticontent_3.0.0-dev_201810051125.zip *

Site running under MAMP dies when ob_get_clean is called

I'm running MAMP with PHP version 5.5.10. PHP and Apache are both working, except on pages that call ob_start() and ob_get_clean():
<?php
if (array_key_exists('DOCUMENT_ROOT', $_SERVER))
include("{$_SERVER['DOCUMENT_ROOT']}/php-libs/setup.php");
else {
// use include path - under CGI
include("php-libs/setup.php");
}
$page = $site->page();
$page_info = array(
'title' => 'Welcome!',
'page_title' => '',
'page_subtitle' => '',
'page_type' => 'homepage',
'body_class' => 'home full'
);
$page->setup($page_info);
ob_start();
?>
<p>Hello World!</p>
<?php
$page->setContent(ob_get_clean());
$page->display();
The result is that I get a 200 response but no page content and no errors. Nothing shows up in the PHP or Apache error log, so I'm at a complete loss. I've tried multiple different PHP versions and it doesn't seem to matter.
If I comment out the $page->setContent(ob_get_clean()); line then the page loads but the included files aren't included.
Here is my phpinfo output: http://jsfiddle.net/LeyLcr5f/embedded/result/
Also, a colleague of mine is using the same repo on his machine with MAMP PRO without an issue (we're both running OS X Mavericks).
This looks like a library I've used in the past. Try making sure that the web server has write access to the smarty/templates_c directory.

Laravel not creating log file.

I'm learning Laravel 4.0 to develop a webserver.
I'm using a LAMP stack (Apache 2, php 5.5).
I can't find the log file where Log::error() calls writes to.
As far as I know it's supposed to be to app/storage/logs/log-cli-.txt but there are no files there.
Here is the code:
app/commands/MsgCommand.php
public function fire(){
Log::error('messages - log');
}
It's called from artisan:
app/start/artisan.php
Artisan::add(new MsgCommand());
Am I looking in the right place?
How can I check that this is indeed the right folder (i.e. where is it configured)? To check for faulty installation or setup.
Thanks to marcanuy, I am now sure it is writing to app/storage/logs.
Also I found out it writes fine if I call the command through artisan. Running on apache 2 nothing happens though. I'm starting to think I set up the command wrong.
By default app/storage is the location for log files, storage folder is configured in bootstrap/paths.php
'storage' => __DIR__.'/../app/storage',
Also be sure that this folder is writable by the web server.
The problem was permissions.
User permissions for the www-var user in the ../app/storage
And MySQL settings: Creating a user corresponding to what is set in the app/config/database.php
'mysql' => array(
'driver' => 'mysql',
'host' => 'your host',
'database' => 'your db',
'username' => 'your user',
'password' => 'your pass',
),

Categories