Log errors to file (PHP + IIS6 + FastCGI + Win2003 Server) - php

Though I have read lots of posts and pages concerning the issue (shown below), I guess I'm missing something here. The mais issue is: my PHP errors are not being logged to the file specified nor to the system event log.
My phpinfo() shows: Windows Server 2003, PHP 5.3.6, log_errors = On, error_log = C:\\errorphp.log
I have tried both error_log = C:\Inetpub\logs\php.log and error_log = syslog in php.ini to no effect (either one at a time).
I have:
restarted IIS after every php.ini change
granted the IUSR_XXXXX User Modify permissions on the folder AND the file
tried leaving the directory blank and letting PHP create the file
had a headache.
Any help is much appreciated.
references:
PHP Manual - PHP on IIS 6
Store PHP errors in a log file
IIS PHP doesn't log errors to log file
My php error log file is empty
Running a defect php file cause error 500
Logging PHP to Windows Event Log

In my case, setting
fastcgi.logging = 1
in php.ini solved the issue and I do have the log file working now (I left the file creation to php itself, my directory was blank)
I'd never guess that as the php.ini itself states (right above the stated config)
; Disable logging through FastCGI connection. PHP's default behavior is to enable this feature.
Go figure.

Have you
checked your error_reporting level
tried setting a log file inside the document root (incl. permission to write) to see if any restrictions apply?

Related

Issue setting server up to log php errors in specified file

I've been combing through my /etc/php/7.0/apache2/php.ini and /etc/apache2/apache2.conf files while trying to set up a specific error log file to dump all the errors in.
Using phpinfo(); I see that /var/www/html/error_log is being used for error_log which is what I want. I set this up in /etc/php/7.0/apache2/php.ini already.
However, php errors are still being placed in /var/log/apache2/error.log
I tried restarting Apache using sudo service apache2 restart yet the issue persists.
Do you have any suggestions for how I can fix this? Let me know if you'd like more information.
PHP can be used and configured by two ways.
First of all the php.ini is taken and all those settings are used in CLI mode, so when you call a script from terminal or console.
Second way is a webserver, in your case apache. This uses either mod_php or php-fpm. Apache is controlled by custom config files which you will find in /etc/apache2/sites-enabled. Depending on how you configure your hostnames, ideally one file per virtual host, those settings will override that from the php.ini. One of commonly overritten values is log file and the access file.
Changing settings in a apache config require a service restart, because apache keeps them all in memory for performance.

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

Linux PHP crashing on error-reporting

Basically, I have an issue whenever PHP should show an error; it won't load the .php file at all.
For example, let's say that I make a mistake while writing:
<?php
function foo($value) { return $value; };
foo(); //missing value, should display a warning or error
?>
That won't show an error, it will just say "This page isnt working".
I checked my php.ini file, but what I found inside seems legit:
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
What could be the cause of this issue? And of course, how to solve it?
You are most probably looking at the wrong error log file.
For PHP there are basically 3 options, depending on what error_log in php.ini is set to. To determine the correct value, add a file with the contents <php phpinfo(); and open it in your browser. This should show a list of all php settings. I recommend this method instead of just opening php.ini because it avoids confusion that might be caused by multiple php.ini and conf.d files.
In that page, search for error_log. This setting determines your log location. If it is not set, that means that PHP is logging to the SAPI interface. Look in your your webserver logs (location depends on OS and used webserver, for Ubuntu and Apache it would be /var/log/apache2/error.log).
If there is a file path in error_log that is the path of your PHP error log. Just open it and the error should be there.
If error_log is set to syslog, PHP logs to your system log. For windows, that is the event log (can be opened by searching for "event log" from the taskbar). For Unix that is the syslog, usually /var/log/syslog but might vary depending on configuration and distro.
Please note that in case you are using php-fpm there are additional FPM log settings, which you also would need to check.

PHP errors : No display & No log

I checked which php.ini is used with phpinfo(), so I'm editing the right php config file.
In that php.ini file (and in phpinfo() details) I have display_errors at On and error_reporting at E_ALL.
BUT when I have a PHP error, most of the time I find no log (in the file specified by error_log, nor in the file specified in apache vhost, nor in /var/syslog), and only a blank page displayed.
I also tried to use the ini_set("display_errors", 1) but that didn't change anything.
One thing was weird, I had no php5 folder in /var/log (I created it, and configured error_log to use it).
Any idea would be much appreciated, that's not so great to code without knowing anything about the errors you have !
P.S. I'm using PHP 5.4 & Symfony2 (using the app_dev.php file), on Debian Wheezy.
Edit : Error logs now work thanks to #martinezjc , but still having a blank page in Apache.
You can create a custom directory, remember to assign apache permission
mkdir /var/log/php-5-4
chown www-data /var/log/php-5-4
The in the php.ini file
error_log = /var/log/php-5-4/php_errors.log
This link talk about more about logs, you can check it http://doc.exyks.org/wiki/Server_php_log_configuration

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