I have the following code in a php/html file:
<?php
include('sample.php');
include_once('foo.php');
include('bar.php');
?>
On my dev server (php's built-in server), everything is working fine, on the production server (apache2) though I get a blank page when accessing the file.
The only way to get to the actual page is by removing all 3 includes, removing a single one or two of them does not resolve the problem. In the included files I do include files, which might get loaded more than once with include_once. Apart from that I have no glue why there is an error since everything is working on my dev server and some of the included files work well in other parts of the app.
It is probable that the configuration of include_path on your dev server contains ., which means: if file is included with relative path, try to find it in the current directory. This setting is probably not present on the prod server (see for yourself with phpinfo()).
Related
I've uploaded my site files to ../public_html directory in cPanel. PHP scripts are in cgi-bin folder, each has 0755 privileges set. Domain is set up.
Html, css and javascript work fine but I get Internal Server Error when I try to execute any of php scripts.
I've tried adding
ini_set("include_path", '/home/*%username%*/php:' . ini_get("include_path") );
to each php source file (as was suggested in the PHP section of cPanel). But I keep getting the same error and the adress bar shows http://%domain-name%/cgi-bin/%script-name%.php
cPanel Error log doesn't show any errors.
cPanel documentation was completely unhelpful (for a beginner like me).
What do I have to do to make the scripts run as intented?
The problem was with relative paths in html files. For some reason they were interpreted differently than on Windows with XAMPP.
I had to write all paths to php scripts starting with / (as relative to the home directory not the html file). And in php scripts I had to write paths to resources as relative to the php file. (Thanks #Sky for pointing me in the right direction.)
This is all very confusing and getting it right involved lots of tweaking.
I am using the php page includes in my site, it's perfectly working without error in localhost, but at the time of running this with a live web server it shows the error.
with using these functions
include("http-url/file.php") and required_once("http-url/file.php")
they are shows error like this
Warning: include(): http:// wrapper is disabled in the server
configuration by allow_url_include=0 in
www.mysite.com/....
with file inclution.........
what to do to solve this issue
Many developers include files by pointing to a remote URL, even if the file is within the local system. For example:
<?php include("http://example.com/includes/example_include.php"); ?>
With allow_url_include disabled, this method does not work. Instead, the file must be included with a local path, and there are three methods of doing this:
By using a relative path, such as ../includes/example_include.php.
By using an absolute path (also known as relative-from-root), such as /home/username/example.com/includes/example_include.php.
By using the PHP environment variable $_SERVER['DOCUMENT_ROOT'], which returns the absolute path to the web root directory. This is by far the best (and most portable) solution. The following example shows the environment variable in action.
Example Include
<?php include($_SERVER['DOCUMENT_ROOT']."/includes/example_include.php"); ?>
More about allow_url_include here
I've been working on a development LAMP server for some months with no issue.
Recently, whenever I update a file on the webserver, the changes I make are not taking affect. I've confirmed that the modified file has been uploaded to the filesystem from a shell, but none of the additions are taking effect when I run the file in a browser.
Anyone have any idea of what this could be?
EDIT:
Okay I found the issue. The file I was making an update to was a PHP include in another folder. At the top of the parent file was this line:
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . '/usr/share/xxxx/zzzz');
For unknown reasons, this stopped working (possibly the include_path in the ini was somehow changed).
I had to change the PHP includes to contain the full path to the includes and then my updates began to work.
You can see cached version (try to to force refresh - CTLR-F5) Or you changing the files in the different location than they are being served from. Check your httpd config and see if both location matches.
I am developing a website on php, I have installed wamp on my personal computer and my website files are in the www folder of wamp.
now considering www as my root folder i have a template folder in the root folder and header.inc.html file in the template folder. when I try to include this header.inc.html file in any other php file using an absolute path include('/template/header.inc.html'); it gives me error "Failed to open stream: No such file or directory", but when I create a simple html link using the same absolute path it works perfectly and opens the file. below is my test code
<?php
echo 'headerfile';
include('/template/header.inc.html');
?>
if I give the full path for example C:/wamp/www/template/header.inc.html to the include function it works fine.
I am confused that this problem is occurring on my wamp server only and it would work perfectly on any webhost server, or maybe the same problem will exist on a webhost
I would appreciate any help that would clarify my confusion, Thanks.
Absolute paths on the server start from the server's hard disk (C:\).
Absolute paths on the client start from the root of the website (http://example.com/).
You can make use of __DIR__ to make some file on disk relative to the php-file on disk itself:
include(__DIR__.'/template/header.inc.html');
This should solve your issue.
The difference is not that easy to explain because both types of paths - even related - are two pair of shoes. I suggest you start with a very basic HTML website tutorial that explains how to link on your website and where files are located and how that is related to the webserver configuration.
HTML pages live in the client's browser that know nothing about your server's folder structure, and they're relative to the domain name eg. http://example.com/.
PHP programs run on the server side and they deal with the server folders. You shouldn't hardcode full paths in your php programs, because it will cause problems whenever you'll move them between the development server and the live host (just to name an example). Therefore in php files you should either use relative paths to your file, or use the __DIR__ magic constant that gets substituted with the directory where the php file is.
1.) First approach: include('template/header.inc.html');
2.) Second approach: include(__DIR__ .'/template/header.inc.html');
In your case (working on a development machine) both the client and the server is the same box, that might be confusing you.
I'm trying to use Dreamweaver with an existing code base (not WP, Drupal, or Joomla!) in a PHP/MySQL site. I continue to receive "Dynamically related files could not be found because of an internal server error." I've been googling all day and have read plenty of WP-specific solutions, including the thread on this site. I've tried all the methods listed, no luck.
Setup Info
MAMP 2.0.1
Mac OS X 10.6.8
Dreamweaver CS 5.5
Site's local address: /Users/myName/Sites/siteName
Testing server address: /Applications/MAMP/htdocs/siteName
Attempted solutions:
1) added library to site root (/Users/myName/Sites/siteName/library)
2) added library to MAMP root (/Applications/MAMP/library)
3) added include path for both locations to applied php.ini listed in phpinfo
4) set Dreamweaver to use Site Root paths instead of page-relative paths
5) switched back to page relative paths
6) Restart MAMP, reset ports in Preferences to 8888/8889, or 80/3306
7) checked site info to make sure paths are correctly defined
When I insert the following code, or any require function with a relative path, live view and preview in browser display empty pages.
<?php require_once('includes/initialize.php'); ?>
I'm incredibly frustrated. I had been using XAMPP and a plain text editor for previous work and never had an issue with relative paths. Any help would be appreciated.
Answering my own question; bad form, I'm aware.
EDIT:
Adding to previous list of attempted solutions:
8) tried designating the server ports as 8888/8889 and defining server route as http://localhost:8889/mySite/, like setting up a Drupal/WP/Joomla! testing environment.
9) Uninstalled/Reinstalled MAMP, Dreamweaver, disabled the out-of-the-box Apache server included with OS X, the redefined the site in Dreamweaver.
Fix attempt 8 led to packet error discussed here. Fix attempt 9, plus error reporting that hadn't been working, but did now:
// Report all PHP errors (see changelog)
error_reporting(E_ALL);
showed that the testing server was using the local definition to refer to dynamically related files and, even though that should work, it wasn't working.
After reinstall, created new site with "Site > Manage Sites" and defined Local Site Folder in "Site" menu and the Server Folder in the "Server" Menu as the same directory. (/Applications/MAMP/htdocs/mySite)
Refer to the Setup info in the OP to see my system variables; this may be specific to any/all settings. But only identical local definition and server definition solved the problem. I've recreated previous settings to be sure, and different local/server definitions don't work.
This error can happen with Dreamweaver and PHP sites if the contents of the included file make additional dynamic calls using PHP syntax that Dreamweaver doesn't recognize. Without seeing the contents of initialize.php, I can't be 100% sure this is the case but I am pretty sure that DW is not able to parse the code there and figure out what files to get for display.
Problem Dynamically related files that I see a lot of people run into:
Dreamweaver is scanning whatever is in you Local Copy, it should be a the full installation of WordPress. If you're working locally, download everything on your "Testing server" to your "Local view" in the Files panel.
If you're working with two sets of files, your local copy and what is in MAMP's htdocs or on your "Testing server" should be nearly identical, except for what you're working on of coarse. That's the problem I see people have.
If you're working in kind of "pho-FTP" environment.