PHP Upload Issues

Muaz Khan edited this page Jul 15, 2018 · 4 revisions

This wiki page explains how to modify php.ini file or .htaccess file to support large-size uploads in PHP applications. Such issues usually happens when you try to record 2-3 minutes of audio/video streams and resulting Blobs size gets bigger/larger than 10MB.

References:

  1. https://github.com/muaz-khan/WebRTC-Experiment/issues/224#issuecomment-46087136
  2. https://github.com/muaz-khan/WebRTC-Experiment/issues/281

.htaccess solution

It is a common case among all PHP default installations. You should define following values in .htaccess file if you've root-level privileges.

<IfModule mod_php4.c>
php_value session.gc_maxlifetime 10800
php_value max_input_time 10800
php_value max_execution_time 10800
php_value upload_max_filesize 500M
php_value post_max_size 500M
</IfModule>

php.ini solution

Above technique rarely works on Amazon EC2. You need to login as root-user to the terminal; then search for all php.ini files:

find /etc/ -name "php.ini"

There should be php.ini file located in your appache installation directory. Its location varies for each installation that's why you should check all php.ini files.

vim php.ini

// or otherwise you can use "vi"
vi php.ini

Above command will open editing mode; then you should search and edit following values:

/session.gc_maxlifetime
/max_input_time
/max_execution_time
/upload_max_filesize
/post_max_size

Each line is searching a specific string. Note: Above command may work in replace mode instead of insert mode.

You should change default values to:

session.gc_maxlifetime=10800
max_input_time=10800
max_execution_time=10800
upload_max_filesize=500M
post_max_size=500M

Remember, NEVER forget "max_execution_time" because usually ffmpeg execution process takes time to transcode and merge webm.

:wq command can be used to save changes and close editing mode. You need to type this command in "replace" mode.

Note: You can navigate between insert and replace modes by simply pressing insert key.

After modifying php.ini

You MUST restart/reboot appache server to make sure new changes are applied.

Then

Please don't forget to set a temporary PHP page where you can check PHP-info:

<?php

// Show all information, defaults to INFO_ALL
phpinfo();

?>

Now, open that PHP page and search for all above values e.g. post_max_size etc.

File Permissions

[sudo] chmod 755 ./uploads
[sudo] chown -R www-data:www-data ./uploads
[sudo] chown -R apache:apache ./uploads

P.S. Sometimes you need to manually set read/write access for directories like "uploads" however your demo has privileges to read/write WAV/WebM files in uploads directory.

You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.
Press h to open a hovercard with more details.