Smarty permissions problems - php

Smarty is complaining about permissions. I've written a small mvc framework for a project I'm working on and I need to be able to render templates in each controller. I went ahead and followed the Smarty installation instructions, and set all of the configuration options in my "front controller", or the page that routes requests to the rest of the application. The testinstall function says everything is kosher, yet when I attempt to render templates in my controllers, I end up with this.
Warning: mkdir(): Permission denied in
/var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php
on line 28 Warning:
rename(/tmp/wrt6piczo,./templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php):
No such file or directory in
/var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php
on line 48 Warning: chmod(): No such
file or directory in
/var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_write_file.php
on line 50 Warning:
include(./templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php):
failed to open stream: No such file or
directory in
/var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_template.php
on line 423 Warning: include(): Failed
opening
'./templates_c/73b1662b4c376f493278f9873564df03430a0b43.file.poopy.tpl.php'
for inclusion
(include_path='.:/usr/share/php:/usr/share/pear')
in
/var/www/HRTRL/includes/CallLog/lib/Smarty/libs/sysplugins/smarty_internal_template.php
on line 423
I have tested the rest of my framework independently and everything seems to work. My "front controller" routes requests properly to the correct controllers, and I seem to be able to render regular HTML just fine.
Additionally, I have chmodded all of the Smarty library folders as well as the other required directories to 777 just for the sake of testing. I'm still receiving the same permissions errors.
EDIT
These are the settings I've used for all the required smarty folders.
$smarty->setTemplateDir('lib/smarty/templates');
$smarty->setCompileDir('lib/smarty/templates_c');
$smarty->setCacheDir('lib/smarty/cache');
$smarty->setConfigDir('lib/smarty/configs');

Proper permissions solved it for me:
chown -R www-data /var/www/HRTRL

Could it be a problem with relative paths? Could you add the complete paths for you set****Dir functions, so you'll be sure you're using the correct locations.
If you call this from a /specialdir/thisdirhasonlyaPHPfile/file.php location, you might get in trouble.

For anyone else dealing with permission issues with Smarty after following all of the above (Checking config/chown/chmod etc...) We came across an issue whilst running Smarty on SE(Security Enhanced)Linux.
The compile/cache directories were sub-directories inside of a ~/tmp directory.
The default targeting policy prevents writes to tmp directories.
You can use semanage to update contexts/policies. You'll most likely need to create a new policy to assign the httpd_sys_rw_content_t context to the directory your web-app needs to write too.
More information:
http://www.serverlab.ca/tutorials/linux/web-servers-linux/configuring-selinux-policies-for-apache-web-servers/
t

Simply comment the following line from the index.php file.
$smarty->caching = true;
This will solve your problem.

You should check again access permission for write.
I had the same errors, so I have set permissions to 777 for 'templates_c' folder and anything inside of it and now it works.
However I had to repeat this operation for 3 times in Filezilla, don't know why it didn't change the permissions at once.

According to the documentation, permission of 'template_c' folder should be 775. But it does not work sometime. You have to set its permission to 777.

Related

How to place a custom PHP file in the cPanel root folder

I have a custom PHP file that needs placing in a the cpanel/root folder. Any root folder, be it newly created or /usr/local/cpanel/scripts/.
This is the error I got, when I placed it in one of my accounts:
PHP Warning: opendir(/var/named/): failed to open dir: No such file or directory in /home/****/public_html/cpanel-slave-zones-add.php on line 46
This the response I got from the script developers:
The "ZONES_DIR" is pre-defined in the PHP file as "/var/named/". However, since you are received such error, we recommend you to place the script into the root directory ("/").
Do you know where should I put this script, so it can function properly? Do you know, ways to go about?

Cannot include php files from root using subdomain

