简体   繁体   English

在 Ubuntu php.ini 中对 upload_max_filesize 的更改不会生效

[英]Changes to upload_max_filesize in Ubuntu php.ini will not take effect

I have been trying for two days to increase the max filesize for file uploads via php to 10M from the default 2M.我已经尝试了两天将通过 php 上传文件的最大文件大小从默认的 2M 增加到 10M。 I change the php.ini file that is referenced by phpinfo to no avail.我更改了 phpinfo 引用的 php.ini 文件无济于事。

I saw a few articles stating that there is a syntax error around line 109 of the php.ini file, but I don't know what the syntax error is or how to correct it.看到几篇文章说php.ini文件第109行左右有语法错误,但不知道是什么语法错误,也不知道怎么改正。 users stated that because the upload_max_filesize is AFTER this error in the config file it is being ignored.用户表示,因为upload_max_filesize 是在配置文件中的此错误之后,因此被忽略。 Please help.请帮忙。

This message helped me: 这条消息帮助了我:

The newest php version installed on server does not allow global settings (such as execution time, max upload filesize, max post file size, etc.) to be changed.服务器上安装的最新 php 版本不允许更改全局设置(例如执行时间、最大上传文件大小、最大发布文件大小等)。

Folow these steps to resolve the issue:请按照以下步骤解决问题:

  1. Eval phpinfo();评估phpinfo();
  2. Search for ' Scan this dir for additional .ini files ' text in phpinfo() outputphpinfo()输出中搜索“扫描此目录以获取其他 .ini 文件”文本
  3. It will be something like this /etc/php5/apache2/conf.d它会是这样的/etc/php5/apache2/conf.d
  4. Create your user.ini file inside the dir.在目录中创建您的user.ini文件。 ( /etc/php5/apache2/conf.d/user.ini ) ( /etc/php5/apache2/conf.d/user.ini )
  5. Use this ini file for custom settings.使用此 ini 文件进行自定义设置。
  6. Restart the server重启服务器

File /etc/php5/apache2/conf.d/user.ini文件/etc/php5/apache2/conf.d/user.ini

post_max_size = 90M
upload_max_filesize = 50M

Update 2018.06 2018.06 更新

If you are using nginx + php-fpm your path will be something like this (use your php version in path) .如果您使用的是nginx + php-fpm,您的路径将是这样的(在路径中使用您的 php 版本) Create file using:使用以下命令创建文件:

nano /etc/php/7.0/fpm/conf.d/user.ini

There are a lot of other .ini files in the conf.d directory. conf.d目录中有很多其他.ini文件。 If you want your config to be the last included - use prefix.如果您希望您的配置成为最后一个包含 - 使用前缀。

For example: 30-user.ini .例如: 30-user.ini

After file creation don't forget to restart fpm :创建文件后不要忘记重新启动fpm

sudo service php7.0-fpm restart

如果您的 php.ini 位于/etc/php/7.*/fpm/php.ini地方 - 然后根据需要修改它,而不是sudo service apache2 restart使用service php7.1-fpm restart

Have you restarted apache2?你重启apache2了吗?

sudo service apache2 restart

The new php.ini configuration is only applied when apache starts.新的 php.ini 配置仅在 apache 启动时应用。

You might also need to increase the maximum size of a post:您可能还需要增加帖子的最大大小:

post_max_size=10M

Try that.试试那个。

I had exactly the same problem and solved it using these steps:我遇到了完全相同的问题并使用以下步骤解决了它:

When running the following command on my server在我的服务器上运行以下命令时

php --ini

I got the following path of my php.ini我得到了我的 php.ini 的以下路径

Loaded Configuration File:         /etc/php/7.0/cli/php.ini

I kept on making changes in this php.ini file, but none of the changes took effect.我一直在这个 php.ini 文件中进行更改,但没有任何更改生效。 I then created a file called info.php in my /var/www/html directory and added the following code然后我在我的 /var/www/html 目录中创建了一个名为 info.php 的文件并添加了以下代码

<?php
    phpinfo();
?>

Then I opened the file in my browser http://example.com/info.php , where I saw that the actual loaded php.ini file was in a different directory然后我在浏览器中打开了该文件http://example.com/info.php ,在那里我看到实际加载的 php.ini 文件位于不同的目录中

Loaded Configuration File   /etc/php/7.0/apache2/php.ini

When I made changes to the php.ini file inside of this directory, all the changes took effect.当我对该目录中的 php.ini 文件进行更改时,所有更改都生效了。 In summary make sure that you run the phpinfo();总之,请确保您运行 phpinfo(); function to make sure of the actual php.ini file which php uses.函数以确保 php 使用的实际 php.ini 文件。

