Error when running php scripts on cPanel - php

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.

Related

How to configure local PHP to show directory content

I have a local version of Windows php to test my webpage. I run it using php.exe. It has a built-in webserver so pages can be accessed from a browser through localhost:/path.
If I enter an URL pointing to a file it opens that file in browser. I would like to configure it so that it shows the content of a directory if URL points to a directory. E.g. after inserting URL http://localhost:1234/foo/bar/ into the browser I would want to see the files in the bar directory listed in the browser. Similarly how other webservers do it when configured so.
My local PHP returns 404 instead.
Is there any way how to achieve that for this built-in webserver in php.exe? How?
The built-in server is specifically for quick development and debugging as stated in the command line server doc and directory listing is one of the features is lacks. This answer provides an example for building yours though.

what is the difference of absolute path in html and php?

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.

Dreamweaver CS5.5 Dynamically Related Files

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.

php silently ignoring include on localhost, but not on external server

I'm running Ubuntu 10.04 with Apache2 and PHP5.
I have a directory structure like this:
\www\
\index.php
\parts
\head.php
\body.php
Inside my index.php I have a command
<?php include("parts/head.php") ?>
and the equivalent for body.
These files both exist and they contain more php and html code.
The only thing that shows up when I test the website on localhost (\var\www) is the html outside of the PHP commands. There is no error message, it's as if the file is included but empty.
It is exactly the same as on the website (not localhost) but it works perfectly on the website. I don't understand what is different. Any help would be appreciated.
Check your php.ini file to see if "." is on the path?
You could also try this:
include(basename(__FILE__).'parts/head.php');
It's almost always about permissions. When you have something working locally, and then upload and find it doesn't work (include is ignoring file) check the remote files/folders so that you have read/write/execute permissions set as required. (You can do this in FTP) - then run the script again and it should work.

Apache doesn't execute my copied PHP files, but testing.php works

I've just installed LAMP on my Ubuntu 9.10 machine, and everything works fine except when I copy my PHP files from another computer.
The LAMP guides I've followed also made me create a phpinfo() test file, which works, but when I try to type in e.g. index.php absolutely nothing happens - just a blank page in FireFox. :(
The files are in the exact same directory.
I'm thinking it's probably something with permissions and so on, but since I'm new to both PHP and Ubuntu, I'm kind of lost. It's like I can't create a PHP file with my file browser, but only by using the terminal - like when I created the testing.php from the LAMP guide.
Whaddayaknow... I made an error, tried to:
echo "Hello" world
which, even though I'm a PHP noob, I clearly know is wrong.
I think I'll have to figure out how to enable some sort of error reporting, a blank page is clearly not good enough.
You mean you have a index.php (copied from another computer) and a test.php (edited by hand, with a call to phpinfo()) in the same apache directory, the second works from your browser and the first doesnt ?
That can be a permission issue, or some compilation error in your php.
About permissions, for files should be readable from the apache server (more precisely, form the user that runs the apache server). You can type chmod a+r index.php.
YOu can also check your apache error logs (location dependent on installation). In any case it's vital to know where the error logs are if your are developing a web site.

Categories