I can't find the format file `pdflatex.fmt'! - php

I want to run pdflatex from php on user request.
Running from terminal works fine [php file.php] and creates pdf file. But when I try to run from browser by sending request to php, It gives this error "I can't find the format file `pdflatex.fmt'!"
I am working with php5.2.6, OS is Fedora 9, and safe_mode is turned off.
Code -
$cmd = "/usr/bin/pdflatex /home/deep/public_html/resume/Folder/deependra.tex 2>&1";
$output = exec($cmd);
echo $output;

the pdflatex.fmt must be readable by the web browser in order to be accessible for the exec command, also the server might be chrooted and if so, the chroot folder might not have access to all the pdflatex parts. check it...

Related

Running a blender script on linux hosting

I am currently working on a web app which spits out a .stl file in blender. I have used php and I am calling the script in php using exec(). Please look at the code below. I found the code from
Php: Running a python script using blender from a php project using cmd commands
$script = "C:\\xampp\\htdocs\\test\\test.py";
$blender_path = "C:\Program Files\Blender Foundation\Blender";
$output = exec("cd $blender_path && blender -b -P $script", $data);
echo "<pre>";
print_r($data);
echo "</pre>";
And all works well locally. I uploaded the content to my site(Linux hosting), Uploaded Blender(Linux - https://www.blender.org/download/) changed the paths and nothing happens. It doesn't even output any errors. Is there a separate command line code for linux? I am not used to using Linux and I have been struggling with this for the past 3 days.
Any help is appreciated.
I can think of two possibilities. The first is the path names, on linux there is no drive letters a path should be something like /home/aniket/tests/blendtest
The second relates to running a program, I would expect an error but you may have to look into log files to find it or increase the verbosity of php. The first point is that a file needs permissions set to be executable, this would involve chmod +x blender or maybe using your ftp software to set this, it is often represented as X within a permissions string like RWXRWXRWX. The second point is the way commands are found on a *nix system, there is a PATH environment variable that lists directories to look for a command, the current directory is not in that list by default and I wouldn't expect a hosting company to add it.
$script = "/home/aniket/test1/test.py";
$blendexe = "/home/aniket/blender2.76/blender";
$output = exec("$blendexe -b -P $script", $data);
echo "<pre>";
print_r($data);
echo "</pre>";
On *nix systems ./ represents the current directory, so you may also have luck using
$output = exec("cd $blender_path && ./blender -b -P $script", $data);

wkhtmltopdf not working in php script

I would like to use the wkhtmltopdf for HTML to PDF conversion.
When I have tried to convert it via linux terminal, it works fine.
But when I have tried with the php script it does not work.
I am trying execute the binary directly.
here is the code I am trying with PHP.
exec('/home/binary_loc/wkhtmltopdf http://www.google.com /home/user/output.pdf');
My binary is at the same folder where "index.php" exist.
I have tried to fetch the version of wkhtmltopdf binary with PHP, then it return the version.
But i don't able to understand why not it work to execute with php for pdf.
Here is code for version check using php.
error_reporting(E_ALL);
ini_set('display_errors', '1');
$cmd = "./wkhtmltopdf --version";
$t = shell_exec($cmd);
echo $t;
exit()
Do anyone has solution regarding it??
I want this because this will work in the shared hosting too. No need to install the wkhtmltopdf in the server.
Exec probably doesn't have permission to execute the file. PHP usually runs as either apache or nobody, rather than your user account. You'll have to make sure the execute bit is set for whatever user it runs under. You can use chmod 755 wkhtmltopdf from the directory it's under, to grant read and execute to all users.
Note that on some shared hosting, exec() is disabled. Check with your host to make sure you have access to it.
Define the complete path to the wkhtmltopdf executable and the complete path to the output folder.
To debug try something like this:
shell_exec("/home/binary_loc/wkhtmltopdf http://www.google.com /home/user/output.pdf > /home/user/debug.log 2>&1");
pipe the error in a file

shell_exec to run a Perl file

$cmdOutput = shell_exec("perl run_single_test/hello.pl");
echo "the command output = $cmdOutput";
This causes the file hello.pl to execute and print "hello world back to page". But
shell_exec("perl run_single_test/test_single_run.pl -s \"$testSuiteName\" -t \"$testName\" -i $time");
does not get executed. I echoed the command to screen and ran it on terminal, the Perl script executed perfectly. test_single_run.pl creates a log file and copies a few files.
What am I missing?
Finally figured out the answer.
The test_single_run.pl was modifying a few files in other directories.
I got to know that apache runs the perl script as a different user . In my case it was wwwrun and thus lacked the permissions to operate on other files.
Changed the configuration file uid.conf to make apache run the perl script as my user. And it worked

Generating pdf from webpage in php

how can I execute command wkhtmltopdf http://google.com /tmp/test.pdf from server ie http://localhost/test.php, when I do it from command line it works. I tried system() and exec() functions but did not work. When I use system('touch /tmp/test') file is created. What stops wkhtmltopdf? Is it php, apache?
Make sure that the user the script is running as knows where wkhtmltopdf bin is.
You can find out where it is with the which command.
which wkhtmltopdf
Also you can get the return status of a command by setting a variable equal to it
e.g.
$last_line = system('ls');
echo $last_line

Can't get shell_exec to download a file

I have a multithreaded cli downloader for ubuntu called Aria2c.
I've been trying to get a php script to run aria2c and download a file using shell_exec, but i can't seem to get it to work. Ultimately I plan to have an input box on a page where I can enter a link and aria would download it.
Here's the code I've come up with (for now im inputting the link manually):
<?php $dl = shell_exec('aria2c -d /home/user/ www.downloadlink.com'); ?>
Note that the aria2c command I specified works well in the shell; and the directory I'm attempting to download to is set to '777'.
I'm baffled as to why it's not working, any ideas?
PS: I prefer to use aria rather than the alternatives because it is multithreaded and it supports cookies.
Check if PHP is running in safe_mode. shell_exec won't work if safe_mode is on.
EDIT: aria2c was not referenced with a full path. Referencing it like this: shell_exec('/path/to/aria2c -d /home/user/ www.downloadlink.com') works.
I'll make the assumption that you are running PHP through a web server. In such case, it's very unlikely that the web server has permission to write into your user's home directory: Apache runs as daemon with the credentials of a limited user. Also, the PATH env variable in Apache is not necessarily the same as your user's PATH. Last but not least, you don't check the return value or the script output.
Try something like this:
<?php
exec('/path/to/aria2c -d /tmp www.downloadlink.com', $output, $return_var);
var_dump($output, $return_var);
?>
You can get the full path for aria2c with:
which aria2c

Categories