multiphp php.ini no effect - php

I'm running multiple php versions 5.6, 7.1 (default), 7.2.
To change php values in 7.1 or 7.2, i go to
/etc/php/7.x/apache2/php.ini
.
The problem comes with php5.6. There no apache2 folder inside
/etc/php/5.6
.
When I run $ php5.6 -i "phpinfo()" | grep "php.ini"
I get
Configuration File (php.ini) Path => /etc/php/5.6/cli
Loaded Configuration File => /etc/php/5.6/cli/php.ini
I've tried changing upload_max_filesize and post_max_size inside /etc/php/5.6/cli/php.ini but it has no effect in phpinfo. Also tried set in htaccess:
php_value upload_max_filesize 24M
php_value post_max_size 32M
but is doesn't work either.
Keeps showing default value when installed:
post_max_size 8M
upload_max_filesize 2M
I always restart server service apache2 restart.
I'm setting php version for domains that use another version beside default 7.1 via vhost.
php5.6 Eg:
<FilesMatch \.php$>
# Apache 2.4.10+ can proxy to unix socket
SetHandler "proxy:unix:/var/run/php/php5.6-fpm.sock|fcgi://localhost/"
</FilesMatch>
Any ideas what might be the problem here?

With fpm I needed to restart php, service apache restart had no effect:
service php5.6-fpm restart

Related

PHP 8: Change upload_max_filesize

I need to increase the values of upload_max_filesize and post_max_size from the default 2M to 10M.
(I need to do this for a specific vhost. Changing the values globally (for all vhosts) in php.ini is not an option.)
When running PHP 7, I did it by having the following in the Apache2 configuration file for the VirtualHost.
php_value upload_max_filesize 10M
php_value post_max_size 10M
After upgrading to PHP 8, these lines no longer work.
I'm running Ubuntu 20.04, and have installed PHP 8 using the following PPA:
sudo add-apt-repository ppa:ondrej/php
Here is how I installed PHP:
sudo apt install php
sudo apt install php-fpm
sudo apt install libapache2-mod-fcgid
sudo a2enmod actions fcgid alias proxy_fcgi
Checking status:
sudo systemctl status php8.1-fpm
php8.1-fpm.service - The PHP 8.1 FastCGI Process Manager
Loaded: loaded (/lib/systemd/system/php8.1-fpm.service; enabled;
Active: active (running) since Sun 2022-08-28 15:32:37 UTC; 1min 30s ago
Docs: man:php-fpm8.1(8)
Main PID: 739 (php-fpm8.1)
[…]
Here is how part of the configuration file looks:
<VirtualHost *:80>
[…]
php_value upload_max_filesize 10M
php_value post_max_size 10M
<FilesMatch \.php$>:
SetHandler proxy:unix:/var/run/php/php8.1-fpm.sock|fcgi://localhost"
</FilesMatch>
[…]
</VirtualHost>
When inspecting PHP configuration, I see:
Directive Local value Master value
upload_max_filesize 2M 2M
What is the right way to do this when using PHP 8?
You have php running via fpm. fpm is a separate process with which apache interacts, in your case, via socket file.
As in my comment, you have 2 options to personalize the php settings:
using ini_set()
separate fpm pool for the specific virtualhost
via ini_set() is the fastest and simplest way, just add the following to the page where you manage the upload
ini_set('upload_max_filesize', '10M');
ini_set('post_max_size', '10M');
The second option is a bit more complicated, you need to configure a new fpm pool. By doing it quickly, just copy the existing configuration, usually in /etc/php/8.1/pool.d) and modify it. They key line are:
listen = /var/run/php/php8.1-fpm.sock
to
listen = /var/run/php/php8.1-mysite-fpm.sock
and add/modify
php_admin_value[upload_max_filesize] = 10M
php_admin_value[post_max_size] = 10M
Restart php-fpm and verify that it goes up without error
Then make your apache virtualhost point to the new socket
<FilesMatch \.php$>:
SetHandler proxy:unix:/var/run/php/php8.1-mysite-fpm.sock|fcgi://localhost"
</FilesMatch>
restart apache and it should work

PHP upload_max_filesize doesn't change

I'm trying to change the php config for upload_max_filesize on my server (LEMP Stack).
In phpinfo I can see:
Loaded Configuration File: /etc/php/7.2/fpm/php.ini
I've changed upload_max_filesize to 256M in this file.
Then I've restarted by running this command: systemctl restart nginx.
The problem is that when I check my phpinfo it hasn't changed... .
You have to restart the php-fpm service for the changes to take effect:
systemctl restart php7.2-fpm.service

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

php.ini upload_max_filesize not updating

I'm running CentOS 6.4. I've made changed to my php.ini file in the /etc folder. I have changed the upload_max_filesize from 2M to 50M so it reads:
upload_max_filesize = 50M
I've also changed the post_max_size to 52M so it reads:
post_max_size = 52M
Now I have restarted Apache using both the service httpd restart command and the /sbin/service command but when I go into my root html directory in /var/www/html and open my test phpinfo() file the values for upload_max_filesize and post_max_filesize are still the default 2M and 8M values respectively.
Have I missed something?
I had to do this.
service php-fpm restart
The latest php versions doesn't allow direct php.ini changes.
Look for "Scan this dir for additional .ini files" directory in your phpinfo() output and create whatever-file-name.ini in this location.
Put your custom variables in it.
Restart the webserver.
check the loading configuration file (php.ini) from the o/p of phpinfo(). Make sure that you have made changes in the right configuration file (php.ini file)
I had the same problem.
The following changes fixed the issue.
Open phpinfo() and look for "Loaded Configuration File", this file should be updated.
Update your php.ini file.
Kill "php-fpm" process
killall php-fpm
Restart httpd
systemctl restart httpd
I had this line uncommented, it needs to be commented Default Value: E_ALL & ~E_NOTICE & ~E_STRICT & ~E_DEPRECATED in php.ini
After that I could edit any value. And of course restart your apache
In my case sudo service apache2 restart applied the changes.
Check your php.ini file, don't have any errors. php.ini don't set any configuration after error line.
I have set the following values in .htaccess and it's working fine.
(I wanted to upload 25 MB file)
php_value post_max_size 30M
php_value upload_max_filesize 25M
php_value upload_max_size 25M

Categories