Internal Error 500 Apache, but nothing in the logs? - apache

I'm getting 500 Internal Server errors when I try to make an HTTP POST to a specific address in my app. I've looked into the server logs in the custom log directory specified in the virtual hosts file, but the error doesn't show up there so debugging this has been a pain in the ass.
How do I cause Apache to log Internal 500 errors into the error log?

This is an Ancient answer from 2013, back when PHP was new and security wasn't an issue:
Here in the future it's a security risk to dump errors to screen like this. You better not be doing this in any production setting.
Why are the 500 Internal Server Errors not being logged into your apache error logs?
The errors that cause your 500 Internal Server Error are coming from a PHP module. By default, PHP does NOT log these errors. Reason being you want web requests go as fast as physically possible and it's a security hazard to log errors to screen where attackers can observe them.
These instructions to enable Internal Server Error Logging are for Ubuntu 12.10 with PHP 5.3.10 and Apache/2.2.22.
Make sure PHP logging is turned on:
Locate your php.ini file:
el#apollo:~$ locate php.ini
/etc/php5/apache2/php.ini
Edit that file as root:
sudo vi /etc/php5/apache2/php.ini
Find this line in php.ini:
display_errors = Off
Change the above line to this:
display_errors = On
Lower down in the file you'll see this:
;display_startup_errors
; Default Value: Off
; Development Value: On
; Production Value: Off
;error_reporting
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
The semicolons are comments, that means the lines don't take effect. Change those lines so they look like this:
display_startup_errors = On
; Default Value: Off
; Development Value: On
; Production Value: Off
error_reporting = E_ALL
; Default Value: E_ALL & ~E_NOTICE
; Development Value: E_ALL | E_STRICT
; Production Value: E_ALL & ~E_DEPRECATED
What this communicates to PHP is that we want to log all these errors. Warning, there will be a large performance hit, so you don't want this enabled on production because logging takes work and work takes time, time costs money.
Restarting PHP and Apache should apply the change.
Do what you did to cause the 500 Internal Server error again, and check the log:
tail -f /var/log/apache2/error.log
You should see the 500 error at the end, something like this:
[Wed Dec 11 01:00:40 2013] [error] [client 192.168.11.11] PHP Fatal error:
Call to undefined function Foobar\\byob\\penguin\\alert() in /yourproject/
your_src/symfony/Controller/MessedUpController.php on line 249

I just ran into this and it was due to a mod_authnz_ldap misconfiguration in my .htaccess file. Absolutely nothing was being logged, but I kept getting a 500 error.
If you run into this particular issue, you can change the log level of mod_authnz_ldap like so:
LogLevel warn authnz_ldap_module:debug
That will use a log level of debug for mod_authnz_ldap but warn for everything else (https://httpd.apache.org/docs/2.4/en/mod/core.html#loglevel).

Check your php error log which might be a separate file from your apache error log.
Find it by going to phpinfo() and check for error_log attribute.
If it is not set. Set it: https://stackoverflow.com/a/12835262/445131
Maybe your post_max_size is too small for what you're trying to post, or one of the other max memory settings is too low.

If your Internal Server Error information doesn't show up in log files, you probably need to restart the Apache service.
I've found that Apache 2.4 (at least on Windows platform) tends to stubbornly refuse to flush log files—instead, logged data remains in memory for quite a while. It's a good idea from the performance point of view but it can be confusing when developing.

Please Note: The original poster was not specifically asking about PHP. All the php centric answers make large assumptions not relevant to the actual question.
The default error log as opposed to the scripts error logs usually has the (more) specific error. often it will be permissions denied or even an interpreter that can't be found.
This means the fault almost always lies with your script. e.g you uploaded a perl script but didnt give it execute permissions? or perhaps it was corrupted in a linux environment if you write the script in windows and then upload it to the server without the line endings being converted you will get this error.
in perl if you forget
print "content-type: text/html\r\n\r\n";
you will get this error
There are many reasons for it. so please first check your error log and then provide some more information.
The default error log is often in /var/log/httpd/error_log or /var/log/apache2/error.log.
The reason you look at the default error logs (as indicated above) is because errors don't always get posted into the custom error log as defined in the virtual host.
Assumes linux and not necessarily perl

The answers by #eric-leschinski is correct.
But there is another case if your Server API is FPM/FastCGI (Default on Centos 8 or you can check use phpinfo() function)
In this case:
Run phpinfo() in a php file;
Looking for Loaded Configuration File param to see where is config file for your PHP.
Edit config file like #eric-leschinski 's answer.
Check Server API param.
If your server only use apache handle API -> restart apache.
If your server use php-fpm you must restart php-fpm service
systemctl restart php-fpm
Check the log file in php-fpm log folder. eg /var/log/php-fpm/www-error.log

Please check if you are disable error reporting somewhere in your code.
There was a place in my code where I have disabled it, so I added the debug code after it:
require_once("inc/req.php"); <-- Error reporting is disabled here
// overwrite it
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

Add HttpProtocolOptions Unsafe to your apache config file and restart the apache server. It shows the error details.

In my case it was the ErrorLog directive in httpd.conf. Just accidently noticed it already after I gave up. Decided to share the discovery )
Now I know where to find the 500-errors.

