php.ini not updating after changes - php

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.

Related

PHP.ini not updating when changing values on AWS EC2

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.

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

Loading Newly Installed PHP Module Into Apache

I am working to build a small email client inside a web application. After doing some research I attempted to use the imap function. I got an error saying I was calling an undefined function, so again I researched and uncommented extension=php_imap.dll.
I then found I had to update php with the imap function and I did so. Now, the imap functions works in php interactive inside Terminal, but I can't get it to work in the browser. I'm assuming I have to somehow load it in the Apache Config files but I can't seem to find how to do so.
Any Ideas?
You'll need to restart Apache to reload the PHP module with the new configuration. The command line PHP starts a new PHP instance each time with the latest configuration, whereas the PHP extension running in Apache is separate, and only loads new configuration setting when Apache itself is restarted.
Assuming you're running on Windows based on the .dll extension, so apachectl restart or apache2ctl restart may work, or the installer you used may have a tray app or other GUI tool that can do it for you.
If running on Linux sudo service apache2 restart or sudo service httpd restart depending on distribution.

changing php.ini has no effect on my EC2 instance's PHP config

I'm running an Apache server in a micro instance from Amazon AWS, and I need to change the session duration and the max upload limit.
When I edit php.ini and restart Apache, changes don't show in Apache.
I wasn't able to find any info on this.
What can I do? is there any file overriding php.ini that you know of?
Since PHP on Amazon Linux ran with FPM/FastCGI I had to do:
sudo systemctl restart php-fpm.service
before restarting apache, i.e
sudo systemctl restart httpd.service
Which config file are you editing? When you do a phpinfo() what is the path shown under Loaded Configuration File? Edit the php.ini that it says it is loading & your changes should be reflected.
If you don’t know how phpinfo() works, just create a file on your server called something like:
phpinfo_test.php
In that file place this code:
<?php
phpinfo();
?>
Now load phpinfo_test.php from that web server.
This is very late, but for those of you who don't know how to handle this problem, you want to restart apache for it to reflect the changes:
sudo service httpd restart
I want to leave the method that worked for me here for others that run into my same problem in language I would appreciate at my level of expertise. I found the location of the php.ini file with the following command in the terminal connected to the server:
$ php --ini
You will get the following output:
Change directories to the one specified as "Loaded Configuration File." In the example it is /etc/
Type cd /etc into the command line and hit enter.
To override readonly add sudo before vi php.ini or copy and paste
sudo vi php.ini
into the command line and hit enter.
Find the place where you would like to make changes and arrow the cursor over it. Press the i key to make changes to the document and when you are done hit the ESC key.
To save the changes and exit vi, enter
:x
I hope that helps. Links to some of the resources that helped me cobble together my solution are below:
https://forums.aws.amazon.com/message.jspa?messageID=391689
http://www.geekyboy.com/archives/629
http://www.lagmonster.org/docs/vi.html
https://unix.stackexchange.com/questions/3334/how-do-i-quit-from-vi
I just spent some time and discovered, that there were repeat php.ini settings in the end of php.ini file in section AWS Settings. Including upload size and session duration.
Just scroll to the end of php.ini file. Hope this helps someone :)
I found out that I need to edit my php files through terminal accessing the remote file through ssh client which I was editing below through user-detail.
Then the only file I have in my web server is phpinfo.php since i make use of lampp. To add extra file or directory it has to be through You can best edit web server through accessing the file through terminal. This video assist me greatly https://www.youtube.com/watch?v=h04jIAIcBhg

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