PHP.ini not updating when changing values on AWS EC2 - php

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

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 usually etc/apache2/sites-available/000-default.conf
Add this before the closing tag </VirtualHost>:
php_value post_max_size 16384M
php_value upload_max_filesize 16384M
Then restart php-fpm (in my case it's called php7.4-fpm) and apache2 services in the command line (I'm using the EC2 instance connect)
sudo systemctl restart php7.4-fpm
sudo systemctl restart apache2
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.

Related

php.ini not updating after changes

Followed a few tutorials but it just doesn't update.
I restarted the server many times with sudo service apache2 restart and sudo apachectl restart
I ran php --ini to check all the files being loaded
I checked each file to see if it is being overwritten
I made another override and checked if its being loaded
Used the phpinfo() function to check if its being updated
I'm using PHP Version 5.5.9-1ubuntu4.21
Its a virtual machine in virtualbox
the change that I'm trying to make is for php to allow more inputs in a post.
I don't know if I should post here or in Super User
Chances are you are modifying the php.ini of the CLI instead of the one for apache. It should be under:
/etc/php/$VERSION/apache2/php.ini
Then restart apache.

Lightsail Wordpress Instance Restart Apache

I am trying to import a sql file that exceeds the default file size in the phpmyadmin tool. So after some research, I discovered I needed to change some of the variables in the php.ini. Specifically the : upload_max_filesize, memory_limit and post_max_size in the php.ini. Easy enough, then I assumed I needed to restart the apache2 server and I did just that:
sudo /opt/bitnami/ctlscript.sh restart apache
Unmonitored apache
Syntax OK
/opt/bitnami/apache2/scripts/ctl.sh : httpd stopped
Syntax OK
/opt/bitnami/apache2/scripts/ctl.sh : httpd started at port 80
Monitored apache`
However, the limit size did not change in the phpmyadmin tool. I also printed out the phpinfo() command to see if there are multiple versions of the php.ini file which there isn't. So now I am really stuck. Any ideas?
The main php.ini file path :- /opt/bitnami/php/etc/php.ini

I have changed every last PHP.ini, *.ini related or unrelated on my server for setting post_max_size to 8000M but its not working

I have changed every last PHP.ini, *.ini related or unrelated on my server for setting post_max_size to 8000M but its not working.But atleast 50M will do my work.I am stuck here.
restarted server after changing every php.ini
httpd - k restart
even stopped server and start again.
but i cant see a small change in PHP.info
tried various tricks like
1) php_ini
2) .htaccess
3) .user.ini
but not getting desired result .Please help
I have dedicated server.With WHM and root access but still nothing working
CentOS release 6.8 (Final)
All the suggested answers make change in HTACESS or php.ini while i already changed on it. more than any time.
First create a phpinfo.php file within your web directory (ideally in the same folder where the scripts you are testing are saved) containing:
<?php
phpinfo();
Then access this file using a browser.
Right close to the top there is a line saying:
Loaded Configuration File /etc/php/some/path/php.ini
Edit the loaded php.ini file as follows:
; Maximum allowed size for uploaded files.
upload_max_filesize = 50M
; Must be greater than or equal to upload_max_filesize
post_max_size = 50M
Your question mentions only post_max_size, but if your form accepts files you need to change upload_max_filesize too.
After that you need to restart the web sever (apache?). If you are using php-fpm then you need to restart that process. I don't know about centOS, but for ubuntu commands can be:
sudo service apache2 restart
sudo service php-fpm restart
Reload the phpinfo file in your browser and check if both values have been updated.

Changes to php.ini not reflected in PHP's phpinfo()

I just can't get php_info() values to change on my localhost setup, or the related phpMyAdmin maximum file size.
So I have located the PHP file that phpinfo states is being loaded. I have changed the three parameters:
upload_max_filesize
post_max_size
memory_limit
Saved the file, restarted Apache and MySQL, reloaded the phpinfo() page... no changes.
I've also tried putting a .htaccess file in the web root folder with changes to these parameters. This is reflected in phpinfo in the local value (the master value still says 2M for maximum upload size), and then when I go to phpMyAdmin the maximum upload size is still 2M...
I've looked for a php.ini file in C://windows as this is where phpinfo() states the master value is derived from. But there isn't any php.ini file there. So I created one with the values I wanted... no success!
How can I fix this?
I came across the same issue.
Check if php-fpm is running by this command:
ps aux | grep php-fpm
php-fpm stands for "FastCGI Process Manager" for PHP and it was probably built in your system.
If so, you have to restart it. Assuming you are on a Linux system type:
For Red Hat Linux, CentOS, Fedora, etc.
sudo systemctl restart php-fpm.service
For Debian-based systems (like Ubuntu)
sudo service php-fpm restart
or
sudo service php7.0-fpm restart
Don't do what I did... I changed max_input_vars from 1000 to 10000 but never noticed that the line was commented out by default.
; max_input_vars = 10000
I couldn't figure out why the value displayed in phpinfo() wouldn't change.
Doh!
Have you attempted to look for php.ini-development / php.ini-production? If you update php.ini-development and then remove the -development then you should be good to go I believe.
Don't do what I did though and update the php.ini-development file and forget to remove the -development... I spent far too long wondering why the settings weren't updating!
That happen for me, php.ini changes do not affect in phpinfo()
The reason is, that several php-fpm installed into the system and command was not reload config
service php-fpm restart
Proper command to reload service php74-php-fpm restart in my case:
service php74-php-fpm restart

Trouble changing `upload_max_filesize` on nginx

I've see a few other similar questions on here, but most of the answers are Apache specific (dealing with their .htaccess file) and I'm using nginx.
I'm having trouble making my change to the upload_max_filesize in php.ini stick. I'm using nginx, php5 and wordpress on Debian.
When I run phpinfo() I see the following output:
Loaded Configuration File /etc/php5/cgi/php.ini
I then go to the relevant .ini file, change a few values, and then restart nginx. When I fire up a phpinfo() plugin I got for wordpress, it reports the values as unchanged.
I'm at a loss because phpinfo() reports that it is loading config values from the file that I've changed, but it doesn't report the changes.
You might be using FAST CGI:
[webserver] <----> [fcgi daemon]
`- [php]
If you restart the webserver, PHP is not restarted, so still has the old ini values because it didn't reload the ini file.
Restarting the fcgi daemon solves that issue, PHP will be restarted, re-reading the ini.
Some fcgi daemons have a command that reloads the child processes more gracefully. Depends on what you use.
For me the problem was a syntax error in the custom php.ini file, which I found after checking the error logs.
This might help the ones that are using php -i from the terminal to check php.ini settings.
In my case, I increased the upload_max_filesize from 2M to 20 MB by editing /etc/php/7.3/apache2/php.ini and restarted the apache by apachectl restart command.
I used php -i command from the Debian terminal to see the changes are in effect but upload_max_filesize was still 2M.
Then I realized settings readings came from /etc/php/7.3/cli/php.ini because I was using php -i from the terminal instead of phpinfo() function in a web page.
$ sudo service php7.4-fpm restart
Resolved my problem. change the php version to the one you using.

Categories