I am having trouble getting the Smarty Template Engine to work correctly on my local test server. I have it set up like this:
<?php
// put full path to Smarty.class.php
require('smarty/Smarty.class.php');
$smarty = new Smarty();
$smarty->testInstall();
$smarty->setTemplateDir('smarty/templates');
$smarty->setCompileDir('smarty/templates_c');
$smarty->setCacheDir('smarty/cache');
$smarty->setConfigDir('smarty/configs');
$smarty->assign('name', 'Ned');
$smarty->display('index.tpl');
?>
However, I keep getting this error:
Fatal error: Uncaught exception 'SmartyException' with message 'Unable to load template file 'index.tpl'' in /var/www/WEBSITE/smarty/sysplugins/smarty_internal_templatebase.php:127 Stack trace: #0 /var/www/WEBSITE/smarty/sysplugins/smarty_internal_templatebase.php(374): Smarty_Internal_TemplateBase->fetch('index.tpl', NULL, NULL, NULL, true) #1 /var/www/WEBSITE/test.php(13): Smarty_Internal_TemplateBase->display('index.tpl') #2 {main} thrown in /var/www/WEBSITE/smarty/sysplugins/smarty_internal_templatebase.php on line 127
I used the testInstall function and this was returned:
Smarty Installation test...
Testing template directory...
/var/www/SteamKing/templates is OK.
Testing compile directory...
FAILED: /var/www/SteamKing/templates_c is not writable.
Testing plugins directory...
/var/www/SteamKing/smarty/plugins is OK.
Testing cache directory...
FAILED: /var/www/SteamKing/cache is not writable.
Testing configs directory...
FAILED: ./configs/ does not exist.
Testing sysplugin files...
... OK
Testing plugin files...
... OK
Tests complete.
I went through the whole making sure the folders are actually writable and everything but I still get the error. Any ideas?
Well for one thing the paths to your templates are wrong where you're assigning paths. The path is /var/www/SteamKing not smarty/
It's usually a good idea to use absolute paths so you can move your files around without worrying about where your templates go.
As for why your cache and template_c is not writable you need to show the actual paths or show the command you used to try to make them writable.
Related
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}");
}
/*
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>
I am trying to get Smarty setup and working, so that I can install the open-source project here
http://sourceforge.net/projects/assign-calc/
After following the install instructions, I get stuck with the following error message
<b>Fatal error</b>: Uncaught exception 'SmartyCompilerException' with message 'Syntax Error in template "/var/www/dev/calendar/skins/rpc/tmpl/page/rpc_header.tpl" on line 5 " {$application.long_name|escape}" unknown modifier "escape"' in /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_templatecompilerbase.php:423
Stack trace:
#0 /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_compile_private_modifier.php(62): Smarty_Internal_TemplateCompilerBase->trigger_template_error('unknown modifie...', 5)
#1 /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_templatecompilerbase.php(279): Smarty_Internal_Compile_Private_Modifier->compile(Array, Object(Smarty_Internal_SmartyTemplateCompiler), Array, NULL, NULL)
#2 /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_templatecompilerbase.php(123): Smarty_Internal_TemplateCompilerBase->callTagCompiler('private_modifie...', Array, Array)
#3 /usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_compile_private_print_expression.php(68): Smarty_Internal_TemplateCompilerBase in <b>/usr/lib/php5/Smarty/Smarty/sysplugins/smarty_internal_templatecompilerbase.php</b> on line <b>423</b><br />
After a bit of googling, I think the problem is being cause by Smarty not reading the escape modifier in the plugins directory.
How do I resolve this? I've even tried 777 the permissions on smarty, but that hasnt change anything...
Have you loaded the smarty configuration correctly? In particular, have you setted correctly the plugin path, through the command
$smarty->addPluginsDir('path/to/plugins');
?
I'm the developer of the Research Project Calculator, and found this SO question while researching the same problem for another user. The code has only been in the wild for a few weeks and we're discovering some of these things as other institutions install it.
I was able to get it running for the other user by explicitly calling parent::__construct(); before anything else in the inc/rpc_smarty.inc.php class constructor. I'll post a new release shortly, but for now you should just be able to patch that constructor as below.
Please feel free to contact me via the link in the project's installation instructions wiki page if you have more questions or run into other problems.
public function __construct($config)
{
parent::__construct();
$this->config = $config;
...
...
}
An absolute system path is the fastest and safest approach. You can use relative paths, but be certain the php include_path contains what is needed to find it. You could also use SMARTY_DIR to base your path from.