WordPress: server error

If you try to move wordpress sites between servers you may experience this issue.

HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.

I had no idea what causing this. It was working fine with the other server. After a lot of debugging and googling I understood this error might be because PHP memory limit. So I tried to increase memory limit. Again as there are couple ways to increase this variable and not all hosts allow all of them I had to face some issues.  below are the possible ways to increase PHP memory limit and get rid of this error to make your site work again.

 

1. php.ini

By changing following variable you can increase emory limit value in php.ini

memory_limit = 128M ;

But chances are that you might be n shared hosting and your hosting provider might not allow you to make any changes directl to php.ini. In that case you can set this in .htaccess or in run time using ini_set variable.

php_value memory_limit 64M

Above is the .htaccess way of increasing memory limit.  Again some hosts wont allow you to set PHP variables using .htaccess . In this case you may experience Internal server error as those lines code in .htaccess would be treated as invalid. In that case you can change memory limit value using ini_set like below. You can also set a wordpress constant WP_MEMORY_LIMIT in wp-config.php and this is better way.

 

ini_set('memory_limit', '128M');

define('WP_MEMORY_LIMIT', '164M'); /*wordpress way*/