Internal Server Error - Invalid command 'RewriteEngine' (Ubuntu Apache/PHP)

What is Internal Server Error?

It usually a server misconfiguration (check .htaccess file) or problem with your server side script.

First of all check for error log

$ 

sudo vim /var/log/apache2/error.log


If log file become empty then enable it via php.ini



For php7
$ sudo vim /etc/php/7.0/apache2/php.ini 

or

For php5
$ sudo vim /etc/php5/apache2/php.ini 

Find display_errors, display_startup_errors
, error_reporting
 (Which look’s like below)

;display_errors
;   Default Value: On
;   Development Value: On
;   Production Value: Off

;display_startup_errors
;   Default Value: Off
;   Development Value: On
;   Production Value: Off

;error_reporting
;   Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
;   Development Value: E_ALL
;   Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

Uncomment it via removing semicolons (After change it will look like below)

display_errors
;   Default Value: On
;   Development Value: On
;   Production Value: Off

display_startup_errors
;   Default Value: Off
;   Development Value: On
;   Production Value: Off

error_reporting
;   Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED
;   Development Value: E_ALL
;   Production Value: E_ALL & ~E_DEPRECATED & ~E_STRICT

Restart apache via below command


$ sudo service apache2 restart 

or

$ sudo /etc/init.d/apache2 restart


Now check in error.log file for Internal Server related problem.


If in error log you got module related problem like below:

/var/www/html/.htaccess: Invalid command ‘RewriteEngine’, perhaps misspelled or defined by a module not included in the server configuration 


Then perform below command for above error which enable rewrite module of apache2:

$ sudo a2enmod rewrite && sudo service apache2 restart

That’s it. You are done :)

Comments