Check that the version of php you're running matches your codebase. For example, your local environment may be running php 5.4 (and things run fine) and maybe you're testing your code on a new machine that has php 5.3 installed. If you are using 5.4 syntax such as [] for array() then you'll get the situation you described above.

Try accessing a static file. If this is not working either then
go to all directories from the root "/" or "c:\" to the directory of your file and check if they contain ".htaccess" files.
I once left a file in "c:\" and it had the most strange results.

Related

Is there a way to serve julia from the cgi-bin directory with apache?

I have a user who wants to serve output of julia files from an apache webserver.
Placing the code in there, adding .jl to AddHandler, and chmod 775 the file gets a 500 internal server error.
helloworld.jl: -rwxr-xr-x
println("hello world")
Here is what is displayed from apache:
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, root#localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.```

Is it possible to check a .htaccess file using the -t option of the apache2 command?

I've got a .htaccess file that I copied from one Apache HTTPD server and deployed onto another. Unfortunately, I foolishly didn't check the version of the destination server and just put the file in place; the site stopped working because it's Apache 2.4 and the file has 2.2 syntax. So I quickly reverted it to the previous version and hoped that nobody noticed!
Now, of course, I'm paranoid.
I tried copying the broken-on-2.4 version elsewhere and using apache2 -t .htaccess to find out what's wrong, but I get this error:
apache2: Could not open configuration file /etc/apache2/.htaccess: No such file or directory
If I supply the full path (i.e. apache2 -t /path/to/it/.htaccess) I get:
AH00534: apache2: Configuration error: No MPM loaded.
This error appears to be unrelated but I get the same error message and exit code (1) regardless of whether or not there's an error in the .htaccess file.
So my question is: can I use apache2 -t [...] to test a .htaccess file, and if not, what can I use instead (aside from the manual)? There is this site but it doesn't seem to allow me to say what version of Apache to check against.
I haven't found out how to do what I asked, but I have come up with a workaround.
I created a new directory on the server and put the incompatible .htaccess file in there. I then accessed the directory via my browser whilst tail -fing the error log (/var/log/apache2/error.log) to see what the problem was.

The Requested Operation has failed- Apache error

When I'm trying to start the Apache 2.2 server it is showing the following message: The Requested Operation has failed
In command Prompt it is showing as follows:
C:\Documents and Settings\amth>net start apache2.2
The Apache2.2 service is starting.
The Apache2.2 service could not be started.
A service specific error occurred: 1.
More help is available by typing NET HELPMSG 3547.
Open run( win + r ) in windows and then type services.msc. Search for Apache service. Double click on the service and select any startup type other than disabled. This should work like a charm.
Open conf folder then open httpd.conf file in your text editor.
Find this line:
Listen 12.34.56.78:80
Listen 80
and change it to
Listen 12.34.56.78:80
Listen 8080
Then hit save
I have wasted a whole day on figuring out why curl_init() threw an undefined-error. Im using Windows, Apache 2.4 and PHP 7.3
After trying to:
Install a fresh version of Curl As described in this post
Enabe Curl in the php.ini file following this description
I still got this error.
The solution was to add the directory of the php e.g c:php/ to the PATH Variable in the Windows environment variables.
->Hit the Windows-Key and S
-> search for "System"
-> go to advanced options(a small window shuld pop up)
-> hit environment variables
-> in the **bottom** box scroll until you find "PATH"
-> select it and hit "edit"
-> enter the php directory and close the window
-> reboot your PC
Hopefully it will work for you too :)
Have you done any changes in httpd.conf file ? i was also facing same problem in my case i have saved httpd.conf file as txt so due to that i was getting error
Was getting this issue when trying to start Apache with mod_jk. As part of loadmodule in http.conf file LoadModule jk_module modules/mod_jk.so was added but in Apache2.2\modules folder mod_jk.so file was not available. Added mod_jk.so file to modules folder and apache started without any issues.
Here is what I did - if you uninstall and reinstall apache via command prompt it
httpd -k unistall/httpd -k install
then it displays the errors
in my case the require all was missing 'granted' at the end of to look like 'require all granted'
<Directory />
AllowOverride all
Require all
</Directory>
If your lan ip changed then you would come across this error. In the httpd conf file you to rectify the following:
Listen IP:Port
I ran into the same error message on Windows Server 2008 R2. I was using SSL and realized that my signer certs, configured in ssl.conf, where placed in the wrong folders on the file system. I placed the certs in the correct spot and the service and Apache was working fine afterwards.
I've tried closing World Wide Web services, changing a lot of ports and surfing many forums, and eventually I looked in to Logs=>Apache (error.log) files.
I saw in this error:
PHP Fatal error: Directive 'asp_tags' is no longer available in PHP in Unknown on line 0
Then I opened php.ini files in XAMPP. Find with ctrl+f asp_tags=On line and turn it to Off.
All of it then worked.
In my case Apache 2.4 is worked on Win7Pro 64bit. Last week it worked fine but today I was unable to start it as usually. I tried to check logs for errors but no clue. Then I went to Control panel -> Administrative tools -> Services and found there Apache service was disabled!? Click on property, set Startup type to manual and - voila! It started like charm.