I have recently made an API now for that api i have made a subdomain however it broke my php file includes
include $_SERVER['DOCUMENT_ROOT'].'/core/init.php';
now my subdomain i am using is api.website.com and i need to include something from website.com when i try to include its giving the root of the subdomain,
Summary
When i try to include init.php i get
Warning: include(/home/website/public_html/API/core/init.php): failed to open stream: No such file or directory in /home/website/public_html/api/apex/getusers.php on line 2
When i actually need
Warning: include(/home/website/public_html/core/init.php): failed to open stream: No such file or directory in /home/website/public_html/api/apex/getusers.php on line 2
I apologize for my grammar if need be.
Changing your include path to
include ("../../core/init.php");
will fix your problem. However, this is not a recommended approach.
You should think about using a dependency manager like composer. ( https://getcomposer.org/ ). Then your included files will always be under a directory like
/home/website/public_html/vendor/core
and there will be less of a chance of your application breaking if the files in /home/website/public_html/core change.
This should work.
include("../core/init.php");
Use following code
include_once $_SERVER['DOCUMENT_ROOT'] . '/../core/init.php';
visit https://developer.hyvor.com/php/including-files-in-root-with-subdomain.php to learn more.

Moving yii project to another machine

I have a project, build in Yii Framework , in my machine 1.
Now I moved my whole project to new laptop.
But it's not running and displaying some error:
Warning: require_once(D:\xampp\htdocs\rpadmin/../framework/yii.php): failed to open stream: No such file or directory in D:\xampp\htdocs\rpadmin\index.php on line 11
Fatal error: require_once(): Failed opening required 'D:\xampp\htdocs\rpadmin/../framework/yii.php' (include_path='.;D:\xampp\php\PEAR') in D:\xampp\htdocs\rpadmin\index.php on line 11
Does anyone know what is happening?
You need to edit in your project the file index.php and change the line:
// change the following paths if necessary
$yii=dirname(__FILE__).'/../framework/yii.php';
$config=dirname(__FILE__).'/protected/config/main.php';
with your Yii Framework path location.
If you have framework folder in the same location with the project, you need to change like this:
$yii=dirname(__FILE__).'/framework/yii.php';
actually u have folder of yii(framework named folder) framework outside the rpadmin folder now u have to upload it from your local machine to the server and put it outside the rpadmin from... the error message ...
Warning: require_once(D:\xampp\htdocs\rpadmin/../framework/yii.php):
so there will be a framework named folder....
after that make some changes
Give rpadmin/protected/runtime permission 777
If its ISS the you have to give rpadmin/assets folder permission 777
change the required settings in rpadmin/protected/config/main.php if theres only like db connection

Symlink - require_once doesn't seem to work?

I store my WordPress theme in my Dropbox to use it easily on many machines. Unfortunately require_once()/include_once() doesn't seem to work for me.
Is store original theme at G:\Dropbox\Dropbox\Wordpress\Themes\Blabla\
The symlink is placed at C:\xampp\htdocs\blabla\wp-content\themes\Blabla
When I wanted to require/include any file, eg. C:\xampp\htdocs\blabla\wp-load.php I used to do require_once('../../wp-load.php');
But with symlink all I got is:
Warning: require_once(../../../wp-load.php): failed to
open stream: No such file or directory in
G:\Dropbox\Dropbox\Wordpress\Themes\Blabla\foo\bar.php on line
2 Fatal error: require_once(): Failed
opening required '../../../wp-load.php'
(include_path='.;C:\xampp\php\PEAR') in
G:\Dropbox\Dropbox\Wordpress\Themes\Blabla\foo\bar.php on line
2
Looks like require_once looks for the file within the Dropbox, not symlink context? Is it possible to fix it somehow? I can't use absolute path as I develop on different machines / different OSes and those vary... Any ideas? How does require_once work when it's symlinked? Does it look for required file in both places (original-context & symlink-context)?
How about putting the original file into you Wordpress folder and symlinking to dropbox?
While installing this, you should turn off dropbox on all machines where you did not move the folder yet.

Web application not finding file in what appears to be the correct path

I tried to reorganise my facebook application files into better folders and now when I try to load my application on facebook it throws the following error:
Warning: require_once(../scripts/mysql_connect.php) [function.require-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3
Fatal error: require_once() [function.require]: Failed opening required '../scripts/mysql_connect.php' (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\<root folder>\Model\Database.php on line 3
The second error is a result of the failure of the first one I think. The weird thing is that my program works perfectly fine when I'm accessing through the localhost url in the browser but when I run it through facebook it throws this error.
In my root folder I have a "Model" folder where the Database.php file is kept and a "scripts" folder where the mysql_connect.php file is kept. I have tried clearing my cache on the browser and using private browsing but it is still throwing this error.
Does anyone know what could be wrong?
EDIT: Sorry this does not seem to be working in localhost either now! One thing I think is weird is that it says "failed to open stream : NO SUCH FILE OR DIRECTORY IN" and then lists the database.php path. Why is it looking in there?
I use the line require_once('../scripts/mysql_connect.php'); at the top of my Database.php file to include it.
It seems that on the server there is a different working directory. Something like the following owuld be a quick fix
dirname(__FILE__) . '/../scripts/mysql_connect.php'
Ok I've fixed this, but I'm still unsure why it was a problem. In my root folder I have two folders: scripts, and Model. I have a database.php file in my Model folder which has the following line of code in:
require_once('../scripts/mysql_connect.php');
For some reason this did not work, but by replacing the line with:
require_once('/scripts/mysql_connect.php');
This started working again! Just thought I would post the solution. Does anyone know why the other way failed? I thought the ".." just makes it go up one level in the folder hierarchy i.e. to the root folder in this case, and then follow the path which would have taken it to the file...
EDIT: This appears to only have solved it for localhost and not through Facebook...
Do you have permission to edit your php.ini file? One solution would be to find the line with the include path (you'll notice it has C:\xampp\php\PEAR in there already). Include the full path to the "scripts" folder you're referencing, then you can change the php code to read:
require_once('mysql_connect.php');
PHP will be able to find this file since it's in the include path. Just make sure that if you start adding several include paths that you shouldn't have a file named mysql_connect.php in two or more of the different include paths because you'll most likely get errors. Hope this helps. It definitely makes for some cleaner code.

Categories