How Do I Know php.ini Location?

如果你正在使用WordPress,你迟早要问自己这个问题. Although not directly connected to WordPress, php.ini 是服务器上最重要的配置文件之一,因为它负责配置PHP安装, 这样你的WordPress网站就会懂php了.ini location is important.



您可能需要更改的最常见参数是 upload_max_filesize. By default it’s 2Mb, which can be quite low. 其他流行的包括register_globals、safe_mode和max_execution_time. 您还可以使用该文件启用或禁用PHP安装的扩展.

根据您的系统和服务器环境,有不同的位置和方法可以找到php.ini location.


What's php.ini Location?

Whether you’re working on localhost, or on a live server, the easiest and proven way to locate your php.ini文件的目的是创建一个PHP文件,其中只有一行代码,并查看输出.

  1. 创建一个文件(命名为任何你想要的,在我们的例子中是test.php’), and make sure it ends with .php extension.
  2. Put this line of code in it:
phpinfo(); ?>
  1. Open the file via your browser. 例如,如果将它放在根文件夹中,运行http://mywebsite.com/test.php.

You should see something like this:

Your php.ini文件应该位于“配置文件路径”部分, 或者像我在“加载配置文件”部分的情况. The first location is the default one, 第二个位置适用于将PHP安装用作模块的情况.


Other solutions

如果在某些情况下,创建一个php文件并插入一行代码对您不起作用, there are some other ways to find php.ini.

Local server

If you’re working locally, finding php.Ini将取决于您使用的服务器环境. 让我们快速浏览一些最受欢迎的.


WAMP

php.ini on WAMP

Left click on your WAPM server icon, then go to PHP -> php.ini. Easy? Easy.


XAMPP

XAMPP是一个有点不同的野兽,但也可以不太困难地驯服. Run your XAMPP installation, 右键单击“Config”按钮(在Apache模块前面),就是这样了, our little guy:

php.ini XAMPP

Linux

如果你使用的是Linux,在终端运行以下命令:

php -i | grep "Loaded Configuration File"

It should output something like this:

Loaded Configuration File => /usr/local/lib/php.ini

In most cases the php.ini将位于“加载的配置文件”中。, but if it’s not there, 将' Loaded Configuration File '字符串替换为' Configuration File '.


Live server

The location of php.ini mostly depends on the hosting you’re using, 但是我们将在这里介绍一些最常见的场景.

cPanel

打开文件管理器,并导航到根目录. Our little guy should be sitting at the bottom.

php.ini cPanel

If you don’t know how to find your root folder, 只需在主public_html目录上走一层.


Shared Hosting

不幸的是,如果您使用的是共享主机,则无法访问php.ini file. 解决方法是在您的文件中指定所需的配置设置 .htaccess file in the following pattern:

php_value name value

这里的名称表示需要更改的PHP属性的名称. The same applies to the value. 例如,下面这行将上传文件的最大大小更改为8mb:

php_value  upload_max_filesize  8M

Restart after the changes

If you made at least one change to php.Ini文件,您必须重新启动服务器,否则更改将不适用. 如果你在Linux上,写下面的命令:

/etc/init.d/httpd restart

WAMP用户必须右键单击工具栏中的服务器图标, and choose ‘Restart all services’.

If you’re using XAMPP, go to the main dashboard, 点击“Apache”模块前面的“停止”按钮, and then click the ‘start’ button again.


Final words

As you can see, finding php.Ini可能既棘手又容易. 我试图涵盖最常见的解决方案和服务器环境, 希望这个指南能帮助你最终找到这个文件. If you know any other ways to find php.Ini,请在下面的评论中分享你的想法.


FAQ

What is php.ini?

它是一个定义所有需要PHP的程序的工作的文件. 它包含默认配置并控制诸如资源限制和上传大小等重要内容.

Why could you need to find the php.ini?

如前所述,它包含了在PHP上工作的应用程序的非常重要的配置. 如果你想改变其中的一些-你将需要php.ini.

变化最频繁的参数是什么?

首先,它可能是upload_max_filesize. 默认值(2Mb)通常太小,网站所有者会将其设置得更大. Besides that, 您可能想要更改register_globals的值, safe_mode, and max_execution_time.

Read Also

How to Build & Maintain Elementor WordPress Website? [Free Course]

How to Build and Maintain an HTML5 Website? [Free Course]

Ultimate Gutenberg Editor Learning Course


Don’t miss out these all-time favourites

  1. The best hosting for a WordPress website. 点击我们的链接,获得市场上最优惠的价格,82%的折扣. If HostPapa didn’t impress you check out other alternatives.
  2. Website Installation service -让您的模板启动和运行在短短6小时内没有麻烦. No minute is wasted and the work is going.
  3. ONE Membership -下载无限数量的WordPress主题, plugins, ppt and other products within one license. Since bigger is always better.
  4. Ready-to-Use Website service 最终的解决方案是否包含完整的模板安装 & configuration, content integration, implementation of must-have plugins, 安全功能和扩展的页面SEO优化. 开发团队将为您完成所有工作.
  5. Must-Have WordPress Plugins -获得最重要的插件为您的网站在一个捆绑包. 所有插件将被安装、激活并检查是否正常运行. 
  6. Finest Stock Images for Websites - to create amazing visuals. You’ll get access to Depositphotos.Com选择15张无限制主题和大小选择的图片.
  7. SSL Certificate Creation service -获得网站访问者的绝对信任. Comodo证书是最可靠的http协议,确保用户数据安全,免受网络攻击. 
  8. Website speed optimization service -增加您的网站的用户体验,并获得更好的谷歌PageSpeed得分.


Matthew Cain

我喜欢从头开始创建网站,用HTML和CSS仔细编码. 有时,即使是最好的和专业创建的模板也需要一些编码技巧. And here is my Quora account.

Get more to your email

订阅我们的时事通讯和访问独家内容和提供只提供给og体育首页Post订户.

From was successfully send!
Server error. Please, try again later.

Leave a Reply