php.ini does not exist in my apache/bin folder, but I'm getting an error?

I've been trying to figure out how to resolve this error with all the new pages I create:
Server error!
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.
If you think this is a server error, please contact the webmaster.
Error 500
localhost
2011/11/28 13:36:56
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1
Well, it all started when I increased the security on MySQL by setting some more passwords, I think. I figured I'd get a better error report if I turned error reporting on in php.ini, but it's not in my /apache/bin folder.
Alright, so I have no idea what to do. I've also got this line in xampp: MySQL database DEACTIVATED.
Any idea what might be happening? Also, please let me know if this should go to superuser.
If you're on Linux, try a "find", like this:
find / -name php.ini print
Another approach is to create a "phpinfo.php" in your Apache DocumentRoot folder, and let PHP tell you where you should put your php.ini:
<?php
// Create this file in your Apache root,
// then browse to http://localhost/phpinfo.php
// Look for "Configuration File (php.ini) Path" in the resulting output
phpinfo ();
?>
Use the find feature in Linux, as specified by paulsm4 to find php.ini.
Use ctrl+f in Windows and search for files and folders -> php.ini to find it in Windows. I recommend you do this from your web server's root directory rather than from some other location; otherwise, it may fail.
If you're experiencing a 500 error, you should check your Apache log files. They can be found in the /apache/logs folder in the file error.log, I believe. I emptied the file and then caused the error to isolate it. The information lead me to the answer.
In my case, the reason I was getting a 500 error was because my .htaccess file was referencing a .htpasswrd file that did not exist. I changed the line of code in the .htaccess file that was targeting the .htpasswrd file to target an existing .htpasswrd file that I wanted to use. I could have just as soon copied a properly formatted .htpasswrd file or made one from scratch, though.
I've read at multiple sources that 500 errors have many causes. So, none of these steps are guaranteed to work for you. If they do not, I wish you luck, and I hope that you will post a reply telling me how you fixed your 500 error, too--or, a link to a resolved question about a 500 error.

Where does PHP store the error log? (PHP 5, Apache, FastCGI, and cPanel)

