PHP / Apache: Set Max File Upload and Post Size

Last updated on

The default PHP max file upload and post value is actually quite small (around 2 MB) for security reasons. In this guide we will increase the max value using php.ini.

1. Locate php.ini

Firstly, you need to locate your php.ini file. In this example, our php.ini is located in /etc/php/7.2/apache2/php.ini, however, this may be different for you depending on your PHP version. If you are unsure, please read:

2. Edit php.ini

Open your php.ini file with nano.

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

upload_max_filesize

In nano, press CTRL + W and search for upload_max_filesize and change the value to 64M (for 64 megabytes) or whatever value you require.

/etc/php/7.2/apache2/php.ini
...
upload_max_filesize = 64M
...

post_max_size

Press CTRL + W again and search for post_max_size and change the value to 64M (for 64 megabytes) or whatever value you require.

/etc/php/7.2/apache2/php.ini
...
post_max_size = 64M
...

Save file and exit. (Press CTRL + X, press Y and then press ENTER).

3. Restart Apache/PHP

Restart Apache to apply changes.

sudo systemctl restart apache2

If you are using PHP-FPM, you may need to restart PHP-FPM service separately.

Let me know in the comments if this helped. Follow me on Twitter, Facebook and YouTube.

p.s. I increased my AdSense revenue by 68% using AI 🤖. Read my Ezoic review to find out how.

1 Star2 Stars3 Stars4 Stars5 Stars 5.00 (5 votes)

Leave a Reply

Your email address will not be published. Required fields are marked *

We use Markdown to style comments, like on Github and Reddit.
To do a line break, type two spaces after the sentence.
You can add inline code by wrapping it in backticks: `code here`

    To do an entire block of code  
    type four spaces before the line
    and it will appear in a block like this.
    <-- four empty spaces

1 reply