PHP script showing a blank screen - php

I have a server setup where a test script with just phpinfo() works fine.
When I try to run my application on it, it shows up as a blank screen.
I am calling index.php from the browser. The first few lines are as:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once('codelibrary...
Yet, the screen continues to be blank.
Edit 1
Here's the structure of the files:
/.htaccess
/index.php
/codelibrary/inc/user-top.php
/codelibrary/inc/variables.php
/codelibrary/inc/config.php
index.php
<?php
require_once('codelibrary/inc/user-top.php');
...
/codelibrary/inc/user-top.php
<?php
require_once("./codelibrary/inc/variables.php");
...
/codelibrary/inc/variables.php
<?php
include_once('config.php');
...
I thought the referencing here might be a problem, so I changed it to:
require_once("./codelibrary/inc/config.php");
as well, but no luck.
Edit 2
Ah ha! Thanks Col and TopQ for pointing out that I should look at the log file, it says:
[10-Sep-2010 17:06:02] PHP Warning: PHP Startup: Unable to load dynamic library '/usr/local/lib/php/extensions/no-debug-non-zts-20090626/suhosin.so' - /usr/local/lib/php/extensions/no-debug-non-zts-20090626/suhosin.so: cannot open shared object file: No such file or directory in Unknown on line 0

Try setting display_errors from a .htaccess file
php_flag display_startup_errors on
php_flag display_errors on
php_flag html_errors on

Use "view source" in your browser to see if anything is being written by your script that the browser might not be rendering visibly.
EDIT
If you're getting an http 500 response, then you can always do a php lint check on your script from the command line:
php -l <filename.php>
An extremely useful and oft-forgotten check on the syntax of your code.

Check the PHP error log. Usually syntax error or missing dependencies.

The problem is possibly the following: The error occurrs before your script runs (i.e. while parsing. Probably some syntax error). Since your script does not run, the error-level cannot be changed dynamically. You need to set error_reporting in your php.ini, or try fire's suggestion, which should produce equivalent results.

As noted in the other answers here if there is an error present in your script it will fail to set the error levels dynamically.
You can add the proper directives to either the .htaccess file in the current directory, the webserver config or the php.ini file (http://php.net/manual/en/errorfunc.configuration.php). You need to prefix those with the php_flag directive a la php_flag display_errors on.
If you can't add the commands to the .htaccess files it is most probable that your server config does not allow for overrides for those properties. Consult with the server maintainer for either changing these values, allowing you to override these directives on a per-folder basis and having access to error logs for your virtual hosts.

Considering that this is a script that will be executed by a user outside of your group (the browser/webserver) i would think that the file should be set with permissions 755 as this allows the you to make changes and noone else yet ensures that the browser can execute the script (755 -> -rwxr-xr-x)

Related

WordPress: PHP warnings and notices shown even with WP_DEBUG and WP_DEBUG_DISPLAY consts set to false

I've tried setting WP_DEBUG and WP_DEBUG_DISPLAY to false. After that, I've tried following in wp-config:
ini_set('display_errors','Off');
ini_set('error_reporting', E_ALL );
define('WP_DEBUG', false);
define('WP_DEBUG_DISPLAY', false);
Still, PHP warnings and notices are shown on the frontend. I've also checked with ini_get before and after setting ini vars, looks like it's properly set everything, but notices and warnings are still shown.
If I clone website locally or to different host, everything works properly, ie. notices and warnings are hidden. Is there anything else I could try?
This is not a wordpress issue but tied to your server setup and php configuration.
Option 1: Make sure error output is disabled on server side
If you have access to your hosting admin area (... maybe something like plesk or a custom admin ui): search for something like:
error reporting
php settings
php.ini
Usually you'll see some options like:
show only critical errors and omit notices
log errors to a log file
disable all error messages and logging
Nothing?
Contact the hosting provider's support (or web admin), where to set this configuration. (This should actually be default in every hosting environment – even with most basic shared hosting setups).
Option 2: Dirty Hacks/overridung
php-script
htaccess directives
2.1 If your theme has a global header template part/include like "header.php" that's included/required before any html output, you could add a php function like
<?php
error_reporting(0);
<?>
This should work pretty much everywhere – still a temporary solution. If you're using a regularly updated theme – this hack will be deleted after every update.
2.2 htaccess directive
Jeff Starr has elaborated on this approach
If you have access to a .htaccess file you might try to add these directives
# supress php errors
php_flag display_startup_errors off
php_flag display_errors off
php_flag html_errors off
php_value docref_root 0
php_value docref_ext 0
Actually ... not a valid solution either.
.htaccess will only work if you're on an apache driven webserver (even then – based on your apache version, specific compiled version, configuration ... quite a lot of snippets just won't work).
Maybe your website isn't even hosted on an apache webserver but instead nginx or even IIS ... etc.
Before checking other options, you might check your current webserver/php setup by
uploading a test.php file with this content to your root dir
<?php phpinfo(); ?>
Delete this file after checking your setup. In particular interesting wether you're on apache or nginx etc.
Conclusion
Make sure to disable error handling on the server side. So stick with proper server configs and don't waste too much time with any hacks! (... we all need them now and then!)
You can check on your server setting and make error reporting off.May be it will works

How to fix PHP Deprecated Automatically populating $HTTP_RAW_POST_DATA is deprecated issue?

hello i'm getting this error in my error log:
"PHP Deprecated: Automatically populating $HTTP_RAW_POST_DATA is deprecated and will be removed in a future version. To avoid this warning set 'always_populate_raw_post_data' to '-1' in php.ini and use the php://input stream instead. in Unknown on line 0"
My wordpress version is 4.8.1 and the php version is 5.6.30.
I tried fixing the issue by creating a php ini file and setting always_populate_raw_post_data value to -1. But i still get the error.
If it cannot be fixed, how can i prevent it prints on the error log?
I'm using a shared hosting.
how can i prevent it prints on the error log?
Your problem here is not that you cannot access php.ini and it is not that error shows.
Your problem, in fact, is that you use deprecated variable
instead, you could try using
file_get_contents('php://input');
php.ini is located somewhere in the php files on the server, which I assume you have no access to on shared hosting.
The php.ini file you created needs to be located where PHP expects to find its config files. You can see the configs which PHP is already loading using the phpinfo() function:
Upload a file named info.php with the following contents to your web server root:
<?php
// delete this file or comment out the below function when not in use
phpinfo();
?>
Then use a browser to navigate to http://yourwebsite.com/info.php. A page should load which tells you all about your php configuration. Look for the part near the top which shows information about the loaded configuration files. In particular, look for these entries:
"Loaded Configuration File" and "Scan this dir for additional .ini files".
If you have access to the .ini file listed as the Loaded Configuration File simply modify the value for always_populate_raw_post_data there. Otherwise, upload the .ini file you already created to the directory that is scanned for additional configuration files. Of course, you'll need to reload or restart php in order to reparse the configuration files.
If you don't have access to any of the locations listed from the above steps, it's possible your hosting provider may give you access to your php.ini file through cPanel or a similar means. Otherwise, your best bet is to contact them directly.
Finally, if you don't care about the actual configuration value as much as just suppressing the warning message, you could use the ini_set() function to set your error reporting to a different value, eliminating any deprecation warnings. The variable you want to set is "error_reporting" and a list of possible values can be found here.
In addition, since you are running WordPress there are some debug and error reporting options you can set in the wp-config.php file.
If your Account (on the shared hosting) using (or Configured) PHP-FPM, you can't do it via php.ini (if you create php.ini in your root, it will have no effect)
you can try: add this code
<IfModule mod_php5.c>
php_value always_populate_raw_post_data -1
</IfModule>
in your .htaccess file in your root directory, if not helps then ask the server admin (support) to change that in core php.ini globally for the given host.
You cant create a PHP.ini just like that. This is a core config file that is part of the PHP install. http://php.net/manual/en/configuration.file.php Read over this documentation to get a better idea of what the ini does.
The ini file could be located in multiple places depending on the OS and who installed it. If you do not have access to it, talk to your hosting provider

Can't get PHP to report errors

I can't see any PHP errors. I have tried every trick I can find to turn error reporting on, but nothing works.
display_errors is on and error_logging is on, but when I view any page with an error, I get a blank page.
/var/log/php.log does not exist.
if I set a local logfile, Nothing gets created.
The file I have been testing with is
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
ini_set('error_log','script_errors.log');
ini_set('log_errors','On');
$a=
phpinfo();
?>
any other ideas?
You probably need to set it in .htaccess, httpd.conf or php.ini (depending on your server or hosting company). You most likely have a parse error, which means your script never gets to the point where it can turn on the error reporting.
Have you tried editing the actual ini file as opposed to trying to change it at runtime? You can also try using ini_get('display_errors'); to see if your change took effect. If neither of those work I would say your installation is either faulty or very restricted.
Run phpinfo() as the first thing in the script, before you try any of the ini_set options. If your host has those ini functions disabled/restricted, you'll most likely not ever get to phpinfo.
Does the userID the webserver's running under have write permissions in the directory you're running this script from? It could be failing to open your test log file and kill the script that way.
Once you get some phpinfo() output, you'll be able to see if/where PHP is logging errors. It could be going into the server's general error_log, or some other location entirely.
i solved this problem by my hosing website
cpanel-> php config ->display error on

how switch register globals off

my web hosting has the register globals on and I need to turn it off, when using a .htaccess with the following code in the root directory
php_flag register_globals off
I get the following error
Internal Server Error, this is an error with your script, check your error log for more information.
any ideas please.
most likely your host is not allowing that setting in .htaccess files. If you have a php file that is always included you can turn it off there
ini_set('register_globals', false);
If worse comes to worse and you can not disable it, try this psuedo code
Loop through all superglobals
If $var = $_SUPERGLOB[$var] then unset()
Try removing the .htaccess file and placing a php.ini file in its place with register_globals = Off in it.
The 500 server error from a .htaccess file points to php being run as a CGI rather than an Apache Module

php.ini misconfiguration

I've narrowed my problem down somewhat.
When I run "error_log('hey');" from the command line it dumps to STDOUT. But if I run the same code from my web interface (Apache) it puts the error in the error log.
I've checked both ini files, the one Apache is using, and the one in /private/etc (I'm on a Mac running MAMP). Both error_log variables point to the exact same place.
And when I run
echo ini_get('error_log');
The value is the same on the command line as it is in the browser.
What ini setting is misconfigured here? This is quite annoying, as more than just error logging is broken. It's affecting my include paths as well :/
What are you trying to accomplish? Within apache, stderr goes into the error_log... the error_log() function documentation states that by default it logs to the server's error log. If you want to log to a different destination, use the message_type and destination parameters.
You probably need to edit the following config file:
/Applications/MAMP/conf/php5/php.ini
MAMP uses it's own Apache server, which by default runs on port 8080. You probably want to turn off the Apache server in the System Preferences -> Sharing.
Also, try running a PHP file containing:
<?php phpinfo(); ?>
This will tell you which php.ini is actually being read by Apache.
Will
A reason for error_log displaying in the console, and not in the log file might be because of a problem with permissions -- I don't really know MacOS, but as it's UNIX-based, I'm guessing that :
The log file used by Apache belongs to a specific user
When running the script from the console, you are not that user, and you don't have write-access to the log file
If it can't log to the log file, I suppose that error_log is writting to the standard output for error (stderr), which is generally the console.
This comment on the manual's page seems to indicate this might be the cause of your problems (quoting) :
it seems that PHP logs to stderr if it
can't write to the log file. Command
line PHP falls back to stderr because
the log file is (usually) only
writable by the webserver.
Also, make sure the log_errors and display_errors are properly configured in the php.ini file used in CLI :
log_errors boolean
Tells whether script error messages
should be logged to the server's error
log or error_log. This option is thus
server-specific.
And :
display_errors string
This determines whether errors should
be printed to the screen as part of
the output or if they should be hidden
from the user.
Value "stderr" sends the errors to
stderr instead of stdout.
The relevant ini setting here is display_errors.
From the command line a value of On will dump the errors to STDOUT; stderr will divert them to STDERR and Off will suppress them. For Apache only On and Off make any sense.
The odds are that the ini file for Apache has display_errors = Off whilst the one in /private/etc has display_errors = On.
The error_log directive tells PHP where to log errors to, but it also requires log_errors to be set to On, otherwise it has no effect. (Again, chances are the ini file in /private/etc has log_errors = Off.)

Categories