H ow do I increase upload file limit from 2MB to 10MB under Apache 2 UNIX / Linux web server? Ĥ我的OW增加限制由2MB的文件上传到10MB下的Apache 2的UNIX / Linux的Web服务器?
Your php installation putting limits on upload file size.把你的PHP安装限制上传文件大小。 The default will restrict you to a max 2 MB upload file size.默认会限制你到最大2 MB的上传文件大小。 You need to set the following two configuration options:您需要设置以下两个配置选项:
upload_max_filesize - The maximum size of an uploaded file. 中upload_max_filesize -上传的文件的最大规模的一个。
memory_limit - This sets the maximum amount of memory in bytes that a script is allowed to allocate. memory_limit的 -这在字节设置的最大内存量,一个脚本所能够申请到。 This helps prevent poorly written scripts for eating up all available memory on a server.这有助于防止写得不好的吃了服务器上所有可用内存的脚本。 Note that to have no memory limit, set this directive to -1.请注意,有没有内存限制,设置这个指令为-1。
post_max_size - Sets max size of post data allowed. post_max_size要 -设置后的数据允许的最大大小。 This setting also affects file upload.此设定也会影响文件上传。 To upload large files, this value must be larger than upload_max_filesize.要上传大文件,该值必须大于upload_max_filesize。 If memory limit is enabled by your configure script, memory_limit also affects file uploading.如果你的内存限制是由配置脚本启用,memory_limit也会影响文件上传。 Generally speaking, memory_limit should be larger than post_max_size.通常说,memory_limit应该比post_max_size要大。
There are two methods two fix this problem.有两种方法2解决此问题。
Method # 1: Edit php.ini方法#1:编辑的php.ini
Edit your php.ini file (usually stored in /etc/php.ini or /etc/php.d/cgi/php.ini or /usr/local/etc/php.ini):编辑你的php.ini文件(通常在/ etc / php.ini文件或/ etc / php.d /的cgi / php.ini文件或/ usr /本地/ etc / php.ini文件中):
# vi /etc/php.ini
Sample outputs:示例输出:
memory_limit = 32M 记录memory_limit = 32M的
upload_max_filesize = 10M 中upload_max_filesize = 10M的
post_max_size = 20M post_max_size的值 = 20米
Save and close the file.保存并关闭该文件。 Restart apache or lighttpd web server:重新启动Apache或lighttpd Web服务器:
# service httpd restart
OR或
# service lighttpd restart
Method #2: Edit .htaccess方法2:编辑。htaccess的
Edit .htaccess file in your root directory.编辑。htaccess的文件在您的根目录。 This is useful when you do not have access to php.ini file.这是非常有用当你无法访问的php.ini文件。 In this example, /home/httpd/html is considered as root directory (you can also create .htaccess file locally and than upload it using ftp / sftp / scp client):在这个例子中,/家/的httpd / html是作为根目录(也可以考虑创建的。htaccess文件上传它比在本地使用FTP / SFTP发布/ SCP的客户端):
# vi /home/httpd/html/.htaccess
Append / modify setting as follows:添加/修改设置如下:
php_value upload_max_filesize 10M php_value中upload_max_filesize 10M的
php_value post_max_size 20M php_value post_max_size要20米
php_value memory_limit 32M php_value memory_limit的32M的
Save and close the file.保存并关闭该文件。
A Note About Suhosin (Optional)关于Suhosin的说明(可选)
This is not installed by default on many servers (latest version of Debian, Ubuntu, and FreeBSD does install Suhosin by default).这不是安装在多台服务器(最新的Debian,Ubuntu的版本默认情况下,和FreeBSD默认没有安装Suhosin的)。 Use phpinfo() to find out if suhosin enabled or not (create test.php):使用phpinfo()函数,看看Suhosin的启用与否(创建test.php):
<?php <?PHP的
phpinfo ( ) ; 的phpinfo ();
?> ?>
If you are using Suhosin which was designed to protect your servers against a number of well known problems in PHP applications and on the other hand against potential unknown vulnerabilities within these applications or the PHP core itself.如果您使用Suhosin的,目的就是要防止潜在的未知漏洞对您的服务器的一个众所周知的问题,PHP应用程序和数量,另一方面在这些应用程序或PHP的核心本身。 You need to edit /etc/php.d/suhosin.ini to set correct memory and upload limit.您需要编辑的/ etc / php.d / suhosin.ini设置正确的内存和上传限制。 As long scripts are not running within safe_mode they are free to change the memory_limit to whatever value they want.只要不属于safe_mode设置脚本运行,他们可以自由地改变memory_limit的任何值,以他们想要的。