Home > Backend Development > PHP Problem > How to set php.ini in centos

How to set php.ini in centos

PHPz
Release: 2023-04-25 17:50:19
Original
1202 people have browsed it

CentOS is a popular Linux operating system widely used in server and cloud computing scenarios. It is stable, reliable, and highly secure, and is commonly used in web servers, database servers, DNS servers, etc. When using the CentOS server, we often need to adjust the PHP configuration, and the PHP configuration file php.ini is a very important file. This article will introduce how to set up PHP.ini in CentOS. I hope it will be helpful to readers.

1. Find the php.ini file

To modify the php.ini file, you must first find it. In CentOS systems, the php.ini file is usually located in the /etc/php.ini path. You can use the following command to find it:

find / -name php.ini
Copy after login

After execution, the file path will be output on the screen.

2. Back up the original configuration file

Be sure to back up the original configuration file before modifying the configuration file. You can use the following command to back up:

cp /etc/php.ini /etc/php.ini.bak
Copy after login

Use the above command to copy the original configuration file to a new file, and use .bak as the extension.

3. Modify the configuration

First, use the vi editor to open the php.ini file:

vi /etc/php.ini
Copy after login

After entering the edit mode, you can modify different parameters in the configuration file as needed. . The following are descriptions of several commonly used parameters:

max_execution_time = 30  # 执行时间限制,单位为秒
max_input_time = 60  # 输入数据的时间限制,单位为秒
memory_limit = 128M  # PHP脚本运行所能占用的最大内存
upload_max_filesize = 2M  # 上传文件的最大大小
post_max_size = 8M  # post传输数据最大值
Copy after login

After modifying the above parameters, press the ESC key to exit the editing mode, and enter: wq to save the changes and exit the vi editor.

4. Restart the Web server

After completing the above steps, you need to restart the Web server for the configuration to take effect. Generally, CentOS servers use the Apache web server. You can use the following command to restart the Apache Web server:

service httpd restart
Copy after login

If it is an Nginx Web server, you can use the following command to restart:

service nginx restart
Copy after login

5. Verify whether the modification is successful

Completed modification After configuration, you finally need to verify whether the modification is successful. A simple PHP script can be created to test this. In the Web root directory, create a new test.php file with the following content:

<?php phpinfo(); ?>
Copy after login

Then, enter the following address in the browser:

http://<IP地址>/test.php
Copy after login

Among them, is the IP address of the CentOS server. If you can see the output of phpinfo, it means that the PHP configuration has been modified successfully.

Summary

The above are the steps to modify the PHP.ini configuration of CentOS. It should be noted that before modifying the configuration file, be sure to back up the original configuration file. After modifying the configuration file, you need to restart the web server. To verify whether the modification is successful, you can create a simple PHP script to test. Hope this article is helpful to readers.

The above is the detailed content of How to set php.ini in centos. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template