Altering php.ini doesn't seem to have effect - php

I am running a webserver with the following configuration:
Ubuntu 14.04
PHP 5.5.9
PHP-FPM
Nginx
When I upload a file in a Symfony application I am getting the error The file is too large. Allowed maximum size is 2 MiB.. I already altered the maxFileSize annotation in the entity but the problem seems to rely in the server configuration.
If I run phpinfo() it returns me the following path to my php.ini: /etc/php5/fpm/php.ini
In this php.ini I have changed the following settings:
upload_max_filesize = 8M
post_max_size = 8M
Then I restarted php-fpm (service php-fpm restart) but the changes don't appear on the phpinfo page because it still says: upload_max_filesize 2M.
Do I miss something?

Problem solved. It seems that stopping PHP-FPM is quite tricky. Looking further on Serverfault I found that some people had to kill all PHP-FPM processes manually:
sudo pkill php5-fpm
sudo service php5-fpm start
This worked for me.

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.

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

How to Increase max file upload in PHP?

I have a small problem with upload file.
I was set in php.ini:
upload_max_filesize = 64M
post_max_size = 64M
max_execution_time = 300
But when I re-check, it still have old value
upload_max_filesize 2M
value in phpinfo()
I used php7-fpm with nginx, and restarted after change php.ini.
Please help me, thanks.
Do Changes in you config file /etc/php/7.0/fpm/php.ini and save it.
Then run the following commands:
sudo service php7-fpm restart
sudo service nginx restart
Check phpinfo() it will work!
You are probably editing php.ini fole for PHP command-line.
This topic discuss php.ini location for nginx (also fpm is mentioned here):
php.ini: which one?

php 7 php.ini upload_max_filesize not working

