Getting 500 error on certain pages after server migration [duplicate] - php

This question already has answers here:
Getting Internal Server Error while trying to access my site
(5 answers)
Closed 6 years ago.
My site having 4-5 static pages only. index.html & index.php both are there. index.html is working fine. If I change to index.php, it's giving 500 Internal Server Error. I don't know where is my mistake?
Note:
If I use .htaccess file with php_flag display_errors 1,
It's showing Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
If I use .htaccess file with empty,
It's showing Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
And if I give ../contact-us.php, it's showing correctly.
Thanks...

500 Internal Server Error is shown if your php code has fatal errors but error displaying is switched off. You may try this to see the error itself instead of 500 error page:
In your php file:
ini_set('display_errors', 1);
In .htaccess file:
php_flag display_errors 1

A PHP file must have permissions set to 644. Any folder containing PHP files and PHP access (to upload files, for example) must have permissions set to 755. PHP will run a 500 error when dealing with any file or folder that has permissions set to 777!

I was having this problem because I was trying to connect to MySQL but I didn't have the required package. I figured it out because of #Amadan's comment to check the error log. In my case, I was having the error: Call to undefined function mysql_connect()
If your PHP file has any code to connect with a My-SQL db then you might need to install php5-mysql first. I was getting this error because I hadn't installed it. All my file permissions were good. In Ubuntu, you can install it by the following command:
sudo apt-get install php5-mysql

It was changing the line endings (from Windows CRLF to Unix LF) in the .htaccess file that fixed it for me.

I know this question is old, however I ran into this problem on Windows 8.1 while trying to use .htaccess files for rewriting. My solution was simple, I forgot to modify the following line in httpd.conf
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so
Restarted the apache monitor, now all works well. Just posting this as an answer because someone in the future may run across the same issue with a simple fix.
Good luck!

Google guides me here but it didn't fix mine, this is a very general question and there are various causes, so I post my problem and solution here for reference in case anyone might read this later.
Another possible cause of 500 error is syntax error in header(...) function, like this one:
header($_SERVER['SERVER_PROTOCOL'] . '200 OK');
Be aware there should be space between server protocol and status code, so it should be:
header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
So I suggest check your http header call if you have it in your code.

Related

PHP script error 500 but the query works on phpmyadmin [duplicate]

Recently, I put my project which is php+smarty+mysql in my httpd server. But I encountered an error that says:
500 Internal Server Error
My OS is archlinux, and the httpd server and php were installed like this:
sudo pacman -S apache php
If I use a test native php file which contains the following:
<html>
<head>
<title>PHP Test Page</title>
</head>
<body>
This is Arch Linux, running PHP.
<?php
phpinfo();
?>
</body>
</html>
it runs correctly. It tells me that the php can work well. But why is my project with smarty not working? Is there any one who has encountered this problem?
With the info you provided it's difficult to say.
Error 500 happens because you did some error in the code that is supposed to produce the page, or the code generates some unhandled exception.
My suggestion is to visit the page that gives you the 500 error, and then try to comment out all your code. See if the issue is still present. If not, uncomment the code until you find the critical part that originates the error. Could be anything, a typo, a file not found, a logical error, anything.
Also, check in the webserver logs, if you can read them.
Look in your Apache error log (often found at /var/log/httpd/error_log, though this varies greatly). It will have more information about the server error.
Check to make sure that any .htaccess files are correct (syntax wise).
just happened to me and wanted to write down the solution.
The configured Smarty cache directory (/var/cache/Smarty) was configured with incorrect permissions, the apache process needs to create files in that directory.
This is the directory you set with the compile_dir directive.
BTW, the error_log file doesn't show anything with this error, Firebug shows a 500 Internal Server Error.
I was able to get the error details by checking error.log file inside
/var/log/apache2
in ubuntu 16.04

GoDaddy Windows Plex PHP error_log not working right

I'm having an issue where I get an "Internal Server Error" on my php page. To try and debug it, I attempted to use the error_log function in php. However I could not get it to write anything to the error log. Even in a simple php file:
httpdocs/temp.php
<?php
error_log("this is an error");
echo "hello";
?>
I would receive a basic internal server error message:
Internal Server Error The server encountered an internal error or
misconfiguration and was unable to complete your request.
Please contact the server administrator to inform of the time the
error occurred and of anything you might have done that may have
caused the error.
More information about this error may be available in the server error
log.
Web Server at xxxxxxxx.com
So I looked up how to set up the error_log properly, thinking that it was somehow not set up correctly. I found this article.
Since I am on windows I edited the .user.ini file in my httpdocs root folder and added the error_log line:
httpdocs/.user.ini
[PHP]
error_log=G:\PleskVhosts\xxxxxxxxxx.com\httpdocs\php_error.log
display_errors=off
log_errors=on
open_basedir="G:/PleskVhosts//xxxxxxxxx.com\;C:\Windows\Temp\"
safe_mode=off
sendmail_from=xxxxxxxxx#xxxxxxxxx.shr.prod.phx3.secureserver.net
SMTP=relay-hosting.secureserver.net
This article helped me get the absolute path
I restarted the IIS application pool and created an empty php_error.log file in my httpdocs folder, however it still never wrote anything to the log file, and continued to just give the Internal Server Error. I also tried removing all the other lines in the .user.ini file besides the error_log line, restarted, and still nothing. I also tried stopping the application pool and starting it up again, still nothing.
I double checked the phpinfo and the log_errors field was set to on, and the correct directory was set for error_log. So it is seeing the .user.ini file.
I tried calling their support but they couldn't help me.
They linked me to this article about IIS error handling. I created a web.config file and put it in the httpdocs folder as it says in that article. Now I get something different. Now the output of my page is the error that I was passing to error_log. So in other words, when I visit test.php the output on the screen says:
this is an error
Notice how the php script dies after the error? Not only should the error not be put on screen (it should be put in the php_error.log file, which is still not being written to at this point), but the php script shouldn't die afterwards unless it runs into a fatal error. I should see the "hello" from the echo and I don't.
What do I have to do to get this working properly?
My hosting plan has IIS 8 and PHP 5.4 installed.
PS. Their support basically said they cant help me any further because changing configuration files is "coding" and they dont offer coding support.
PHP needed file read write permisions

