Apache - PHP errors logged with escaped n - php

Basically the same problem as this question but the suggested fixes are not working:
PHP error log and newline chars
Error logs are being written by Apache like this:
ErrorLog "|/usr/sbin/rotatelogs /var/www/logs/error_log.%Y-%m-%d 86400"
But the PHP errors in the logs are full of \n where there should be a new line.
I have tried setting the ownership of the logs folder and the logs file to "apache" as suggested in the other question but this doesn't help.
The server is running php-fpm. Note if I chose to use php-fpm logging php_admin_value[error_log] = /var/log/php-fpm/www-error.log then the logs that are created are correct, but this is a general log and not suitable for the server running multiple sites.

Related

PHP Error logging on Apache HTTPD on Windows: What is wrong with this configuration that it is not logging errors?

I am getting a blank screen and nothing in the error logs for a php program I am trying to get up and running (it happens to be yourls). What do I need to do to get error logging enabled or to otherwise get an indicate of why the page is not loading (I know there are multiple postings on this but none of the fixes suggested in this posts seems to generate any output and don't seem to work for this specific implementation)?
I'm running php from this install: php-8.0.0-nts-Win32-vs16-x64.zip
I'm running Apache HTTPD from this install: httpd-2.4.46-o111i-x64-vc15.zip
Turns out this was a behavior of the yourls software I was trying to run. It had a flag that turned error logging/messaging off AND it was not compatable with php 8. I switched to php 7 and switched to the php.ini-development config (by renaming it to php.ini) and I am now seeing error messages (the driver for the database is missing).

bigquery php client not working with Apache web page (Ubuntu 18.10 server)

I have a working Apache 2.4 website that works with Php 7 pages, on an Ubuntu 18.10 server.
My example is based on:
https://cloud.google.com/bigquery/docs/quickstarts/quickstart-client-libraries#client-libraries-install-php
When I run the page as me from the command line
php filex.php
bigquery works and I can see the data.
When I try and view it from the apache web server the 1st part of the page renders then there is an error and the bigquery part is missing.
Error in /var/log/apache2
PHP fatal error Uncaught Google Cloud Exception
I guessed it was a permissions issue with Apache vs my userid.
I thought Apache might be having difficulty accessing the Bigquery php client files, due to directory permissions.
However, the problem was I had not set the environment variable correctly.
I had looked here:
https://help.ubuntu.com/community/EnvironmentVariables
and set System-wide environment variables
/etc/environment
GOOGLE_APPLICATION_CREDENTIALS="/bigquery/project1/accountdetails-xxxxxxxxxxxx.json"
It was visible when logged in as userx
echo $GOOGLE_APPLICATION_CREDENTIALS
Then I came across
https://medium.com/#william.b/setting-dynamic-environmental-variables-in-apache-from-the-os-1d5c1e2e9e6c
which gave me the solution
nano /etc/apache2/envvars
I added the line to the bottom of the (mainly empty) script
export GOOGLE_APPLICATION_CREDENTIALS="/bigquery/project1/accountdetails-xxxxxxxxxxxx.json"
I restarted the server.
Now the web page works as expected.
===================
Nginx
nginx also needs to be configured to work (Ubuntu 18.10, nginx 1.14.)
from
https://medium.com/#tomahock/passing-system-environment-variables-to-php-fpm-when-using-nginx-a70045370fad
/etc/php/7.2/fpm/pool.d$
edited www.conf
uncomment
;clear_env = no
added line
env[GOOGLE_APPLICATION_CREDENTIALS] = /bigquery/project1/accountdetails-xxxxxxxxxxxx.json
restarted nginx and it worked.

PHP Error Logs on IIS 7.5/Windows Server 2008

I'm confused about where I should be looking for a log file containing php errors on a Windows 2008 Server running IIS 7.5 (I'm more familiar with the Mac OS X setup for this).
In my php.ini file I have log_errors set to "On" but I'm not seeing any php errors in the IIS logs that appear in this folder:
C\inetpub\logs\LogFiles
Is it possible to have the php errors included in this file or do I need to specify a new file just for php errors?
(I'm trying to troubleshoot a site that is generating 500 – Internal server error for a php error. I've found this site http://www.webdigi.co.uk/blog/2009/php-on-windows-server-2008-500-internal-server-error-on-iis/ that explains how I can view the error when accessing the page via an RDP session on the server, but I need to be able to log these and view the log as I won't always have RDP access).
In the php.ini (you can find this under "c:\program files (x86)\php\{PHP Version}") change these settings:
log_errors = On
Then set error_log to syslog for the windows event log:
error_log = syslog
Or specify a location on disk such as:
error_log = C:\Windows\temp\php_errors.log
Make sure that the error_log or log_error values aren't being set elsewhere in the file.
If you are using xampp in windows. The error log can be find in
cd C:\xampp\apache\logs\
Use the following command to display the latest errors
tail -f .\error.log

PHP - attempt to log using error_log() causes 500 error

I have an IIS server which is serving PHP via fastcgi.
When the error log file is written to by a user other than one in IIS_IUSRS group (The group the IIS User is running under) the file becomes un-writable by IIS and the PHP calls to error_log() causes a 500 error. (At least that's my guess seeing as if I delete the log file, the error dissapears and the log file is re-created).
Is there anyway I can stop the 500 error from happening?
EDIT: To be clear I know I can stop this by stopping logging, logging to event log or different location etc, but that's not what I mean. I mean I just want to prevent the 500 error, I don't care enough that my system can't log that it should break the site when it tries to. That's exactly the worst behaviour it could have. I just want the 500 error to not happen and the site to continue working.
Since your scheduled task is actually changing the permissions on the error log file, the only viable options I can see are:
1) Make the scheduled task not write to the error_log. Add the following to the top of the cron job:
error_reporting(E_NONE);
2) Make the scheduled task write to the system log (event viewer in windows) by issuing the following command at the start of your scheduled task (PHP file):
ini_set('error_log', 'syslog');
3) If all of the above do not suit you, you can try scheduling the task as the IIS User/Group. This would insure that the permissions are met and error 500 is no longer caused.
There is no magic fix to this, you can either change the scheduled task so it has the same UID/GID as the PHP process, or you can stop logging in the scheduled_task.
Edit the php.ini, and find this line and edit:
error_log = /your/website/path/to/log
And sure to change the display_errors to off:
display_errors = off
Remember to put chmod 777 to the file :). If u wanna to see the file in the browser, can put something like this in the .htaccess file:
<Files /your/site/path/to/log/file.log>
allow from 10.0.1.1/16
deny from all
</Files>
PS: Sry, i dnt see the notation are a ISS server... hum, maybe can view more information about the error in the error_log of the ISS (i dont know where is)
I experienced this. Your error_log might be too big for a file. For example, when your error_log reaches 16mb the server will throw an error 500. You may delete your error_log and try if it still throws that error. You may wanna check the error_logs permissions and ownership too.
You want to avoid the error_log function from throwing a 500 Internal Server Error!
Well, if that may be the case, have you tried prepending your call to error_log with an '#'. That could possibly suppress the error. Please try and revert! :)
You could try using error_log() to write your application log in an alternative path:
error_log("Some fancy error to log", 3, "c:\tmp\your-custom-errors.log");
Or you could configure php to log to windows event log (in your php.ini):
error_log = syslog

