I have web game that I have designed for a Uni project that uses a MySQL database and the Smarty template engine.
Locally, the package functions perfectly. However, I have tried to host it online so that my lecturer can test it, and it's failing.
I have duplicated my htdocs folder on my server, but if I try to access the index page, I get the below error:
Fatal error: Uncaught --> Smarty: unable to write file /opt/bitnami/apache2/htdocs/SWDB/vendor/smarty/templates_c/wrt5ec521ffb8fad9_62962337 <-- thrown in /opt/bitnami/apache2/htdocs/SWDB/vendor/smarty/sysplugins/smarty_internal_runtime_writefile.php on line 60
which is included in the below portion of code from the smarty_internal_runtime_writefile.php file:
// write to tmp file, then move to overt file lock race condition
$_tmp_file = $_dirpath . DIRECTORY_SEPARATOR . str_replace(array('.', ','), '_', uniqid('wrt', true));
if (!file_put_contents($_tmp_file, $_contents)) {
error_reporting($_error_reporting);
throw new SmartyException("unable to write file {$_tmp_file}");
}
/*
Related
I am trying to create pdf with Laravel snappy.
The problem is when I try to run wkhtmltopdf command in the console for example:
wkhtmltopdf http://google.com google.pdf
it works fine and generates pdf.
But when I try to generate pdf in my controller, then it throws this exception:
RuntimeException
The file
'/home/alemil/Projects/test/storage/app/annual_reports/Pdf test.pdf' was not created
(command: /usr/local/bin/wkhtmltopdf --lowquality --orientation
'landscape' --page-size 'a3'
'/tmp/knp_snappy5bb49cd6bfcf14.16728595.html'
'/home/alemil/Projects/test/storage/app/annual_reports/Pdf test.pdf').
I tried to copy command above and execute directly in console. This is what I get:
Loading pages (1/6)
Error: Failed to load http://tmp/knp_snappy5bb49cd6bfcf14.16728595.html, with network status code 3 and http status code 0 - Host tmp not found
Error: Failed loading page http:///tmp/knp_snappy5bb49cd6bfcf14.16728595.html (sometimes it will work just to ignore this error with --load-error-handling ignore)
Exit with code 1 due to network error: HostNotFoundError
As I can see, it tries to fetch local file as it is remote. I couldn't find this issue so I am asking if someone can solve this or has any idea.
My environment is Ubuntu 18.04 PHP and PHP 7.2.10.
This is my code:
// app.php aliases
'PDF' => Barryvdh\Snappy\Facades\SnappyPdf::class,
// controller code
PDF::loadView('admin.reports.annual.pdf_template', $data)
->setPaper('a3', 'landscape')
->save(
storage_path('app/annual_reports/') . $report->pdf,
true // when there is file with same name it throws file already exists so I had to set owerwrite to true
);
Also, one more thing to point out, I was using barryvdh/laravel-dompdf and everything was working fine except it cannot render charts so I'm now trying to set up snappy.
In my case the problem was that I passed null in $html to Knp\Snappy\Pdf::getOutputFromHtml($html). Under the hood it cheks if $html !== null and creates a temporary file for further PDF generating. If temporary file doesn't exist wkhtmltopdf throws error like described in question.
hmm
I think (not sure) that there are a a blocking in your application that blocks your controller from getting to the link. Or at the creating of the PDF.
It can also be your code syntax.
you can try this for html :
$pdf = new Pdf('/usr/local/bin/wkhtmltopdf');
$pdf->generateFromHtml('<h1>test</h1><p>test from test</p>', '/tmp/test-123.pdf');
i created a script in order to insert some articles via a php script. This script is working on my local machine (xampp), but when i deploy the whole joomla project to my web server i get the following error message:
Error displaying the error page: Application Instantiation Error: Application Instantiation Error
By adding some echo calls, i was able to find the line which causes the error:
$app = JFactory::getApplication('site');
Now i am wondering how to fix this behaviour and make my function also run on the web server.
Below i will provide my system informations and the beginning of my php function until the line, which causes the error message:
Systeminformations
joomla version: 3.6.5 Stable
db version: 5.6.34-79.1-log
php version: 5.6.30-he.0
web server: Apache
PHP snippet
<?php
echo "STARTING; ";
// get db connection
include('../includes/mysql.inc.php');
// get all sql querys
include('./autoNewsQuerys.inc.php');
/**
* Prepare joomla framework to insert article correctly
*/
if (!defined('_JEXEC')) {
define('_JEXEC', 1);
define('JPATH_BASE','/is/htdocs/wp1088688_4E1H7PYJFK/www');
require_once(JPATH_BASE . '/includes/defines.php');
require_once(JPATH_BASE . '/includes/framework.php');
defined('DS') or define('DS', DIRECTORY_SEPARATOR);
}
echo "searching app;";
$app = JFactory::getApplication('site');
echo "Found app;";
Full browser output
STARTING; searching app;Error displaying the error page: Application Instantiation Error: Failed to start the session because headers have already been sent by "/is/htdocs/wp1088688_4E1H7PYJFK/www/1500AutoNews/autoNews.php" at line 3.
So as you can see the error is caused by the JFactory call. 'Found app' is never printed out.
Just copy the Joomla index.php file to another file and then replace the $app->execute code with your code.
Note: You don't need to include any MySQL library - since you are loading the Joomla environment then you have access to the JDatabase class, which is a database abstraction layer.
Another note: this file autoNewsQuerys.inc.php likely contains some issues (maybe you are trying to instantiate the app there, but the Joomla environment hasn't loaded yet). You should move it to the end.
if it was working on localhost and it is not working on Web server then the biggest issue is with defining the base path. Give a hardcoded base path of your joomla installation. I suggest you to check your base path using a php script. Create a php file and name it path.php. Put it in the Joomla main folder. Content of the file
<?php
echo "The Base path is ".getcwd();
?>
Once you get the path just change the Base_Path. For ex:
define('JPATH_BASE', '\var\www\joomla');
I have a website in zend framework which is install in another server. Now I have purchase a new server in ubuntu with Zend Engine 2.3.0 . I have installed Apache server, MYSQL , PHPMYADMIN Tool on this server. Then I upload all the files on previous server to the new server. I have also change the urls in the index.php files.
But it is giving me error.
**Uncaught exception 'Zend_Session_Exception' with message 'Zend_Session::start() - /var/www/sample/library/Zend/Session.php(Line:477):Error #2 session_start(): open(/vlk_session/sess_ielitiholu4219p3nph6lkk8n6, O_RDWR) failed: No such file or directory (2) /var/www/videoliked/library/Zend/Session.php(Line:487): **
This is my below code of index.php file
Zend_Layout::startMvc($options);
Zend_Session::setOptions(array('save_path'=>'/vlk_session'));
if(isset($_COOKIE["Zend_Auth_RememberMe"]) && $_COOKIE["Zend_Auth_RememberMe"] !== false){
Zend_Session::rememberMe("5302000");
setcookie("Zend_Auth_RememberMe", false, time(), "/");
}
if(!Zend_Session::isStarted()){
Zend_Session::start();
}
The save path is absolute.
Did you create the folder /vlk_session on your server?
I'd suggest to use and create
/tmp/vlk_session
Instead, or lookup the PHP default folder for sessions in your php.ini and use the one suggested by vendor.
Update:
Make sure the PHP instance is allowed to read/write that folder.
I've created a phar of a Symfony2 web application, but I'm having some troubles with the cache-folders.
I found out that I could mount an external file/folder into a phar. That would fix my issue, but I can't get the example on the PHP site working.
I have a phar which contains an index.php:
<?php
$configuration = simplexml_load_string(file_get_contents(
Phar::running(false) . '/config.xml'));
?>
Then I include the .phar with the following code:
<?php
// first set up the association between the abstract config.xml
// and the actual one on disk
Phar::mount('phar://config.xml', '/var/www/$projectname/config.xml');
// now run the application
include 'phar-archive.phar';
?>
All files exists, but I get the following error:
PHP Fatal error: Uncaught exception 'PharException' with message 'config.xml is not a phar archive, cannot mount' in /var/www/$projectname/index.php:3
I already tried relative/absolute paths, changing permissions but can't get this to work. Additionally a working example of how I could mount a folder into a phar would be great !
First check that variable $projectname exist in this place (just run echo $projectname; before Phar::mount). If all ok, then change
Phar::mount('phar://config.xml', '/var/www/$projectname/config.xml');
to
Phar::mount('phar://config.xml', "/var/www/{$projectname}/config.xml");
It seems that variable $projectname not converted to its value because you used single quotes.
im a PHP newbie . .
i've tried to make a PHAR of my project.
my project include 5 directories and multiply classes within each dir.
I've followed this tutorial
Phar – PHP archiving practice
and i did the following:
to my main index.php i added this lines:
$sLibraryPath = 'lib/myPhar.phar';
// we will build library in case if it not exist
if (! file_exists($sLibraryPath)) {
ini_set("phar.readonly", 0); // Could be done in php.ini
$oPhar = new Phar($sLibraryPath); // creating new Phar
$oPhar->setDefaultStub('index.php', 'classes/index.php'); // pointing main file which require all classes
$oPhar->buildFromDirectory('classes/'); // creating our library using whole directory
$oPhar->compress(Phar::GZ); // plus - compressing it into gzip
}
and i created a new folder called classes , and created a index.php file within it, and there i included all my project classes.
i've chmod 777 the following directories: lib, HelloWorld , HelloWorld/index.php ,
and changed the phar.readonly. (phar.readonly = 0)
still i get this message:
Fatal error: Uncaught exception 'PharException' with message 'unable to create temporary file' in /Applications/XAMPP/xamppfiles/htdocs/HelloWorld/index.php:10 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/HelloWorld/index.php(10): Phar->setDefaultStub('index.php', 'classes/index.p...') #1 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/HelloWorld/index.php on line 10
i havent found any helpful info what to do with it, and i will glad for your help.
(if there is a better way to create PHAR it will be fine)
I'm not sure if it is the point, but check this link Bug #63112 PharException when compiling
May be you have the same trouble with temp directory?
Use the PHP2Phar package to create your Phar file from PHP files.
Link:
https://github.com/00F100/php2phar
Usage:
$ php php2phar.phar --dir-source <path/to/dir> --index-file </path/to/index.php> --output-file <path/to/file.phar>