Jesin's Blog

Welcome to the Portal of Technology

  • Facebook
  • GitHub
  • RSS
  • Twitter
  • Home
  • Categories
    • Domains
    • Linux
    • Networking
    • PHP
    • Virtualization
    • Web Design
    • Web Servers
    • Windows
  • WordPress Plugins
    • Custom Error Pages
    • HTTP Digest Authentication
    • Mailgun Email Validator
  • Toolbox
    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool
  • About Me
  • Contact Me
  • Sitemap
Home ›
PHP ›
Disabling PHP Display Errors

Disabling PHP Display Errors

August 27, 2010 PHP Jesin A 1 Comment

Identifying the errors are very important when learning a new computer language or coding a program. Languages like C and C++ have compilers which display the error message and the lines which contain them only to the programmer (thats you). But with PHP when you’re running a live website and commit any errors in the programming it’ll be displayed to the entire world. Now there is nothing to feel ashamed because everyone commits errors (to error is human, right) the bad thing is that these errors reveal a treasure of information that a potential hacker can use against you and your website. This article will guide you through disabling PHP from displaying errors.

Method 1:- Editing the php.ini file

If you’re hosting your website(s) on a dedicated server/VPS you will have access to the php.ini file. Before editing it please take a copy of it so that it can be restored if something goes wrong. Note that by default the display_errors flag is set to Off state only. If for some reason its On you should modify it. Open the php.ini file using a text editor navigate to the following line

display_errors = On

Replace On with Off, save the file and restart the Web Server. If the web server refuses to start check for syntax errors.

Method 2:- Create/Edit the .htaccess file

This method is for the people using shared hosting services. Some hosting providers think that enabling the server to display PHP errors will help programmers to debug their PHP programs easily. But such good intentions might end up with bad consequences. Create a file named .htaccess (note the dot at the beginning) inside the www or public_html or htdocs folder, if its already there open it using a text editor and add the following line

php_flag display_errors Off

Save the .htaccess file. If you get a “500 Page not Found” error check the syntax used in htaccess.

Testing it

Now its time to test whether this change works. Create a PHP file e.g. file.php and enter a code with errors. Use the following example

<?php
print "Missing double quotes and semicolon
?>

Now access the file by typing the url in a web browser (e.g. https://websistent.com/file.php). You should see a blank page now. So you’ve successfully turned off the display_errors option of PHP.

Related posts:

php category thumbnailPHP error_log .htaccess php category thumbnailHow to use custom php.ini files on shared hosting Default ThumbnailChange the default Directory Index in Apache Server php category thumbnailHow to use PHP to minify HTML output Default ThumbnailHow to create custom error page in Apache

Tags: display_errors, htaccess, php

Trackbacks

  1. PHP Open Port Check Script | Jesin's Blog says:
    June 30, 2013 at 2:28 pm

    […] To prevent PHP from displaying such errors at runtime read Disabling PHP Display Errors […]

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Get a wealth of information delivered to your inbox. Subscribe and never miss a single article.

  • Tutorials and howtos
  • Code, scripts and commands
  • Online Tools

* No spam, unsubscribe anytime

Hire Me

  • SSL installation and hardening (A+ on Qualys SSL test)
  • Apache & Nginx configuration
  • Email deliverability improvement (10/10 on Mail Tester & MailGenius)
  • WordPress customization, optimization and migration
  • and much more…

    Tools

    • DNS Lookup Tool
    • htdigest Generator Tool Online
    • htpasswd Generator Tool Online
    • HTTP Headers Lookup Tool
    • MD5 Encryption Tool
    • Open Port Check Tool
    • SHA-1 Encryption Tool
    • URL Encoding/Decoding Tool

    Nav

    • Home
    • About Me
    • Contact Me
    • Privacy Policy
    • Sitemap
    Vultr SSD VPS

    Creative Commons License
    Jesin's Blog by Jesin A is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.
    Based on a work at websistent.com.