service apache2 reload needs to be run as root, even if it does not appear to fail without root . service apache2 reload需要以 root 身份运行,即使它在没有 root 的情况下似乎不会失败 Running sudo service apache2 reload works.运行sudo service apache2 reload工作。 This is in Ubuntu 14.04.这是在 Ubuntu 14.04 中。

Maybe you find 2 directories for php.ini files.也许您会找到 2 个 php.ini 文件目录。 If you search where php.ini is using cli like php --ini maybe it show you /etc/php/7.1/cli/php.ini , but thereis another folder to php-fpm found in /etc/php/7.1/fpm/php.ini and you need to create your new ini file under conf.d folder like /etc/php/7.1/fpm/conf.d/30-user.ini and if you need a ini file to cli command line you need to put your ini file under /etc/php/7.1/cli/conf.d/30-user.ini如果您搜索 php.ini 使用 cli 的位置,例如php --ini可能会显示/etc/php/7.1/cli/php.ini ,但是在/etc/php/7.1/fpm/php.ini还有另一个php-fpm文件夹/etc/php/7.1/fpm/php.ini并且您需要在conf.d文件夹下创建新的 ini 文件,例如/etc/php/7.1/fpm/conf.d/30-user.ini并且如果您需要一个用于 cli 命令行的 ini 文件,您需要将您的 ini 文件放在/etc/php/7.1/cli/conf.d/30-user.ini

I had a very strange experience which caused the same symptom like this.我有一个非常奇怪的经历,导致了同样的症状。

The point is that my php.ini file contained an old-style comment (starting with hashmark) which, as of php 7.0, is not a comment any more.关键是我的 php.ini 文件包含一个旧式注释(以哈希标记开头),从 php 7.0 开始,它不再是注释。 The incorrect comment confused the ini-parser.不正确的注释混淆了 ini 解析器。

The solution was to replace all # comment symbols with semicolon (;) which is the only standard way for writing comments.解决方案是用分号 (;) 替换所有 # 注释符号,这是编写注释的唯​​一标准方式。

For further details, please read my comment here:有关更多详细信息,请在此处阅读我的评论:

https://serverfault.com/a/1012262/494670 https://serverfault.com/a/1012262/494670

After reading great @Jekis 's answer, I solved the same issue for Fedora distribution (it's the same thing, just different path):在阅读了很棒的@Jekis的回答后,我解决了 Fedora 发行版的相同问题(这是同一件事,只是路径不同):

  1. After evaluting phpinfo();在评估phpinfo(); output I found out that other .ini files are stored in: /etc/php.d directory输出我发现其他.ini文件存储在: /etc/php.d目录中

  2. In /etc/php.d I created a new file - 40-user.ini ./etc/php.d我创建了一个新文件 - 40-user.ini I added upload_max_filesize and other settings that I wanted to change我添加了upload_max_filesize和我想更改的其他设置

  3. Then I restarted apache (httpd)然后我重新启动了apache(httpd)

And then changes were picked up.然后改变了。

Changes to Ubuntu php.ini will not take effect.对 Ubuntu php.ini 的更改不会生效。

Steps to resolve this issue in Ubuntu 18.04 with Nginx 1.18.0.在使用 Nginx 1.18.0 的 Ubuntu 18.04 中解决此问题的步骤。

  1. Check the php version you are running: php -v检查您正在运行的 php 版本: php -v
  2. Check for syntax errors in php.ini: sudo php-fpm7.4 -t (change to the version you are running).检查 php.ini 中的语法错误: sudo php-fpm7.4 -t (更改为您正在运行的版本)。
  3. Use your favorite editor to fix syntax errors.使用您喜欢的编辑器修复语法错误。
  4. Restart php-fpm: sudo systemctl restart php7.4-fpm (change to the version you are running).重启 php-fpm: sudo systemctl restart php7.4-fpm (更改为您正在运行的版本)。

My results: PHP: syntax error, unexpected END_OF_LINE, expecting '=' in /etc/php/7.4/fpm/php.ini on line 2我的结果:PHP:语法错误,意外的 END_OF_LINE,在第 2 行的 /etc/php/7.4/fpm/php.ini 中期待“=”

In my case it was a "w" before the [PHP] which must have happened when I was using Ctrl w for searching with nano.在我的情况下,它是 [PHP] 之前的“w”,当我使用 Ctrl w 使用 nano 进行搜索时一定发生过。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM