I want to increase the limit of upload size max, but because I using shared hosting, I cannot edit php.ini. Then I try to edit my .htaccess file. I added these lines:

php_value upload_max_filesize 700M
php_value post_max_size 700M
php_value max_execution_time 600
php_value max_input_time 600

When I test it in localhost, it running succedded. But, when I upload this .htaccess file to my shared hosting, it produce 500 Internal Server Error. I also try to put that similar code in my .php files, but not affected. Any idea how to solve this problem? Thanks a lot.

Dani AI

Generated

Nice troubleshooting by — wrapping the PHP settings in an IfModule stopped the 500, which fits the usual cause: php_value/php_flag in .htaccess only work when PHP is loaded as Apache’s module (mod_php). On many shared hosts PHP runs as CGI/FastCGI (PHP‑FPM) or under suEXEC, and Apache will reject those directives (you’ll see “Invalid command 'php_value'” in the error log). (support.cpanel.net)

Quick check you can run: create a small file (for example info.php) containing this and open it in your browser:

<?php phpinfo(); ?>

Look for the “Server API” / “Server” or “Server API” line — it tells you whether PHP is “Apache 2.0 Handler” (mod_php) or “FPM/FastCGI” / “CGI”. That determines which method to use. (php.net)

If the Server API is FPM/FastCGI, use a per-directory INI instead of php_value in .htaccess — most hosts support a .user.ini (scanned by CGI/FastCGI) or provide a MultiPHP INI editor in the control panel; some hosts using suPHP accept a local php.ini. .user.ini changes may take a few minutes to propagate (user_ini.cache_ttl). ’s suggestion to check the hosting panel is worth doing first. (php.net)

Two final notes: the upload settings you tried (upload/post sizes) are changeable at the per-directory level (PHP_INI_PERDIR), so they must be set in php.ini/.user.ini/.htaccess as appropriate — they cannot reliably be changed at runtime with ini_set(); also keep memory_limit larger than post_max_size, and use set_time_limit() or adjust max_execution_time where allowed to avoid timeouts during big uploads. (php.net)

Recommended Answers

All 2 Replies

Member Avatar for Member #120589

Are you sure you don't have access to a php.ini file through a panel? Who's your host?

Surely. When I using shared hosting, I cannot see Apache, PHP and MySQL Folder. There's a PHP section which I can edit. But, when I saved it, close it then re-opened again, it back to default setting. So, I thing I cannot edit setting of php.ini file.

Update: My problem solved! I just have to put these codes:

    php_value upload_max_filesize 700M
    php_value post_max_size 700M
    php_value max_execution_time 600
    php_value max_input_time 600

between :
<IfModule mod_php5.c>

Thanks ! :D

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.