0

I have Apache directive like so:

error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT
display_errors = On
log_errors = On
log_errors_max_len = 10240
error_log = php_errors.log

I get this error on one of my pages - the error is displayed in the browser.

Deprecated: Function money_format() is deprecated in /var/www/html/sample.php on line 152

That's great because it shows me there is an error in my code. But I am surprised it shows me deprecated error when in Apache config I explicitly request to not show me deprecated errors (~E_DEPRECATED).

But, no matter... since it is production environment, I need to see the error, but not see it in the browser. So I set display_errors to Off. But now, I do not see the error, and it is not logged anywhere despite my php.ini config having directives to do so.

Question

How can I see the error in a log (preferably apache's error.log is best), but not in the browser. I am puzzled as to why it is not happening this way, because my php.ini directives seem to be requesting php to do this via log_errors and error_log directives

Virtual Host Config

<VirtualHost *:80>
    ServerName apps.domain.com
    ServerAdmin [email protected]
    DocumentRoot /var/www/html
   <Directory /var/www/html>
       AllowOverride All
       Require all granted
   </Directory>
    Redirect permanent "/" "https://apps.domain.com/"
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =apps.domain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,QSA,R=permanent]
</VirtualHost>

.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteCond %{REQUEST_URI}::$1 ^(/.+)(.+)::\2$
RewriteRule ^(.*) - [E=BASE:%1]
RewriteRule ^(.*)$ %{ENV:BASE}index.php [NC,L]
2
  • please show us the virtual host config in Apache, the .htaccess und the php configuration as well as the php setting in your file. because for example the .htaccess has priority compared to the virtual host settings and so on. there are many possibilities. Commented May 13, 2020 at 22:53
  • Max, I've added the virtual host config. and htaccess but I fixed my error with full path to a folder and also making folder accessible with a+wx. I am onto the next question - why some errors go into apache log and why some go into php.ini-specified log Commented May 14, 2020 at 14:41

1 Answer 1

1

The logging directory needs to exist and be accessible by apache (on linux this can be acomplished by sudo chown www-data:www-data /var/log/php)

How to configure php to do what you want?

For this specific case you do not need to edit anything for the apache config, but you do need to edit the config for php.ini

// add this your php.ini file
display_errors = Off
error_log = /var/log/php/error.log # Assuming you have /var/log/php directory and it's writable by httpd
error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT

changing only your apache directive to do what you want

What is going wrong in your apache config is that you are specifying a incorrect path.

you need to specify either an absolute path E.G /var/log/php/error.log or you can specify a path based on your document root like %{DOCUMENT_ROOT}/log/error.log

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.