WordPress way to make an Ajax call in a custom page template is unbelievable complicated. I cant get it to run at all without crashing my whole site. Why I need to do it that way? My other Ajax calls are not needing this complicated and complex way too.
So what I am trying to do:
I want to add a feature to the Shop that Resellers can enter there ID and reorder new bags for there Shops. So long so good.
I got my landing page:
<?php
/*
Template Name:
*/
?>
<?php
get_header();
?>
<section id="main" class="reseller-page">
<form action="<?php echo get_stylesheet_directory_uri(); ?>/reseller.php" method="GET" id="resellerform">
Reseller ID: <br><input type="text" name="rid" id="rid">
<button id="resellercheck">SUCHEN</button>
</form>
<div id="resellerwrapper" style="display: none;">
<div id="resellerinfo"></div>
<div id="resellerorder" style="display: none;">
<h2>Bestellformular:</h2>
<?php
$args = array('post_type' => 'product', 'posts_per_page' => -1, 'product_cat' => 'tabak-taschen');
query_posts($args);
if (have_posts()):
echo '<div id="reseller-select-wrapper"><select id="artikelselector">';
while (have_posts()) : the_post();
echo '<option value="' . $product->get_sku() . ': ' . $product->get_title() . '" data-type-href="' . get_permalink() . '">' . $product->get_sku() . ': ' . $product->get_title() . '</option>';
endwhile;
echo '</select>Menge: <input id="reseller-menge" type="text" class="input-text"><button value="hinzufügen" id="reseller-add-to-form">+</button></div>';
endif;
?>
<form action="" method="POST" id="reseller-bestell-liste">
<ul>
</ul>
<textarea name="nachricht" id="reseller-msg"></textarea>
<input type="submit" id="reseller-send-order" value="bestellen" title="verbindliche Bestellung" />
</form>
</div>
</div>
</section>
<?php
get_footer();
?>
then the checkresellerid.php that checks the database if the RiD(ResellerID) is in the DB:
<?php
//header('Content-Type: text/html; charset=utf-8');
include 'db_connect.php';
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_GET['rid'])) {
// $rid = "R10369";
$rid = $_GET['rid'];
$result = mysqli_query($con, "SELECT rid FROM reseller WHERE rid = '" . $rid . "'");
$ergebnis = mysqli_num_rows($result);
if ($ergebnis == 1) {
$RJSON = [];
$RQUERY = mysqli_query($con, "SELECT * FROM reseller WHERE rid = '" . $rid . "'");
while ($row = mysqli_fetch_array($RQUERY, MYSQL_ASSOC)) {
$RJSON[] = array(
// 'rid' => $row['rid'],
'name' => $row['name'],
'adresse' => $row['adresse'],
'email' => $row['email'],
'phone' => $row['phone']
);
}
echo json_encode($RJSON);
} else {
echo 'false';
}
mysqli_close($con);
}
?>
When I enter something in the Input Field(no matter if its in the DB or not) I get a 500 Internal Server Error. But why my other Ajax calls on the Site like my «Love a product» feature in the woocommerce shop loop are working but not this little fella? on my localhost is everything runnning correctly. Did it has anything to do because its a custom php file(template page file)?
Check the Example Page >>> Here <<<
I tried registering a function in functions.php but that crashed the whole site.
How can I pack my php script in this functions.php and call it correctly? Why is it even neccesary to make it that complicated? I am googling this for hours and tryied many ways, nothing works…
Thanks for any help and sorry for my bad englisch.
EDIT:
my functions.php looks like this:
<?php
/****************************************
Theme Setup
*****************************************/
require_once( get_template_directory() . '/lib/init.php' );
require_once( get_template_directory() . '/lib/theme-helpers.php' );
require_once( get_template_directory() . '/lib/theme-functions.php' );
require_once( get_template_directory() . '/lib/theme-comments.php' );
/****************************************
Require Plugins
*****************************************/
require_once( get_template_directory() . '/lib/class-tgm-plugin-activation.php' );
require_once( get_template_directory() . '/lib/theme-require-plugins.php' );
add_action( 'tgmpa_register', 'mb_register_required_plugins' );
add_theme_support( 'woocommerce' );
/****************************************
Misc Theme Functions
*****************************************/
/**
* Define custom post type capabilities for use with Members
*/
function mb_add_post_type_caps() {
// mb_add_capabilities( 'portfolio' );
}
/**
* Filter Yoast SEO Metabox Priority
*/
add_filter( 'wpseo_metabox_prio', 'mb_filter_yoast_seo_metabox' );
function mb_filter_yoast_seo_metabox() {
return 'low';
}
function checkResellerId(){
include 'db_connect.php';
wp_localize_script( 'function', 'checkResellerId', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
if (isset($_GET['rid'])) {
// $rid = "R10369";
$rid = $_GET['rid'];
$result = mysqli_query($con, "SELECT rid FROM reseller WHERE rid = '" . $rid . "'");
$ergebnis = mysqli_num_rows($result);
if ($ergebnis == 1) {
$RJSON = [];
$RQUERY = mysqli_query($con, "SELECT * FROM reseller WHERE rid = '" . $rid . "'");
while ($row = mysqli_fetch_array($RQUERY, MYSQL_ASSOC)) {
$RJSON[] = array(
// 'rid' => $row['rid'],
'name' => $row['name'],
'adresse' => $row['adresse'],
'email' => $row['email'],
'phone' => $row['phone']
);
}
echo json_encode($RJSON);
} else {
echo 'false';
}
mysqli_close($con);
}
}
add_action( 'wp_ajax_nopriv_product_s', 'checkResellerId' );
add_action( 'wp_ajax_product_s', 'checkResellerId' );
function resellerMail(){
wp_localize_script( 'function', 'resellerMail', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) ) );
$zieladresse = 'xxx';
$absenderadresse = 'xxxReseller';
$absendername = 'xxxReseller';
$betreff = 'Reseller-Bestellung';
$trenner = ":t";
if ($_SERVER['REQUEST_METHOD'] === "POST") {
$header = array();
$header[] = "From: ".mb_encode_mimeheader($absendername, "ISO-8859-15", "Q")." <".$absenderadresse.">";
$header[] = "MIME-Version: 1.0";
$header[] = "Content-type: text/plain; charset=ISO-8859-15";
$header[] = "Content-transfer-encoding: 8bit";
$mailtext = "";
foreach ($_POST as $name => $wert) {
if (is_array($wert)) {
foreach ($wert as $einzelwert) {
$mailtext .= $name.$trenner.$einzelwert."n";
}
} else {
$mailtext .= $name.$trenner.$wert."n";
}
}
mail(
$zieladresse,
mb_encode_mimeheader($betreff, "ISO-8859-15", "Q"),
$mailtext,
implode("n", $header)
) or die("Die Mail konnte nicht versendet werden.");
echo $mailtext; // nur check für ajax response, später wieder entfernen!!!!
echo 'Ihre Bestellung wurde an uns versandt.<br>Sie werden telefonisch von uns kontaktiert um die Bestellung zu bestätigen.';
exit;
}
//header("Content-type: text/html; charset=utf-8");
}
add_action( 'wp_ajax_nopriv_product_s', 'resellerMail' );
add_action( 'wp_ajax_product_s', 'resellerMail' );
Screen of the 500 Error:
![Screenshot 500 Internal error][2]
Hello,
Since the new version 2.4, I’m having problems in one computer (which is very strange), that does not load the media Library and Variations (modules with ajax). I’ve updated every plugin and WordPress 4.3 but it does not solve it. It has to be related with Woocommerce, because when I deactivate it, it does not have any problem.
This is the error message in Console:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,plupload&ver=4.3:5 POST https://equitienda.es/wp-admin/admin-ajax.php
500 (Internal Server Error)send @ load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,plupload&ver=4.3:5m.extend.ajax @ load-scripts.php?c=0&load[]=jquery-core,jquery-migrate,utils,plupload&ver=4.3:5j @ load-scripts.php?c=0&load[]=hoverIntent,common,admin-bar,underscore,shortcode,backbone,wp-util,wp-b…:376(anonymous function) @ load-scripts.php?c=0&load[]=hoverIntent,common,admin-bar,underscore,shortcode,backbone,wp-util,wp-b…:376
Regards.
How to fix ajax POST /wp-admin/admin-ajax.php 500 (Internal Server Error)? I’m receiving this error in console when I’m about to call my ajax code backend. It appears to me that I am missing global variable in enable the code to work. See the wrong and correct coding below. It might be not the same issue on you but you can found a clue how to fix 500 (Internal Server Error) error.
Wrong code, missing “global $wpdb;” global variable and this is causing 500 (Internal Server Error) error
// JS CODE jQuery( document ).ready( function( $ ){ $( '#gallery #select-friend' ).keyup( function(){ $.ajax({ url : ajaxurl, type : 'post', data : { action : 'ys_creadit_to', keyword : $( '#gallery #select-friend' ).val() }, success : function(data){ console.log(data); } }); }); }); // PHP CODE add_action( 'wp_ajax_ys_creadit_to', 'ajax_creadit_to' ); add_action( 'wp_ajax_nopriv_ys_creadit_to', 'ajax_creadit_to' ); function ajax_creadit_to(){ $keyword = isset( $_POST['keyword'] ) ? explode( ' ', $_POST['keyword'] ) : array(); $s = ""; if( $keyword ) : foreach( $keyword as $id => $word ) : if( $id != 0 && ( ( count( $keyword ) - 1 ) < $id ) ) : $s .= " OR "; endif; $s .= "(display_name LIKE '%$word%')"; endforeach; endif; $results = $wpdb->get_results( "SELECT ID, display_name FROM wp_users WHERE display_name LIKE '%$s%' LIMIT 0, 50" ); print_r( $results ); die(); }
Correct and working code
// JS CODE jQuery( document ).ready( function( $ ){ $( '#gallery #select-friend' ).keyup( function(){ $.ajax({ url : ajaxurl, type : 'post', data : { action : 'ys_creadit_to', keyword : $( '#gallery #select-friend' ).val() }, success : function(data){ console.log(data); } }); }); }); // PHP CODE add_action( 'wp_ajax_ys_creadit_to', 'ajax_creadit_to' ); add_action( 'wp_ajax_nopriv_ys_creadit_to', 'ajax_creadit_to' ); function ajax_creadit_to(){ global $wpdb; $keyword = isset( $_POST['keyword'] ) ? explode( ' ', $_POST['keyword'] ) : array(); $s = ""; if( $keyword ) : foreach( $keyword as $id => $word ) : if( $id != 0 && ( ( count( $keyword ) - 1 ) < $id ) ) : $s .= " OR "; endif; $s .= "(display_name LIKE '%$word%')"; endforeach; endif; $results = $wpdb->get_results( "SELECT ID, display_name FROM wp_users WHERE display_name LIKE '%$s%' LIMIT 0, 50" ); print_r( $results ); die(); }
Gravity Forms Image Upload Field for User Registration
Image Upload Field for User Registration is a Gravity Forms add-on that is specialize for front-end user registration form. It has the ability to upload a user avatar or profile picture during the user registration process. This field has advance settings that can help you adjust the preferred design on the front-end form such as image dimension (width and height), text button, etc. and other settings to enhance front-end layout.
Image Upload Field for User Registration requires Gravity Forms and Gravity Forms User Registration Add-On before install.
Add to cart VIEW PRODUCT
Gravity Forms Media Upload Field
Media Upload Field is a Gravity Forms add-on that allow users to upload an image with advance front-end setup, and easy to use image cropping. This field provide advance settings to manage the image dimension (width and height) and other settings that can be found in the front-end layout.
Add to cart VIEW PRODUCT
I’m getting 500 errors with AJAX on the admin side. However, these errors aren’t being logged in the Apache logs so they’re rather hard to debug.
Is there some way I can find out what they are?
Thanks
asked Mar 2, 2012 at 13:16
1
Sometimes I have a 500 error ( from NGinx ) just because I have a «character» getting outputted before the first header gets written ( or in-between ).
Activate WP_DEBUG = true and see what happens. 99% of the case I could spot the error from there. ( and it was nearly all the time the above error ).
Post back if that doesn’t solve your debug difficulty problem. We’ll have a look at your apache config by then.
answered Mar 2, 2012 at 14:24
nembletonnembleton
3492 silver badges3 bronze badges
1
910 votes
1 answers
Get the solution ↓↓↓
I am getting a strange 500 Internal Server Error with a new script I am trying to implement in the actual site. Here’s a screen:
I can route to this files manually without problems and they are working too. But not in the script itself. The Paths are also correct.
Heres the link to the Site:
(just enter R10369 in the input field or a random number)
Everything else is working correctly except these 3 files:
reseller.php,
checkresellerid.php,
resellermail.php
I googled a bit and everywhere is the .htaccess mentioned. but I never modified it or overwrited it. What could be the Problem? Thanks for any Help and sorry for my bad Englisch.
(Let me know if you want to see the php files)
EDIT: I managed to include my new php files into wordpress but i still got the 500 Error
2022-06-11
Write your answer
263
votes
Answer
Solution:
I checked out the website.
I think WordPress doesn’t let you call .php inside of it’s system.
I mean you cannot call PHP files for ajax.
You need to use wordpress ajax. Here is a snippet how to use ajax:
Function.php in your theme file.
function myajax()
{
//do stuff
die();
}
add_action( 'wp_ajax_nopriv_product_s', 'myajax' );
add_action( 'wp_ajax_product_s', 'myajax' );
And in your javascript file using jQuery:
The url may change, maybe it’s enough to have wp-admin/admin.ajax.php or something like this, i don’t really remember right now.
$.post('/wp-admin/admin-ajax.php',{action:'myajax',yourdata:"mydata"}).done(function(data)
{
//do stuffs
});
Update:
So basically if you want to have ajax request inside wordpresss, you need to define these things and use it like this. the «action» parameter is the function name which you want to call. And you need to put the PHP code into your current theme’s function.php.
Share solution ↓
Additional Information:
Date the issue was resolved:
2022-06-11
Link To Source
Link To Answer
People are also looking for solutions of the problem: warning: undefined array key
Didn’t find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Question
Having a problem with WordPress Ajax calls. In the development environment and in the admin mode on the production server, the ajax works perfectly. When the JQuery post call is made by the same code and with the same, well formatted, request data on the front-end, it fails. Debugged the client side and got the same server response with both the Safari Web Inspector and the Chrome Developer tools. The error message is Internal Server Error (500). What’s going on with IIS 10.0 ? How to set up IIS to accept front-end Ajax calls? Should I install Ajax.Net ?
Solution
AJAX (Asynchronous JavaScript And XML) is a client-side technology. On the server side the IIS can’t distinguish between normal web page and AJAX POST, GET requests. There is no need to ‘setup’ your IIS or Apache for AJAX. jQuery is nothing else than an easy-to-use wrapper for the native JavaScript. ASP.NET AJAX is a set of technologies to add AJAX support to ASP.NET. It integrates client script libraries with the ASP.NET. It has nothing to do with your PHP WordPress side.
500 internal server error is an irritating all-you-cannot-eat message. To trace the error, first look at the logs of IIS to discover something more about the infamous error, and second, find and look at the WordPress plugins and themes, ie. the PHP code. The typical cause is conflicts between plugins and/or themes, including child theme with your code. It’s true for other technologies as well, always look at the web site installation, identify possible conficts, and check out your server side code.
IIS detailed error log
1. On Windows Server 2008/2012 you can use Advanced Logging option of IIS 7.5 or 8. You may need to download and install it from Microsoft. Check out the latest version if it’s already available for IIS 10.
2. Go to the server. Just to be sure, look at the folders of PHP and website if permissions are set properly. Open IIS Manager, select server and website. Enable Trace Logging for Failed Requests regardless of the use of the Advanced Logging option. In the Actions pane at the Configure group, click Failed Request Tracing and set the directory you will use:
3. Open your web browser and load the website. When needed, activate whatever you need to run the AJAX call, for example click on a button if that initiate the call. Recheck AJAX ‘data’ request if it’s really formatted well.
4. Go back to the server, find the log directory where you will be greated by a couple of large xml files. Open the latest one the IIS generated when serving your site’s request. If you run into an access error, copy the file into a folder where you have open/read permissions. Well, you’ll spend some time to locate the line you really wanted to see. Like this:
Now we know that in this case the 500 error is triggered by ‘Reached the end of the file’. That rarely means the PHP had problems reading a physical file though.
WP plugin conflicts at handling AJAX calls
1. Must do checklist
– Step A: disable all other plugins or themes.
– Step B: reload the web site on the client side. Check out if the 500 error pops up. If not, activate the next plugin.
– Step C: go back to Step B and repeat it until the suspect has been caught. If you are lucky.
If not, your code is likely in conflict with WordPress (PHP installation) or parent theme.
2. PHP, WordPress and your code
Probably you are unlucky and found nothing so far. Switch on WP debug mode (wp-config.php) and see if it helps locate suspects:
Likely found something relevant here.
3. admin-ajax.php
You may want to diagnose and look at admin-ajax.php to see how server responses (How ? Use Chrome Developer tools for example). Initially admin-ajax.php was used for autosave, post locking and log-in expiration warnings. You will notice third party plugins polling this file frequently, thinking it’s a horse race, that may cause problems without any code error, but doing nothing good at all. Each POST request had a corresponding PHP script execution on the server using expensive CPU time.
4. Your code
We all have bad days and write bad codes, and sometimes need another two eyes to catch the obvious. Invite someone to look at your code and offer a free cup of tea.
The 500 Internal Server Error is arguably the most frustrating error you can experience with WordPress because it can literally mean just about anything. That’s not to say you can’t fix it—you can, and one of the solutions below should help you get your site back up and running.
There are a few common causes, such as having a corrupted .htaccess file, exceeding your PHP memory limit, and having improper file permissions. There are less common causes, too, including issues with your plugins or server.
Unfortunately, there’s no straightforward, 5-minute fix. Solving your 500 internal server error will require troubleshooting that will take time and patience. Typically, fixing this cryptic error will help you determine what actually caused it.
To help you, I’ve put together this troubleshooting guide. Start with the first potential fix—creating a new .htaccess file—and work through each solution before moving onto the next possible fix.
What is a 500 Internal Server Error?
When you visit a site, your browser sends a request to the site’s server. The server processes the request and sends back the resources to display the page, along with an HTTP header, which includes an HTTP status code.
The status code tells your browser the status of the request. For example, a 200 status code means smooth sailing—everything is OK. But if you get a 500 status code, it means something went wrong, and the server isn’t quite sure what went wrong.
Basically, the 500 internal server error code is a generic “catch-all” that means the server encountered an unexpected condition that prevented it from fulfilling the request.
There are several different types of 500 status error codes, which all mean something different, such as 501 Not Implemented, 502 Bad Gateway, 503 Service Unavailable, and 504 Gateway Timeout.
Naming Variations for 500 Internal Server Errors
There are many variations of the 500 internal server error message, depending on the many web servers and browsers available. The website you’re visiting might also have its own custom page for these errors.
Here are several variations of what you might see:
- 500 Internal Server Error
- Internal Server Error
- 500 Internal server error
- Error 500
- HTTP Error 500
- HTTP Error 500 – Internal Server Error
- Temporary Error (500)
No matter which of these (or other variations) you see, they all mean the same thing—something has gone wrong and the server doesn’t know what’s happened.
How to Fix the 500 Internal Server Error
Like I mentioned above, this error indicates that something went wrong, but what the cause is a mystery. With resolving these errors, you essentially need to work backward—find the fix first and then you’ll know what caused the error.
Generally, 500 errors happen due to an issue on the server, but they can also happen due to some kind of client-side issue. So we’ll work through a number of different solutions below that involve both.
Create a Backup First
The fixes below involve tinkering with your site under the hood, i.e. making changes to your site’s root directory. So it’s critical you run a backup.
And if you don’t already have a backup plugin or some other solution in place, it’s high time you got one!
Some of my favorite tools include BackUpWordPress, VaultPress, and BackupBuddy. If you’re interested in database backups, check out WP Migrate DB Pro or simply use WP-CLI to run quick exports.
If you’re with a web host that offers backups, that’s great. But I’d recommend having your own solution that you can quickly access in an emergency without having to go through your host.
1. Check Your .htaccess File
If your site is hosted on a server running Apache, there’s a chance your .htaccess file is corrupted. This can happen after installing plugins or making other changes to your site.
It’s an easy fix. All you need to do is replace your corrupted .htaccess file with a new one.
Usually, all you need to do to create a new .htaccess file is to re-save your permalinks settings in the WordPress dashboard. But if your site is down, it’s likely you can’t log in to your site, ruling out this option.
So you’ll need to use FTP or cPanel to access your site’s files and locate your .htaccess file. For a step-by-step walkthrough on how to do this with FTP and cPanel, check out What is .htaccess and How to Use it With WordPress.
Before you go replacing your old .htaccess file with a new one, create a backup of your name. To do this, simply rename your existing file something like .htaccess-old. WordPress will then stop recognizing this file.
Refresh your site and if it loads properly, you know your .htaccess file has caused the 500 error. Now, revert your .htaccess file to its proper name—the issue will return, but now we’re going to fix it.
For WP Rocket users, you’ll need to be especially careful of what you do next with your .htaccess file because it contains performance optimization rules that you shouldn’t mess around with. So check out Resolve 500 Internal Server Error for what to do next.
If you’re not a WP Rocket user (what’s going on!?), create a new .htaccess file that includes the following, and then upload it to your site’s root directory:
These are the rules shown in the image above:
#BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
#END WordPress
2. Increase PHP Memory limit
The cause of your 500 error could be that you’re hitting your PHP memory limit. This often happens due to poorly-coded plugins, when a site is using a lot of plugins, or when a site is using resource-intensive plugins.
All you need to do to fix this issue is increase the PHP memory limit for your site. There are a few different ways you can do this that involve updating your .htaccess file, php.ini file, or wp-config.php file.
For each of the three memory fixes below, don’t forget to refresh your site to check if it’s working so you know what’s causing your 500 internal server error.
1. Increase PHP Memory Limit in .htaccess File
Find your .htaccess file in the root directory of your site and add the following line:php_value memory_limit 256M
This will increase your memory limit to 256 MB. If you can’t find your .htaccess, make sure you’re able to view hidden files. And if you don’t have an .htaccess file, create a new one and paste in the line above.
2. Increase PHP Memory Limit in php.ini File
You’ll find your php.ini file in the wp-admin folder in your root directory. Open it up and look for the line that starts with “memory_limit.” If it shows 64 MB or lower, replace it with this line:
memory_limit = 256M
If you can’t find your php.ini file (make sure you’ve got “show hidden files” enabled), then you’ll need to create a new file, paste in the line above, name it php.ini and save it to your wp-admin folder.
3. Increase PHP Memory Limit in wp-config.php File
If updating your .htaccess and php.ini files didn’t work, you can try increasing the memory limit in your wp-config.php file.
Add the following line to your wp-config.php file just before the “happy blogging” line:
define('WP_MEMORY_LIMIT', '256M');
Save the file and refresh your site. If it still isn’t working and you have a sneaking suspicion your plugins could be pushing your PHP memory limits, get in touch with your web host about increasing your memory on the server side.
3. Audit Your Plugins
Plugins can also cause 500 internal server errors. This includes outdated plugins causing compatibility issues and even new plugins that have been coded poorly. You might even find that you get the 500 error immediately after installing a new plugin.
To find out which, if any, of your plugins is causing your error, you’ll need to bulk deactivate your plugins and reactivate them one at a time.
If you’re unable to access your WordPress dashboard, FTP into your server and open your wp-content folder, find your plugins folder and rename it something like plugins-old—this will effectively deactivate all of your plugins.
Then refresh your site. If it starts working, the cause of your 500 error is one of your plugins.
The next step is identifying which plugin is the culprit. To do this, rename your plugins folder back to “plugins” and then go into the folder and rename each individual plugin folder, one-by-one until you’re able to refresh your site and it works again.
When you find the offending plugin, get in touch with the plugin developer for help.
4. Check File Permissions
If none of the above has worked, you could have an issue with file permissions. Files in your WordPress directory should be set to 755 or 644 and when they’re mistakenly or accidentally set to anything else it can set off a 500 error.
To check your file permissions, FTP into your server and check your site’s directory. Here, I’m using Filezilla to access my test site and as you can see my permissions are set to 755 for folders and 644 for everything else.
The WordPress Codex recommends the following file permissions:
- All directories should be 755 or 750.
- All files should be 644 or 640. (The exception being wp-config.php, which you can set to 440 or 400 to prevent other users on the server from reading it.)
- Directories should never be set to 777.
If you find that a certain file has the wrong permission, just right-click it in your FTP program to access file permissions and update it to the appropriate number.
Check out How to make system files (.htaccess, wp-config.php) writeable to learn more about updating file permissions.
5. Reinstall WordPress Core Files
It’s not unusual for WordPress core files to become corrupted, especially on older sites that have been customized and updated many times.
To fix this issues, you’ll need to replace your core WordPress files with fresh ones. There’s no need to re-install WordPress—simply download the latest version of WordPress and unzip the file. FTP into your site’s root directory and upload the wp-admin and wp-includes folders from the zip file you just downloaded, overwriting the older versions.
Doing it this way, you won’t overwrite your plugins and themes.
Refresh your site. If the 500 error has disappeared, you’ve pinpointed the cause—corrupted core files.
6. Contact Your Web Host
If you’re still getting the 500 internal server error after working through each of the fixes above, it’s time to contact your web host. Your host’s server logs might be able to shed some light on what’s causing the error so it can be resolved.
Rather than skip the above and go straight to your host for help, it’s a good idea to investigate the cause of your error first. This way, you can provide your host with a rundown of what you’ve tried, so your error isn’t simply dismissed as an issue with your site’s files.
This is particularly true if you’re on cheaper shared hosting. If you’re on managed WordPress hosting, it’s usually the case that your host will help you pinpoint and fix you 500 internal server error.
Wrapping Up
This is by no means an exhaustive list of 500 internal server error fixes. What’s causing your particular issue could be just about anything. But this list will give you a head start on fixing and finding the cause (in that order!).
Lastly, don’t forget to back up your site before updating files in your root directory. If you make a change that impacts your site, you’ll be able to quickly revert to a previous backup.
Have you experienced a 500 internal server error? How did you fix it? Let us know in the comments below!
Are you seeing 500 internal server error in WordPress?
Internal server error is one of the most common WordPress errors. Since the error doesn’t give any other information, many beginners find it quite frustrating.
In this article, we will show you how to easily fix internal server error in WordPress.
What Causes Internal Server Error in WordPress?
Internal server error is not specific to WordPress. It can happen with any website running on a web server. Due to the generic nature of this error, it does not tell the developer anything.
Asking how to fix an internal server error is like asking your doctor how to fix the pain without telling them where the pain is.
Internal server error in WordPress is often caused by plugin or theme functions. Other possible causes of internal server error in WordPress that we know of are: corrupted .htaccess file and PHP memory limit.
We have also heard internal server error only showing up when you are trying to access the admin area while the rest of the site works fine.
That being said, now let’s take a look at how to go about troubleshooting the internal server error in WordPress.
Video Tutorial
Subscribe to WPBeginner
If you don’t like the video or need more instructions, then continue reading.
Checking for Corrupt .htaccess File
The first thing you should do when troubleshooting the internal server error in WordPress is check for the corrupted .htaccess file.
You can do so by renaming your main .htaccess file to something like .htaccess_old. To rename the .htaccess file, you will need to login to your site using FTP or File Manager app in your hosting account’s cPanel dashboard.
Once you connected, the .htaccess file will be located in the same directory where you will see folders like wp-content, wp-admin, and wp-includes.
Once you have renamed the .htaccess file, try visiting your site to see if this solved the problem. If it did, then give yourself a pat on the back because you fixed the internal server error.
Before you move on with other things, make sure that you go to Settings » Permalinks page in WordPress admin area and click the save button without making any changes. This will generate a new .htaccess file for you with proper rewrite rules to ensure that your post pages do not return a 404 error.
If checking for the corrupt .htaccess file solution did not work for you, then you need to continue reading this article.
Increasing the PHP Memory Limit
Sometimes internal server error can happen if you are exhausting your PHP memory limit. Use our tutorial on how to increase PHP memory limit in WordPress to fix that.
If you are seeing the internal server error only when you try to login to your WordPress admin or uploading an image in your wp-admin, then you should increase the memory limit by following these steps:
- Create a blank text file called php.ini
- Paste this code in there: memory=64MB
- Save the file
- Upload it into your /wp-admin/ folder using FTP
Several users have said that doing the above fixed the admin side problem for them.
If increasing the memory limit fixed the problem for you, then you have only fixed the problem temporarily. You still need to find the cause that is exhausting your memory limit.
This could be a poorly coded plugin or even a theme function. We strongly recommend that you ask your WordPress web hosting company to look into the server logs to help you find the exact diagnostics.
If increasing the PHP memory limit did not fix the issue for you, then you are in for some more troubleshooting.
Deactivate all Plugins
If none of the above solutions worked for you, then this error is most likely being caused by a specific plugin. It is also possible that it is a combination of plugins that are not playing nice with each other.
Sadly, there is no easy way to find this out. You have to deactivate all WordPress plugins at once.
Follow the instructions in our guide on how to deactivate all WordPress plugins without WP-Admin.
If disabling all plugins fixed the error, then you know it is one of the plugins that is causing the error.
Simply go to the WordPress admin area and click on ‘Plugins’. Now you need to reactivate one plugin at a time until you find the one that caused the issue. Get rid of that plugin, and report the error to the plugin author.
Re-uploading Core Files
If the plugin option didn’t fix the internal server error, then it is worth re-uploading the wp-admin and wp-includes folder from a fresh WordPress install.
This will NOT remove any of your information, but it may solve the problem in case any file was corrupted.
First you will need to visit the WordPress.org website and click on the Download button.
This will install WordPress zip file to your computer. You need to extract the zip file and inside it you will find a wordpress folder.
Next you need to connect to your WordPress website using an FTP client. Once connected go to the root folder of your website. It is the folder that has wp-admin, wp-includes, wp-content folders inside it.
In the left column open the WordPress folder on your computer. Now you need to select wp-includes and wp-admin folders and then right-click and select ‘Upload’.
Your FTP client will now transfer those folder to your server. It will ask you whether you would like to overwrite the files. Select ‘Overwrite’ and then select ‘Always use this action’.
Your FTP client will now replace your older WordPress files with newer fresh copies. If your WordPress files were corrupted, then this step will fix the internal server error for you.
Ask your Hosting Provider
If all methods fail to fix internal server error on your website, then it is time to get some more help. Contact your web hosting support team and they will be able to check the server logs and locate the root cause of the error.
If you want to continue troubleshooting on your own, then see our ultimate WordPress troubleshooting guide for beginners.
We hope this article helped you fix the internal server error in WordPress. You may also want to see our complete list of the most common WordPress errors, and our beginners guide on troubleshooting WordPress.
If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.
Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.
Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. We have been creating WordPress tutorials since 2009, and WPBeginner has become the largest free WordPress resource site in the industry.