How to Send PHP Errors to a File Rather Than the Web Browser

How to Send PHP Errors to a File Rather Than the Web Browser thumbnail
PHP offers a solution to logging errors in a log file.

When you create a PHP file, you then load it to a web server to be executed in an Internet browser. The server checks the file for logical and syntax errors in the PHP code when trying to run it. If there is an error, the server stops running the file and sends the error to the user through the browser. Webmasters can't know that errors have occurred on the user's side unless it is reported, which isn't done every time a user encounters an error. Sending the errors to a log file lets the webmaster keep up with them.

Instructions

    • 1

      Log in to your server and locate the php.ini file. This file is located in the "etc" folder in the root directory. The php.ini file is where you change all of your PHP settings. This is also where you will select a log file for errors instead of a web browser.

    • 2

      Open the php.ini in a text editor or a code editor. Add the following lines to the php.ini file:

      "#vi /etc/php.ini

      error_log= /var/log/php-scripts.log"

      This code in the php.ini will start to send the errors to the PHP log file. It will still send it to the web browser if you don't cut this feature off.

    • 3

      Turn off the feature that displays errors in the web browser. With the php.ini file still open, add the following line:

      "display_errors = Off"

      Save the php.ini file and refresh your web browser.

Tips & Warnings

  • You can also save the errors to a Windows Server Event log file instead of the PHP log file. Just replace "error_log = /var/log/php-scripts.log" with "error-log = syslog."

Related Searches:

References

  • Photo Credit keyboard - error image by Kirubeshwaran from Fotolia.com

Comments

You May Also Like

  • How to Send a PHP Image File

    PHP is a powerful scripting language that is often used to create dynamic Web pages and applications. The functionality that PHP provides...

  • Different Types of Errors in PHP

    Different Types of Errors in PHP. PHP is a server-side scripting language that allows webmasters to add programming functionality to their websites....

  • How to Send PHP Mail to HTML Email

    PHP provides Web developers with website creation tools. PHP is a server-side language, so the code created runs on the server and...

  • How to Save a Text File in PHP

    PHP is a Web programming language typically used on Web servers to control content and interactivity on websites. It is an advanced...

  • How to Upload Multiple Images in PHP

    When programming your website in PHP, you want to create a dynamic environment where your users interact with you and contribute to...

  • How to Upload Files to a Web Server in PHP

    You want a website that allows visitors to upload files and interact with your site. PHP is a scripting language you can...

  • How to Remove Cache in PHP

    When programming in PHP, there are certain instances that you may not want information to be cached, as it may affect data...

  • How to Echo Variables Using PHP

    Use the echo function to output several variables at once. Here is a more complex example that uses an environmental variable (...

  • How to Read a Text File in PHP

    Reading the contents of a text file is an important part programming, whether you are putting data on a web page, or...

  • How to Include a PHP File in an HTML Page

    PHP is a powerful programming language used to run millions of dynamic websites. Often, it is interspersed with HTML so you can...

Related Ads

Featured