I have read many solutions on internet , but still cannot change upload_max_filesize value (upload_max_filesize always = 2M )
here is my loaded php.ini in phpinfo() :
Configuration File (php.ini) Path /etc/php/7.0/apache2
Loaded Configuration File /etc/php/7.0/apache2/php.ini
Scan this dir for additional .ini files /etc/php/7.0/apache2/conf.d
upload_max_filesize 2M 2M
post_max_size 8M 8M
here is my edited php.ini in /etc/php/7.0/apache2/php.ini
; http://php.net/post-max-size
post_max_size = 86M
; http://php.net/upload-max-filesize
upload_max_filesize = 40M
im using ubuntu 14.04,apache2,php7.0
(I have reset apache2 many time after each change in php.ini )
I had a fix for PHP-FPM 7.1
Edit your php.ini in
/etc/php/7.1/fpm/php.ini
Make changes to whatever option you want like, post_max_size, upload_max_filesize, max_execution_time & so...
save & close file.
run
sudo service php7.1-fpm restart
It will work!
I had an other fix for it.
os: ubuntu 16.04
phpversion: 7.0
I created a phpinfo.php file containing:
<?php phpinfo() ?>
place the phpinfo.php file in the root of your website www.mywebsite.com/phpinfo.php
Navigating to it and lookup the line:
Loaded Configuration File : /etc/php/7.0/cgi/php.ini
Now you know what php.ini file is loaded.
ssh into the server and use your favorite editing tool (mine is nano) to adjust the php.ini
change the values to meet your preferences.
post_max_size = 128M
upload_max_filesize = 64M
Save and close the file.
Restart apache
sudo service apache2 restart
__
check the phpinfo.ini if the new values are as set.
and if they do you are set to go.
i fingured out !
in my loaded php.ini config , my error_reporting values is E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED-> this is wrong!, so i changed it to
error_reporting: E_ALL and then restart apache2 server,
now everything working fine !
so please note : if php.ini have any error , it will use default value (which means upload_max_filesize always 2M )
For php7.2-fpm
Ubuntu php-fpm located at /etc/php/7.2/fpm so
cd /etc/php/7.2/fpm
sudo nano php.ini
Search for post_max_size = 512M and add your fav size that you really needed
Search for upload_max_filesize = 512M and add your fav size that you really needed
Save File
And Last DO NOT FORGET TO RESTART PHP7.2-FPM to restart sudo service php7.2-fpm restart
Thats all!
I also found that restarting the httpd service didn't pick up changes in the loaded configuration file (/etc/php.ini on Fedora 29). It's worth listing all systemd units and doing a grep for the string "php":
# systemctl list-unit-files | grep php
php-fpm.service
Restarting php-fpm did the trick for me:
# systemctl restart php-fpm
I am using Nginx and my solution was to restart php-fpm.
Restarting Nginx didn't do anything.
sudo service php7.2-fpm restart
i also had this problem!
if you are using php-fpm service need to find php-fpm.conf and add line
php_admin_value[upload_max_filesize] = 100M
for changing other type of values
#just for example
php_flag[display_errors] = off
php_admin_value[error_log] = /var/log/fpm-php.www.log
php_admin_flag[log_errors] = on
After spending hours reading forum I've resolved this way:
cd /etc/php
find . -name "*.ini" | xargs grep -il upload_max_filesize
./7.1/apache2/php.ini
./7.1/mods-available/better.ini
./7.1/cgi/php.ini
./7.1/cli/php.ini
./7.1/phpdbg/php.ini
./7.1/fpm/conf.d/20-better.ini
./7.1/fpm/php.ini
./7.1/embed/php.ini
change upload_max_filesize in ./7.1/fpm/conf.d/20-better.ini then
/etc/init.d/php7.1-fpm restart
now phpinfo reports: upload_max_filesize 10G 10G
Hope this helps.
Most people are forgetting to restart their php via the terminal that's why it isn't working, if you think you've done everything correctly be sure to restart your php & the server.
Yeah, Actually I forgot to restart correctly.
sudo service apache2 restart is not enough
first add the configurations to /etc/php/7.1/fpm/php.ini and to /etc/php/7.1/cli/php.ini
#/php/ - then your php version here instead "7.1"
ACtually one of these configuration file is the active one (if you want to see what use <?php phpinfo() ?> command in indextest.php file and check it on browser)
Then change these parameters on each file with what you want:
post_max_size = 512M
upload_max_filesize = 512M
And then use following command to restart the php server:
sudo service php7.0-fpm restart #php<then your php version here> instead "7.0"
or
sudo /etc/init.d/php7.1-fpm restart #php<then your php version here> instead "7.1"
Now you should be able to see the changes of upload size. Cheers !
as shown in here you can get to know more about the php server controlls :
$ sudo service php7.0-fpmstart # <- restart it
$ sudo service php7.0-fpm stop # <- restart it
$ sudo service php7.0-fpm restart # <- restart it
$ sudo service php7.0-fpm reload # <- reload it
create two different files in the root of your project(if you are a Wordpress user,it is the root public_html folder).one is php.ini & the second one is .user.ini
and then simply add these two lines of codes in both files.
upload_max_filesize = 20M
post_max_size = 20M
don't forget to restart the server.
and also make sure the user.ini file must be starting with a dot (.)
systemctl restart apache2
In my case I was editing the wrong one. It turns out I should mondify this /etc/php/7.2/apache2/php.ini
After doing so, it worked!
For those who have all the obvious settings mentioned in other answers and PHP file uploads are stil not working.
Check php.ini for open_basedir value. If a value is set (which it should be for security reasons), make sure that /tmp is included there. Or choose a custom value in upload_tmp_dir and set open_basedir accordingly.
Then reload the FPM service.
I installed multiple versions of PHP on MacOS Big Sur following the steps here
I used command:
sudo /usr/local/bin/httpd -k restart
to load changes made to the php.ini file.
open your putty or bitvise ssh client login your server
sudo apt update
After that
cd /etc/php/7.4/apache2/
see the list to hit command below
ls -ltr
output
total 76
drwxr-xr-x 2 root root 4096 Sep 4 14:31 conf.d
-rw-r--r-- 1 root root 72540 Sep 7 09:28 php.ini
to open php.ini enter the below command
sudo nano php.ini
Move down Arow till not find the Below code
upload_max_filesize = 20M
change 20MB to your desired upload size Press ctrl+s to save php.ini and exit to the editor to command prompt hot ctrl+x after that to reload apache2 hit the below command
sudo systemctl reload apache2
Happy coding

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

Categories