15
votes

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?

5
You should read the error logs for more information. - vbence
Yeah, thanks, forgot about that. The error.log says Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration - A-OK
@A-OK: Assuming PHP is running, create a phpinfo() file, and check the server method. php_value will only work if mod_php is being used, ie. PHP is an Apache Module, if it's FCGI, it will not work. - Orbling
Do you use PHP as a module? No for example with FastCGI? - vbence
It's CGI, not even FastCGI :) - A-OK

5 Answers

11
votes

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.

8
votes

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>

7
votes

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
3
votes

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

0
votes

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