php - increasing the max upload filesize

Submitted by admindm on Mon, 11/04/2013 - 20:45

Upping the limit on php max filesize

At some point you are likely to run into the issue that by default you can only upload a 2MB file. If you try to upload anything larger it will get refused by the server. This is a security measue and in most cases its a good idea to leave this as it is and just use ftp to transfer larger files. Drupal can limit the file size so you can make the server limit larger and then limit it in Drupal, you can even set different limits for different file types within Drupal.

For my own server I decidede to increase the limit. I'm going to show you how to increase the server limit to 16MB but consider your usage and set it as small as would be practical. You can always change this later.

Connect to your server and open php.ini in a text editor.

sudo nano /etc/php5/apache2/php.ini

Now look for "upload_max_filesize". If your using nano like I am you can press Ctrl-W to search. Change the "2M" to "16M" and then save and close the file.

php upload filesize limit

Once you have saved it you will need to restart Apache for the changes to take effect.

sudo service apache2 restart

Checking the php max upload limit

Its a good idea to check this has taken effect. You can do this by creating an info.php file to give you some details about php. The file needs to be in your websites root directory. If you have left the drupal default site enabled this it will go here /var/www/info.php. If you have disabled Apaches default then it needs to go in your websites root directory. In my case I've been using /var/www/username/domainname. So first we crated the file

sudo nano /var/www/info.php

or

sudo nano /var/www/username/domainname/info.php

Now in the file we need to place the following.

<?php
// Show all information, defaults to INFO_ALL
phpinfo();
?>

Save the file and then open "serverip/info.php" or "domainname/info.php" in your web browser.  Now use your browsers search funtion, usually Ctrl-F to search for "upload_max_filesize". It should say 16M.

Its considered bad practice to allow access to your php setup info so as a last step we are going to make is so that the file isnt readable. Run this command

sudo chmod 600 /var/www/info.php

This gives you read/write but makes it inaccessible to anyone else. You wont be able to access it through a browser either, if you ever want to access it in the future run this, not forgetting to change it back afterwards.

sudo chmod 644 /var/www/info.php

That gives everyone read permissions so it can be read through a browser.