开发者

.htaccess produces 500 Internal Server Error

The content of .htaccess is:

php_value upload_max_filesize 64M

Works on localhost, sc开发者_运维问答rews 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?


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.


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>


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


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


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


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.


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