hmahdavi
hmahdavi

Reputation: 2354

How to log errors into file in php?

I started the beginner with php. I need to get errors that append in my website I use below code for log errors into file but do not work. This has no any error.

<!DOCTYPE html>
<html>
<body>

<?php
ini_set('display_startup_errors',1);
ini_set('display_errors',1);
error_reporting(E_ALL);

echo "My first PHP script!";
error_log( "Hello, errors!" );

?>
</body>
</html>  

What is problem?

Upvotes: 0

Views: 345

Answers (1)

Rotimi
Rotimi

Reputation: 4825

In the above code, you need to also instruct php to log errors. Add the following directive

$path =$_SERVER['DOCUMENT_ROOT'].'/path/file.txt';//tell php where to save your error logs

ini_set('log_errors',1);//logs errors 

ini_set('error_log',$path); //override php's default error log directory 

Upvotes: 1

Related Questions