A-OK
A-OK

Reputation: 3254

.htaccess produces 500 Internal Server Error

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?

Upvotes: 21

Views: 61864

Answers (7)

Jhonny Ramirez Zeballos
Jhonny Ramirez Zeballos

Reputation: 3186

  1. Create .user.ini file
  2. Add the line upload_max_filesize="5M"

Upvotes: 0

Kisha Kindle
Kisha Kindle

Reputation: 19

I too was receiving a 500 internal server error. My error log showed: Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration

I tried updating upload_max_filesize as suggested but it didn't work for me. The last line of my .htaccess file had:

php_value max_execution_time 120

I removed that line and the site resolved perfectly.

Upvotes: 1

rubo77
rubo77

Reputation: 20875

It seems like the php module is not loaded. Make sure, it is installed with

sudo apt-get install libapache2-mod-php

and check if it is enabled in apache with

ll /etc/apache2/mods-enabled/*php*

if it is installed but not enabled, enable it (depending on your php-version) e.g. for PHP 8.0 with

sudo a2enmod php8.0.load

and restart apache

sudo apache2ctl graceful

Upvotes: 4

PhoneixS
PhoneixS

Reputation: 11036

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

Upvotes: 9

bart
bart

Reputation: 15298

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>

Upvotes: 11

BeetleJuice
BeetleJuice

Reputation: 40936

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.

Upvotes: 16

A-OK
A-OK

Reputation: 3254

The problem was the hosting provider, they only allow changing this via php.ini

Upvotes: 4

Related Questions