Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.htaccess produces 500 Internal Server Error

Tags:

apache

The content of .htaccess is:

php_value upload_max_filesize 64M

Works on localhost, screws up every hosting server I upload it to. The error.log says: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration

Is there another way to change the upload_max_filesize?

like image 709
A-OK Avatar asked Apr 02 '11 12:04

A-OK


People also ask

How do I fix a 500 Internal server error?

Clear your browser cache and cookies Check these articles on deleting the cache on an Android phone or iPhone, if you use a mobile device. Alternatively, you can test opening the page from another browser. For instance, if you use Chrome, try Firefox or vice versa.

What causes 500 errors PHP?

PHP Coding Timing Out If your PHP script makes external network connections, the connections may time out. If too many connections are attempted and time out, this will cause a "500 Internal Server Error." To prevent these time outs and errors, you'll want to make sure that PHP scripts be coded with some timeout rules.

What is .htaccess file in PHP?

htaccess is a configuration file for use on web servers running on the web apache server software. when a . htaccess file is placed in a directory which in turn loaded via the Apache web server, then the . htaccess file detected and executed by the Apache server software.


3 Answers

If php_value is not recognized as a valid command, it may be because PHP is not installed as an Apache module. Create a php file with the following contents:

<?php phpinfo();

Run the file to show your PHP configuration. Search the page (Ctr+F) for "mod_php". If you don't find it anywhere, this explains your problem.

If you have access to php.ini, you may be able to fix your problem by editing that file instead. At the phpinfo page, look at the value under Loaded Configuration File for the location of the file to edit. On Linux, it will be something such as /usr/local/lib/php.ini

Open the ini file (it's just a text file) and look for the setting you want to change. If it's not present, just add a line and set it as desired: upload_max_filesize=64M

Save the file and restart the Apache server.

like image 154
BeetleJuice Avatar answered Sep 23 '22 16:09

BeetleJuice


If you don't want to remove the php_flag command in .htaccess but want to avoid the error, wrap the command as follows:

<IfModule mod_php5.c>
    php_flag display_errors 0
    php_flag display_startup_errors 0
</IfModule>

If you're using PHP7, use <IfModule mod_php7.c>

like image 30
bart Avatar answered Sep 20 '22 16:09

bart


For other readers with the same problem and access to the server, this could also be caused by a misconfiguration of PHP as a module of apache. You can fix it reinstalling the module (or configuring the route to libphp.so by yourself in php.ini).

Have in mind that purge will remove the configuration of the packages which usually is nothing to worry, but you are warned just in case.

sudo apt-get purge libapache2-mod-php libapache2-mod-php7.2
sudo apt-get install libapache2-mod-php
like image 37
PhoneixS Avatar answered Sep 22 '22 16:09

PhoneixS