I am on shared hosting and have cPanel, Apache, and PHP is run by FastCGI. Where does PHP store the error log?
Is there another way I can find the error log on a shared hosting environment instead of having to go through entire site structure to look for error_log files?
I have access to the php.ini file (I am using PHP version 5.2.16).
PHP stores error logs in /var/log/apache2 if PHP is an apache2 module.
Shared hosts are often storing log files in your root directory /log subfolder.
But...if you have access to a php.ini file you can do this:
error_log = /var/log/php-scripts.log
According to rinogo's comment: If you're using cPanel, the master log file you're probably looking for is stored (by default) at
/usr/local/apache/logs/error_log
If all else fails you can check the location of the log file using
<?php phpinfo(); ?>
Try phpinfo() and check for "error_log"
Linux
php --info | grep error
The terminal will output the error log location.
Windows
php --info | findstr /r /c:"error_log"
The command prompt will output the error log location.
To set the log location
Open your php.ini and add the following line:
error_log = /log/myCustomLog.log
Thanks chelmertz and Boom for these (comments on the question).
On a LAMP environment the PHP errors are be default directed to this below file.
/var/log/httpd/error_log
All access logs come under:
/var/log/httpd/access_log
How to find your PHP error log on Linux:
sudo updatedb
[sudo] password for eric:
sudo locate error_log
/var/log/httpd/error_log
Another equivalent way:
sudo find / -name "error_log" 2>/dev/null
/var/log/httpd/error_log
It can also be /var/log/apache2/error.log if you are in Google Compute Engine.
And you can view the tail like this:
tail -f /var/log/apache2/error.log
It appears that, by default, PHP does not log errors anywhere. The error_log key in php.ini is commented out in all the installs I've seen.
Generally I:
look for php.ini files. locate php.ini.
Search these files for the error_reporting value;
Which should be set to whatever amalgamation of PHP log levels are enough for you.,
For example: E_ALL & ~E_DEPRECATED & ~E_STRICT
Check the error_log value to make sure it points to an actual place and is not commented out.
The default value doesn't give a full path, only a file name, I don't know where this path resolves to normally. Probably /var/log/.
You should use absolute path when setting error_log variable in your php.ini file, otherwise, error logs will be stored according to your relative path.
error_log = /var/log/php.errors
Other solution would be writing simple script which would list all error logs files from directory tree.
php --info | grep error
This is helpful.
NGINX usually stores it in /var/log/nginx/error.log or access.log (on Ubuntu in any case).
The best way is to look in your httpd.conf file and see what the default is. It could also be overridden by your specific virtual host. I start by looking at /etc/httpd/conf/httpd.conf or /etc/apache2/httpd.conf and search for error_log. It could be listed as either /var/log/httpd/error_log or /var/log/apache2/error_log, but it might also be listed as simply logs/error_log.
In this case it is a relative path, which means it will be under /etc/httpd/logs/error_log. If you still can't find it, check the bottom of your httpd.conf file and see where your virtual hosts are included. It might be in /etc/httpd/conf.d/ <- as "other" or "extra". Your virtual host could override it then with ErrorLog "/path/to/error_log".
If you have build Apache and PHP from source, then the error logs by default is generated at your ${Apache install dir}/logs/error_log, i.e., generally /usr/local/apache2/logs/error_log.
Else, if you have installed it from the repository, you will find it at /var/log/apache2/error_log.
You can set the path in your php.ini also and verify it by invoking phpinfo().
Wherever you want it to, if you set it in your function call:
error_log($errorMessageforLog . "\n", 4, 'somePath/SomeFileName.som');
If you use the php5-fpm log default, it should be under:
/var/log/php5-fpm.log
Search the httpd.conf file for ErrorLog by running cat <file location> | grep ErrorLog on the command line. For example:
cat /etc/apache2/httpd.conf | grep ErrorLog
Output:
# ErrorLog: The location of the error log file.
# If you do not specify an ErrorLog directive within a <VirtualHost>
ErrorLog "/private/var/log/apache2/error_log"
Find the line that starts with ErrorLog and there's your answer.
Note: For virtual hosts, you can edit the virtual hosts file httpd-vhosts.conf to specify a different log file location.
cPanel Error logs are located in:
/usr/local/cpanel/logs/
/usr/local/apache/logs/
By default Apache logs are located inside:
/var/log/apache
or
/var/log/apache2
If anyone is using a custom log location then you can check it by running this command:
cat /etc/apache2/**conf**/httpd.conf | grep ErrorLog
If you are getting an error that the apache2 directory does not exist then you can run this command to find correct location by:
whereis apache
or
whereis apache2
When configuring your error log file in php.ini, you can use an absolute path or a relative path. A relative path will be resolved based on the location of the generating script, and you'll get a log file in each directory you have scripts in. If you want all your error messages to go to the same file, use an absolute path to the file.
See more in Error Handling Functions.
something like this :
sudo locate error.log | xargs -IX grep -iH "errorlog" X
or
sudo locate error_log | xargs -IX grep -iH "errorlog" X
or
sudo find / -iname "error?log" 2>/dev/null | xargs -IX grep -iH "errorlog" X
I can guarantee you, I am not the only person who has been driven to madness at least once in a frustrating search for a log file. It seems like it should be the easiest thing to find in the whole system.
A definitive guide on where the PHP error log is stored would be a complicated bit of work. The official PHP manual does not even try to address the whole topic, because there are dependencies on systems outside PHP, such as the operating system (Linux vs. Windows, which distribution of Linux), including settings within Windows and Linux that affect the name and location of the PHP error log.
Until someone takes the time to write a complete, cross-system guide, the best you are going to get is general directions where you can inquire. Every PHP developer has had to endure agony in this pursuit, with one exception. If you work in one place and the information is provided when you first need it, then you have the information need forever, that is, until you find yourself in a new working environment. There are such fortunate people.
If the information is not given to you on a silver platter, so to speak, you have some hunting to do. The hunt is not the longest you will face in your career, but it is not the simplest either.
As is evident from the many answers already posted, a smart place to begin is the output of phpinfo(). To view it, create a PHP file containing this:
<?php
phpinfo();
Either browse to that file or run it from the command line. If you do both, you likely will find the error_log is in different places, depending on command line vs. web server use of PHP. That is because the PHP interpreter that runs on a web server is not the same PHP interpreter that runs from the command line, even when the command line is on the same machine as the web server. The answers already posted in here mostly are making an unstated assumption that PHP is running as part of a web server.
The default for error_log is no value
Whatever the value is, it comes from the php.ini files used to configure PHP. There can be many php.ini files. Finding your way among them is confusing at first, but you do not need to deal with this to find your PHP log.
If the output from phpinfo() shows a full path to a file, that is where the log is. You are lucky.
The trick is there usually is not a full path indicated in phpinfo(). When there is not a full path, the location depends on:
Whether error_log is no value. If it is, the log file location will depend on the operating system and the mode PHP is running. If PHP is running as an Apache module, on Linux the log often is in /var/log/apache2/error.log. Another likely spot is in a logs directory in your account home directory, ~/logs/error.log.
If there is a file name without a path, the location depends on whether the file name has the value syslog. If it syslog, then the PHP error log is injected into the syslog for the server, which varies by Linux distribution. A common location is /var/log/syslog, but it can be anywhere. Even the name of the syslog varies by distribution.
If the name without a path is not syslog, a frequent home for the file is is the document root of the website (a.k.a., website home directory, not to be confused with the home directory for your account).
This cheat sheet has been helpful in some situations, but I regret to have to admit it is not nearly universal. You have my condolences.
For CentOS 8 it is var/log/httpd/error_log.
You are on a shared environment and cannot find error log. Always check if cPanel has option Errors in your cPanel dashboard. If you are not being able to find the error log, then you can find it there.
In the cPanel search bar, search Error, it will show Error Pages which are basically lists of different HTTP error pages and other Error is where the error logs are displayed.
Other places to look in a shared environment:
/home/yourusername/logs
/home/yourusername/public_html/error_log
You can go in File Manager and check the logs folder.
Check the log file in a public_html folder.
Check "php phpinfo()" file for where the log is stored.
Mine for some reason stored it in:
/var/log/php-errors.log
I'm using Ubuntu Server 16.04 (Xenial Xerus) and PHP 7.1.28.
WordPress
WordPress will direct error_log() messages to /wp-content/debug.log when WP_DEBUG_LOG is set to true.
See WordPress documentation for WP_DEBUG_LOG
For PHP-FPM, just search the configuration file for error_log:
cat /etc/php-fpm.d/www.conf | grep error_log
php_admin_value[error_log] = /var/log/php-fpm/www-error.log
In a shared cPanel environment you cannot find the error log, if your hosting provider doesn’t provide any option in the cPanel dashboard. You can search "error" and see if your provider have any.
Otherwise normally you will find a file called "error_log" in your public_html file, which have all the PHP error recorded.
You can see the php errors for an account under:
/home/username/logs/domain_tld.php.error.log
You can set php error log globally and locally.
Globally through WHM:
WHM -->> MultiPHP INI Editor --> "Editor Mode"
Select the version of PHP you would like to set the error log
Edit the parameter error_log.
error_log = "/some/path"
Change the filename to the desired error log file
Save changes
Locally though cPanel:
CPanel -->> MultiPHP INI Editor --> "Editor Mode"
Select the version of PHP you would like to set the error log
Edit the parameter error_log.
error_log = "/some/path"
Change the filename to the desired error log file
Home directory will set the option for all domains, addons, and subdomains configured on the account
A specific domain will limit the change to that domain, or, in the case of an addon domain, the addon and the matching subdomain
Save changes
If PHP-fpm is enabled:
WHM --> MultiPHP Manager
Find the domain you'd like to change the error log location for
Click "Edit PHP-FPM"
Change the log location in "The error log file (error_log)" relative to the folder "logs" within the user's home directory
Save changes