Increase the size limit for PHP uploads on Ubuntu

When working with PHP-based applications like WordPress on your Ubuntu server, you may encounter restrictions on the size of files you can upload. (upload_max_filesize). This limitation can be frustrating, especially if you need to download large files or media. Fortunately, it is possible to increase this limit. Here’s a step-by-step guide to increasing the size limit for PHP uploads on Ubuntu.

Step 1: Access the php.ini file

When you want to make changes to the PHP configuration on your Ubuntu server, the php.ini file is the central point where all these configurations reside. Here’s how you can access it and modify it to suit your needs:

On your Ubuntu server, launch Terminal to access the command line.

The exact path may vary depending on the version of PHP you’re using and how you’ve installed it.

If you use PHP with Apache, the path is usually :

/etc/php/8.1/apache2/

Here, I’m using php version 8.1.

Replace 8.1 with the exact version of PHP installed on your system.

To find out your PHP version, use the following command:

php -v

Use a text editor to open the php.ini file. In this example, we will use nano, a popular and easy-to-use command line editor:

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

Once again, be sure to replace 8.1 with your specific PHP version.

You should now have the php.ini file open in front of you in the nano editor.

Here you can browse and modify the various configuration parameters to suit your needs.

Step 2: Modify download settings

In the php.ini file, there are several parameters that determine download and upload limitations.

To increase the maximum size of files you can download or transfer, follow these steps.

In php.ini, find the line containing upload_max_filesize.

This parameter defines the maximum size of a file that can be uploaded.

See also: How do I install WordPress on Ubuntu?

Increase the size limit for PHP uploads on Ubuntu

By default, it can be set to values such as 2M or 8M, meaning 2 MB or 8 MB respectively.

Change the value of upload_max_filesize as required.

For example, to increase the limit to 70 MB :

upload_max_filesize = 70M

You will have some :

Increase the size limit for PHP uploads on Ubuntu

Adjust the maximum size of POST data: Look for the post_max_size parameter in php.ini.

This parameter controls the maximum size of data that can be sent by the POST method.

Make sure it’s equal to or slightly greater than upload_max_filesize.

For example:

post_max_size = 100M

You will have :

Increase the size limit for PHP uploads on Ubuntu

It is recommended to set this value slightly higher than upload_max_filesize to take into account other data that may be included in the POST request.

Change the execution time limit: If you’re downloading very large files, the process may take longer than initially configured in PHP.

To avoid this, adjust the max_execution_time parameter.

For example, to set it to 400 seconds :

max_execution_time = 400

You will have :

Increase the size limit for PHP uploads on Ubuntu

Save your changes: Once you’ve made the necessary changes, save the file and exit the editor.

If you’re using nano, press CTRL + X, then Y to confirm, and finally Enter.

Step 3: Restart the Apache server

After making changes to php.ini, it’s crucial to restart the Apache server for the changes to take effect. Here’s how to do it on your Ubuntu server.

To restart the Apache server and apply the changes, enter the following command:

sudo systemctl restart apache2

Check Apache status:

To ensure that the Apache server has restarted correctly without any errors, you can check its status using :

sudo systemctl status apache2

If everything is in order, you’ll see a status indicating that the service is “active (running)” or similar.

Now return to WordPress and refresh the page to see the changes.

Increase the size limit for PHP uploads on Ubuntu

Conclusion

Now you’ve increased the size limit for PHP downloads on your Ubuntu server. This should help you avoid any limitations when working with large files or media on your PHP-based applications. However, remember to always monitor server performance and adjust these settings according to your needs and server resources.

So you’ve found this article useful and would like to find out more or get professional assistance on other subjects? So don’t hesitate to hire me on Upwork. I’ll be happy to help you.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.