# 常见PHP配置文件修改

使用PHP应用程序的时候，php组件的启用或停用、邮件设置、上传文件大小等控制都会涉及修改php配置文件。本镜像php配置文件的安装目录为： /etc/php.ini

下面是一些与安装相关的php参数：

* memory\_limit – **Minimum:** 256M   //默认内存
* upload\_max\_filesize – **Minimum:** 20M  //上传文件最大值
* post\_max\_size – **Minimum:** 20M   //通过POST提交数据的最大值
* max\_execution\_time: **At Least** 120 **Recommended:** 300  //PHP最大执行时间

需要修改上述参数的值，只需要通过SFTP打开php.ini，修改（“#”在前的项表示没有启用，请根据实际情况删除“#”），然后保存

保存后还需要重启http服务才能生效，重启命令如下：

```
~# systemctl restart httpd
```

如果您不会使用命令操作，通过云服务器后台去重启服务器也可以达到同样的效果。

## [实例：如何修改上传文件大小限制？](/bt-linux-image-guide/bt-bao-ta-mian-ban-jing-xiang-shou-ce-linux-1/chang-jian-php-pei-zhi-wen-jian-xiu-gai.md#1301)

通过SFTP修改 /etc/php.ini 如下的部分

```
; Maximum size of POST data that PHP will accept.
post_max_size = 16M
; Maximum allowed size for uploaded files.
upload_max_filesize = 16M
```

保存后，重启http服务

```
~# systemctl restart httpd
```

如果您不会使用命令操作，通过云服务器后台去重启服务器也可以达到同样的效果。

## [实例：如何修改系统最大响应时间？](/bt-linux-image-guide/bt-bao-ta-mian-ban-jing-xiang-shou-ce-linux-1/chang-jian-php-pei-zhi-wen-jian-xiu-gai.md#1302) <a href="#id-0" id="id-0"></a>

我们在运行应用程序的时候，常常会等待很长的时间之后，却收到这样的错误提示 “Maximum execution time of 30 seconds exceeded”。这种情况下就需要通过修改the max\_execution\_time（最大执行响应时间）的值来解决这个问题。

**方法一（推荐）:** 通过SFTP修改 /etc/php.ini 如下的部分

```
; Maximum execution time of each script, in seconds
; http://php.net/max-execution-time
; Note: This directive is hardcoded to 0 for the CLI SAPI
max_execution_time = 90
; Maximum amount of time each script may spend parsing request data. It's a good
; idea to limit this time on productions servers in order to eliminate unexpectedly
; long running scripts.
```

**方法二:** 如果应用程序支持 .htaccess，请修改它:

```
<IfModule mod_php5.c>
php_value max_execution_time 90
</IfModule>
```

保存后，重启http服务

```
~# systemctl restart httpd
```

如果您不会使用命令操作，通过云服务器后台去重启服务器也可以达到同样的效果。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://websoft9.gitbook.io/bt-linux-image-guide/bt-bao-ta-mian-ban-jing-xiang-shou-ce-linux-1/chang-jian-php-pei-zhi-wen-jian-xiu-gai.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
