Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Modifying max upload file size for Wordpress

Good day to you,

  I am trying to upload larger files than 2M in my wordpress.
It's created from the one click deployment solution in Compute Engine.

In order to achieve it, I mostly tried to different things.

First, I wasn't really fan, updating the file /var/www/html/wp-config.php and adding these lines :

 

 

@ini_set( 'upload_max_filesize' , '128M' );
@ini_set( 'post_max_size', '128M');
@ini_set( 'memory_limit', '256M' );
@ini_set( 'max_execution_time', '300' );
@ini_set( 'max_input_time', '300' );

 

 

 It didn't worked.
On a local version (on premise) of this wordpress, I did it modifying php.ini and it worked.

On GCP, I tried this :

 

 

$ sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 100M/' /etc/php/8.1/apache2/php.ini
$ sudo sed -i 's/post_max_size = 8M/post_max_size = 100M/' /etc/php/8.1/apache2/php.ini
$ grep -n "upload_max_filesize\|post_max_size" /etc/php/8.1/apache2/php.ini
703:post_max_size = 100M
855:upload_max_filesize = 100M

$ sudo service apache2 status
● apache2.service - The Apache HTTP Server
     Loaded: loaded (/lib/systemd/system/apache2.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2023-10-11 09:00:38 UTC; 7min ago
       Docs: https://httpd.apache.org/docs/2.4/
    Process: 385 ExecStart=/usr/sbin/apachectl start (code=exited, status=0/SUCCESS)
   Main PID: 559 (apache2)
      Tasks: 10 (limit: 2353)
     Memory: 32.2M
        CPU: 242ms
     CGroup: /system.slice/apache2.service
             ├─559 /usr/sbin/apache2 -k start
             ├─587 /usr/sbin/apache2 -k start
             ├─588 /usr/sbin/apache2 -k start
             ├─589 /usr/sbin/apache2 -k start
             ├─590 /usr/sbin/apache2 -k start
             ├─591 /usr/sbin/apache2 -k start
             ├─691 /usr/sbin/apache2 -k start
             ├─699 /usr/sbin/apache2 -k start
             ├─704 /usr/sbin/apache2 -k start
             └─705 /usr/sbin/apache2 -k start

Oct 11 09:00:30 foxy-pleasure-review-vm systemd[1]: Starting The Apache HTTP Server...
Oct 11 09:00:38 foxy-pleasure-review-vm systemd[1]: Started The Apache HTTP Server.

$ sudo service apache2 stop
$ sudo service apache2 start

 

 

After that, I even tried to restart the VM, I still have in the http://mydns//wp-admin/media-new.php the "Maximum upload file size: 2 MB." message.
I can't upload more.

What am I missing ?

Thanks for your help 🙏

Solved Solved
1 6 4,268
1 ACCEPTED SOLUTION

So in short :

$ sudo sed -i 's/upload_max_filesize = 2M/upload_max_filesize = 100M/' /etc/php/8.1/fpm/php.ini && sudo sed -i 's/post_max_size = 8M/post_max_size = 100M/' /etc/php/8.1/fpm/php.ini
$ sudo service php8.1-fpm restart && sudo service apache2 restart

View solution in original post