Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial

Roger Clary
957 PointsPHP file won't run on server
Using info gained from the PHP and CSS courses here, I redid a form on my web site. Using the localhost (MAMP) and creating .php and .css files, the design looked and ran on localhost exactly as I wanted it. I UL'ed both files to my hosted server, in the same folder just as they existed on my MBPro, and all I get is a blank page. I am at a total loss as to how to determine what might be wrong. Any hints greatly appreciated.
9 Answers

Michalis Efstathiou
11,180 Pointsyou have to remember that local servers have different settings than hosted servers, hosted servers are usually more strict and you will have to write your code to accommodate that, the first thing you should do is go to your php.ini file on the server and turn on error reporting so that when you open the page it will tell you what errors it encountered and then you can figure out how to fix it, or post here so that we can try and help

thomascawthorn
22,986 PointsTry uploading a really simple php file - nothing else but:
<?php
echo "hello world";
exit;
If you can't see this, then something is wrong on the server side.
If you can see this, it's likely something is wrong with your code.

Michalis Efstathiou
11,180 Pointsroger your php.ini is in your public_html folder
its not hard to find at all
if you are planning to become a developer these are stuff you need to learn, I know its a bit daunting in the beginning but once you do it once then it will seem too easy for you

Michalis Efstathiou
11,180 Pointsits not really necessary to go through all this trouble, once he enables error reporting, the problem might be instantly obvious
for example, when I did my first move from local php dev to the server, it wasnt working either, and from the error I got I immediately realized what it was and fixed it
in my case, I was creating a php session in all my php pages, but because I was using ajax to dinamicly load them, the session variables would clash, and although it worked on the local server it didnt on the hosting server, so I just created an extra php file which had only the session code in it and php pages would call that

thomascawthorn
22,986 PointsFor a simple debugging routine, I personally find it easier to play with the error reporting inline instead of changing the php.ini file.
Adding
<?php
error_reporting(E_ALL);
to the top of your script while you're debugging is almost certainly quicker than going into your php settings.
Although printing the error reports to the screen might solve the initial problem, I point out that having error messages turned on for live isn't fantastic - I think users would rather be greeted with a blank screen than a scary looking php error!! This is why I pointed to using error logs - in my opinion a far more developer and user friendly way of working through warnings and errors etc...
On my various cpanel hosting packages, I can find 'Error Log' on the cpanel dashboard under the 'Logs' tab. Any half decent hosting provider should already have a good error setup for php and be pushing everything into your error logs file. If you have access to your server, the error_log file is usually found in: /etc/httpd/logs/.
The errors logs should show exactly the same message that's printed to the screen.
As with everything code - there's so many ways to complete one task!
Whatever works for you :-)

Roger Clary
957 PointsTom, I have been running much more complicated scripts for a few years now so the hosted server is fine. Michalis: I just spent several minutes in the cpanel trying to find out how to edit the php.ini file to no avail. I'm in waaaay over my head on that. I guess my options are to tear apart the new .php file until it runs or just forget it. Thanks to both for your replies.

thomascawthorn
22,986 PointsWhy not check the errors logs out on cpanel?

thomascawthorn
22,986 Pointsas Michalis Efstathiou mentioned, this would be easier to see if you're showing errors.
I would binary chop all the way down my script, uploading to the server after each move. I.e. at the start, echo "hello"; exit. Move down to below the next significant piece of code and exit again etc.. etc.. This might narrow it down to the break.
I would first check the error logs (which should be a nice big button on the cpanel dashboard) and see if that gives me anything. If it doesn't try this series, specifically the last badge error handling. You shouldn't have to do anything to you php ini file, you can change your error handling in your code.
You can also choose to 'export' your errors codes to a specific log instead of to the page - which brings me back to checking the error logs in cpanel.
Hope this helps

Roger Clary
957 Points"roger your php.ini is in your public_html folder" I looked extensively in public_html, in public.html and in all contained folders. There is no file named php.ini Maybe I need a new hosting provider. Gotta go now, will pursue this again tomorrow. Thanks

Nejc Vukovic
Full Stack JavaScript Techdegree Graduate 51,574 PointsForget the public_html folder: the php.ini is a system file and not a public one. try to find it in the "config" folder (root of your domain folder).
I don't know how your folder structure looks like at you providers side, but should be something with "config".
That's how I normally set my folders when installing a Apache web server, MySql & PHP.
I prefix the config files to the "config" folder of the server root at compile time, just to save me some time with finding the config files.

Roger Clary
957 PointsI did find an error log on the server. Opened it. This is the reported error from the last attempt to run "Form_contact.php". [11-Dec-2014 14:59:55 America/New_York] PHP Parse error: syntax error, unexpected '~' in /home/classon/public_html/forms/Form_contact.php on line 123
I thought, "Great, now I'm getting somewhere." Opened the .php file with Sublime Text. A search for '~' turns up nothing. Furthermore, the file is 107 lines long. There is no "line 123". Incredibly frustrated at this point. Not sure what my next step will be. Thanks to all who have responded for your help.

thomascawthorn
22,986 PointsThat's pretty crazy. What on earth are you doing! Stop doing the bad thing you're doing Roger Clary and everything will be fine.
My process would be:
- Make sure the file on the server is the same as the local file
- investigate the file on the server using cpanels editor.
- binary chop chop chop.
Are you including any other files / is this file being included at any point?