Running PHP in IIS6

i am using IIS to run my php website and i configure IIS to work with php as its explained the following tutorial
http://www.wikihow.com/Install-PHP-5-for-IIS-6
but when i run any php page is give me the following error
You have attempted to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed.
i follow this https://serverfault.com/questions/251499/error-when-installing-php5-on-iis6/252149#252149
now i am getting the following error message
FastCGI Error
The FastCGI Handler was unable to process the request.
Error Details:
Could not find entry for "php" on site 67761686 in [Types] section.
Error Number: 1413 (0x80070585).
Error Description: Invalid index.
HTTP Error 500 - Server Error.
Internet Information Services (IIS)
here is my updated fcgiext.ini
[Types]
php=PHP
[PHP]
ExePath=C:\PHP\php-cgi.exe
now i am getting this error message
The FastCGI Handler was unable to process the request.
--------------------------------------------------------------------------------
Error Details:
The FastCGI process exceeded configured request timeout
Error Number: 258 (0x80070102).
Error Description: The wait operation timed out.
I hope this link would help
http://www.ardamis.com/2009/02/15/php-pages-return-a-404-error-on-iis/
Open iis.msc again, go back to the Home Directory tab, and select the “Scripts only” option >from the Execute Permissions menu. Restart the server.
The server should now be correctly processing .php files.
PHP pages return a 404 error on IIS
I was installing PHP 5 on an IIS 6 server when I ran into what turns out to be a pretty common problem. PHP appeared to be installed correctly, but browsing to any page with a .php extension returned a 404 Page Not Found error. While the steps below fixed this for me, I had to piece them together from a few different sources, and a number of other suggestions (like copying the php.ini file to C:/WINDOWS/) didn’t work and were not necessary.
Open your IIS management console at C:\WINDOWS\system32\inetsrv\iis.msc.
Drill down to your web site, right-click and select Properties.
Select the Home Directory tab, then click on the Configuration button.
Select the Mappings tab.
If you don’t see a .php extension listed, click the Add button. Browse to the PHP 5 DLL (which may be at C:\Program Files\PHP\php5isapi.dll). Type .php into the Extension field and leave everything else at the default values. Click OK. The extension and executable path will be filled out and under Verbs you should see “All”.
I should point out that I didn’t have anything listed under the ISAPI Filters tab.
Stop and restart your IIS server and browse to a .php file. (To restart your IIS server, open the IIS management console, right-click the local computer in the left pane, hover on All Tasks and choose Restart IIS.) Chances are, you’re no longer getting the 404 error, but are now seeing a 403.1 message, like:
The page cannot be displayed
You have attempted to execute a CGI, ISAPI, or other executable program from a directory that does not allow programs to be executed.
Please try the following:
* Contact the Web site administrator if you believe this directory should allow execute access.
HTTP Error 403.1 – Forbidden: Execute access is denied.
Internet Information Services (IIS)
Open iis.msc again, go back to the Home Directory tab, and select the “Scripts only” option from the Execute Permissions menu. Restart the server.
The server should now be correctly processing .php files.
Take a look at my answer on Server Fault for a fairly bulletproof way to install PHP in under ten minutes:
Error When Installing PHP5 on IIS6
If you follow all of the steps in the correct order you'll have PHP up and running in no time.
Updated:
As per your comment and question update, edit your fcgiext.ini file so that it only contains the following lines:
[Types]
php=PHP
[PHP]
ExePath=C:\PHP\php-cgi.exe
Execute the following from the command prompt:
1.
cd c:\Windows\system32\inetsrv
2.
c:\Windows\system32\inetsrv>cscript fcgiconfig.js -add -section:"PHP" -extension:php -path:"c:\php\php-cgi.exe"

Categories