I’ve had a problem for a while now where I can’t upload anything larger than 8 megabytes. I’ve narrowed it down that it’s the actual php.ini file, which is not updating.
So far I’ve found 3 different php.ini files, all which I’ve changed the post_max_size
to more than the default 8 megabytes. I’ve tried changing other values too, nothing updates. It’s just stuck at 8M
The three different files are located
/etc/php/7.4/apache2/php.ini
/etc/php/7.4/cli/php.ini
/etc/php/7.4/fpm/php.ini
When I add a test.php
to my website and do phpinfo()
. It tells me that the loaded php.ini
file is located in the apache2 folder.
However when I do php --ini
in my EC2 instance, it shows that the loaded php file is in the cli folder. Like I said I’ve edited all of them and double checked, all 3 php.ini
HAVE changes to them.
Checking the actual php.ini through the command line with php -info
I found that it actually had accepted the changes. And I guess this is the CLI php.ini, so that one has updated. But not the apache2 or fpm one.
I’ve tried restarting apache2 service. And restarting fpm service according to: changing php.ini has no effect on my EC2 instance's PHP config
However in my system it’s called php7.4-fpm
instead of php-fpm
.
So for me: sudo systemctl restart php7.4-fpm.service
Nothing works.
I can confirm that the services I am restarting ARE the actual services (Or at least the apache2) I’m viewing live on my website. If I close the apache2 service down, my website will stop working. So I’m confident in that at least. I’ve tried viewing the files I’ve edited through just editing them via the command line and downloading through ftp. My changes are apparent all the time, but they are just not apparent in practice.
The EC2 instance I’m running is a t2.xlarge
, running: Ubuntu 20.04 LTS (Focal Fossa) LAMP Stack – Linux Apache MySQL/MariaDB PHP
2
Answers
I found a solution for the problem. However a little unconventional, after reading A LOT on the internet finding various solutions and fixes like above mentioned. I finally found something from 7 years ago that still works today!
https://serverfault.com/questions/683026/post-max-size-will-not-change-stuck-at-128m-other-settings-work
Here the OP fixed the problem by editing the virtual host config. I did the same and it turns out doing this actually does changes to the php.ini shown with
phpinfo()
on the website. Why this is the case, I have no clue, but it's the ONLY way to change specific variables like:post_max_size
upload_max_filesize
memory_limit
So like the OP of the link you would find the
sites-available/000-default.conf
wherever it's located in your apache folder usuallyetc/apache2/sites-available/000-default.conf
Add this before the closing tag
</VirtualHost>
:Then restart
php-fpm
(in my case it's called php7.4-fpm) andapache2
services in the command line (I'm using the EC2 instance connect)And now you'll see in the
phpinfo()
that it actually changed the local value of the variables we changed in the apache config.The master value is still the default, but the site accepts the new local value as the relevant one.
Use the exact path of apache2 in your Instance. It will work.
Check this for complete guide for php.ini update in AWS ec2