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?
Related
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.
I'm working on making my web app more portable but I'm having trouble with making links in a sub-directory root-relative.
/website - Let's say that's my directory for the website. /inc -
That's my includes directory for header, footer, and eventually my
config file.
Everything inside the website directory works fine.
I'm trying to include my header/footer files in a receipt directory with..
include("/website/inc/header.php");
but I get..
Warning: include(/website/inc/header.php): failed to open stream: No
such file or directory in F:\xampp\htdocs\website\receipt\index.php on
line 8
Warning: include(): Failed opening '/website/inc/header.php' for
inclusion (include_path='.;F:\xampp\php\PEAR') in
F:\xampp\htdocs\website\receipt\index.php on line 8
in my browser. I've tried removing the / and even adding localhost and htdocs (which was just a desperate attempt at getting it to work). What am I doing wrong and how can I correct it?
That's because a file path starting with / is treated as a file path starting from the root of file system. You have F:\ as a root that's why such a directory doesn't exist.
In your case you have to do something like ../../website/inc/header.php but that depends on the location of the folder where your script resists.
PHP (but not HTML!) works with whole file system, while HTML works only with the site's home directory.
By the way, such file paths are not allowed on Windows, they're only available on UNIX-like systems. If such a construction with /'s works on your server, that's strange as Windows has \ as path separator. Your code'll look like ..\..\website\inc\header.php. Note that you may need to escape the backslashes by adding another backslash like this \\
I have one root folder called GASS where I put all my php files and other related folders (templates,images,js,fonts,css)inside. When i try to run my project in localhost, http://localhost/GASS/alarm_A16GSM.php everything went smoothly. I wanted to change the URL to be more specific, http://localhost/GASS/alarmsystem/16zone/A16/overview.php thus i rename the php file and put it inside folders.
GASS
alarm-system
16-zone
A16
overview
However when i try to run the new URL,the page shows error.This is the error message:
Warning: include(templates/header.php): failed to open stream: No such file or directory in .....
Code for the first URL where the page load successfully.
<div class="overview"><a href="alarm_A16GSM.php" id="overview-selected"><span>
Code for the new URL where the page shows error.
<a href="alarm-system/16-zone/A16/overview.php" id="overview-selected">
It seems like i need to configure something which i do not know what it is.
How am i going to load the page successfully using the new URL? How am i going to traverse four levels up to the root directory so that the page load successfully? Why i cannot directly call the php file using the(alarm-system/16-zone/A16/overview.php) path?
p/s: sorry for my bad English.
It looks like there is a line in your Php file, probably like
include 'templates/header.php';
Include can't find the file using that relative path, because you moved the calling file.
Probably you could change that to
include '../../../../templates/header.php';
To get back down to the GASS folder that apparently has a folder called 'templates' with a file 'header.php' that is required.
An absolute path would be good, instead but it refers to the filesystem path, not webserver path - so you'd need to know your web root folder name on the server.
Copying all the folders (templates,images,js,fonts,css) to the folder overview will solve the issue. Now there is no template file on the folder 'overview' so header.php is failed to load. Another option is create a file save all the included file path and call this file.
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.
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.