Hostgator php 5.4 upgrade in htaccess throws error 404

I have a project hosted on Hostgator. I need PHP 5.4 so, as they require, I add the following line to my .htaccess file:
AddType application/x-httpd-php54 .php
The issue is that with this line, any URL throws an error 404. Without this line, everything works fine - but with PHP 5.3 only.
I'm at a loss to understand how this line and error 404 are connected. Anyone has an idea?
It's the php.ini file, probably located in your root user folder. You have to remove/rename it. There is a php.ini incompatibility between 5.2ish and 5.4.
Also, I've never been able to get AddType to work. I've always had to use the older AddHandler.
On a side note, doing some more playing around in the php.ini, I figured out that register_globals=On was causing my 5.4 to hickup. I thought it was shut off, but I guess not... I changed it to off and my phpinfo page came alive.
And even more testing against my original php.ini file, I learned that: "allow_call_time_pass_reference = On" must be commented out...
Long story short, check your user php.ini files...

500 Internal Server Error for php file not for html [duplicate]

This question already has answers here:
Getting Internal Server Error while trying to access my site
(5 answers)
Closed 6 years ago.
My site having 4-5 static pages only. index.html & index.php both are there. index.html is working fine. If I change to index.php, it's giving 500 Internal Server Error. I don't know where is my mistake?
Note:
If I use .htaccess file with php_flag display_errors 1,
It's showing Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.
If I use .htaccess file with empty,
It's showing Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
And if I give ../contact-us.php, it's showing correctly.
Thanks...
500 Internal Server Error is shown if your php code has fatal errors but error displaying is switched off. You may try this to see the error itself instead of 500 error page:
In your php file:
ini_set('display_errors', 1);
In .htaccess file:
php_flag display_errors 1
A PHP file must have permissions set to 644. Any folder containing PHP files and PHP access (to upload files, for example) must have permissions set to 755. PHP will run a 500 error when dealing with any file or folder that has permissions set to 777!
I was having this problem because I was trying to connect to MySQL but I didn't have the required package. I figured it out because of #Amadan's comment to check the error log. In my case, I was having the error: Call to undefined function mysql_connect()
If your PHP file has any code to connect with a My-SQL db then you might need to install php5-mysql first. I was getting this error because I hadn't installed it. All my file permissions were good. In Ubuntu, you can install it by the following command:
sudo apt-get install php5-mysql
It was changing the line endings (from Windows CRLF to Unix LF) in the .htaccess file that fixed it for me.
I know this question is old, however I ran into this problem on Windows 8.1 while trying to use .htaccess files for rewriting. My solution was simple, I forgot to modify the following line in httpd.conf
#LoadModule rewrite_module modules/mod_rewrite.so
to
LoadModule rewrite_module modules/mod_rewrite.so
Restarted the apache monitor, now all works well. Just posting this as an answer because someone in the future may run across the same issue with a simple fix.
Good luck!
Google guides me here but it didn't fix mine, this is a very general question and there are various causes, so I post my problem and solution here for reference in case anyone might read this later.
Another possible cause of 500 error is syntax error in header(...) function, like this one:
header($_SERVER['SERVER_PROTOCOL'] . '200 OK');
Be aware there should be space between server protocol and status code, so it should be:
header($_SERVER['SERVER_PROTOCOL'] . ' 200 OK');
So I suggest check your http header call if you have it in your code.

500 Internal Server Error?

Recently, I put my project which is php+smarty+mysql in my httpd server. But I encountered an error that says:
500 Internal Server Error
My OS is archlinux, and the httpd server and php were installed like this:
sudo pacman -S apache php
If I use a test native php file which contains the following:
<html>
<head>
<title>PHP Test Page</title>
</head>
<body>
This is Arch Linux, running PHP.
<?php
phpinfo();
?>
</body>
</html>
it runs correctly. It tells me that the php can work well. But why is my project with smarty not working? Is there any one who has encountered this problem?
With the info you provided it's difficult to say.
Error 500 happens because you did some error in the code that is supposed to produce the page, or the code generates some unhandled exception.
My suggestion is to visit the page that gives you the 500 error, and then try to comment out all your code. See if the issue is still present. If not, uncomment the code until you find the critical part that originates the error. Could be anything, a typo, a file not found, a logical error, anything.
Also, check in the webserver logs, if you can read them.
Look in your Apache error log (often found at /var/log/httpd/error_log, though this varies greatly). It will have more information about the server error.
Check to make sure that any .htaccess files are correct (syntax wise).
just happened to me and wanted to write down the solution.
The configured Smarty cache directory (/var/cache/Smarty) was configured with incorrect permissions, the apache process needs to create files in that directory.
This is the directory you set with the compile_dir directive.
BTW, the error_log file doesn't show anything with this error, Firebug shows a 500 Internal Server Error.
I was able to get the error details by checking error.log file inside
/var/log/apache2
in ubuntu 16.04

Categories