How can i trigger 500 Internal Server Error or 404 Page Not Found Apache errors in PHP?
For 500 Internal Server Error i have tried
you simply cannot trigger apache error pages from php code without hackery redirection as proposed by ben lee because error document redirection is handled by another layer of your application's stack (specifically, apache's mod_core).
when your script runs, it's too late.
the trickery of getting an error page by throwing an exception heavily depends on your php.ini's settings about error handling and verbosity.
http_response_code()currently only exists in php's svn thus it's not available in most production environments which are supposed to run an official release version.
my advice is to properly implement a custom error and exception handler via set_error_handler() and set_exception_handler(), respectively, use header() to send the client proper http status information and (if needed) generate error pages.