Hướng dẫn how to find php --ini - cách tìm php --ini

Run

<?php
phpinfo();
?>
0 in your terminal, and you'll get all details about ini files:

Configuration File (php.ini) Path: /etc
Loaded Configuration File:         /etc/php.ini
Scan for additional .ini files in: /etc/php.d
Additional .ini files parsed:      /etc/php.d/apc.ini,
/etc/php.d/bcmath.ini,
/etc/php.d/curl.ini,
/etc/php.d/dba.ini,
/etc/php.d/dom.ini,
/etc/php.d/fileinfo.ini,
/etc/php.d/gd.ini,
/etc/php.d/imap.ini,
/etc/php.d/json.ini,
/etc/php.d/mbstring.ini,
/etc/php.d/memcache.ini,
/etc/php.d/mysql.ini,
/etc/php.d/mysqli.ini,
/etc/php.d/pdo.ini,
/etc/php.d/pdo_mysql.ini,
/etc/php.d/pdo_sqlite.ini,
/etc/php.d/phar.ini,
/etc/php.d/posix.ini,
/etc/php.d/sqlite3.ini,
/etc/php.d/ssh2.ini,
/etc/php.d/sysvmsg.ini,
/etc/php.d/sysvsem.ini,
/etc/php.d/sysvshm.ini,
/etc/php.d/wddx.ini,
/etc/php.d/xmlreader.ini,
/etc/php.d/xmlwriter.ini,
/etc/php.d/xsl.ini,
/etc/php.d/zip.ini

For more, use helping command

<?php
phpinfo();
?>
1. It'll display all the possible options.

Hướng dẫn how to find php --ini - cách tìm php --ini

Last updated on June 7th, 2022 | 2 replies

As there are multiple versions of PHP with different sever configurations, php.ini could be located in several different folders.

Method 1

One way to find out exactly which

<?php
phpinfo();
?>
2 file your web sever is using is by creating a new PHP file in document root called
<?php
phpinfo();
?>
3.

info.php

<?php
phpinfo();
?>

Load this file in your browser, press

<?php
phpinfo();
?>
4 +
<?php
phpinfo();
?>
5 (or
<?php
phpinfo();
?>
6 +
<?php
phpinfo();
?>
5 on Mac) and search for “Loaded Configuration File”. You should see something like

/etc/php/8.1/apache2/php.ini

This will tell you the exact location of the php.ini file you want to edit.

Method 2

In Linux, run this command to locate the

<?php
phpinfo();
?>
8 configuration file.

php -i | grep "Loaded Configuration File"

Or in Windows Command Line:

php -i | findstr /c:"Loaded Configuration File"

The result should be something like this:

Loaded Configuration File => /etc/php/8.1/cli/php.ini

In the above example, we can see that the PHP install is located in

<?php
phpinfo();
?>
9. Note that there are three different configuration files you should we aware of:

CLI

/etc/php/8.1/apache2/php.ini
0 is for the CLI PHP program. Changes to this config file will only affect PHP as it runs in the terminal – it will NOT affect the web server.

Apache

/etc/php/8.1/apache2/php.ini
1 is for the PHP plugin used by Apache. This is the one you need to edit if you are using the Apache web server.

Nginx or Apache with PHP-FPM

/etc/php/8.1/apache2/php.ini
2 is a fastcgi-compatible ‘wrapper’ for PHP processing. This is the one you need to edit if you’re using the Nginx web server or Apache with PHP-FPM.

Method 3

Using the

/etc/php/8.1/apache2/php.ini
3 command in Linux,. If it’s not already installed, run  
/etc/php/8.1/apache2/php.ini
4.

You should see a list of php.ini files here. Try editing one of them and restarting you web server to see if makes the required changes.

Editing php.ini in Linux

Apache

On Apache, 

<?php
phpinfo();
?>
2 is usually located in 
/etc/php/8.1/apache2/php.ini
1. Replace 
/etc/php/8.1/apache2/php.ini
7 with your own version, e.g, 
/etc/php/8.1/apache2/php.ini
8, 
/etc/php/8.1/apache2/php.ini
9, etc.

To edit:

sudo nano /etc/php/8.1/apache2/php.ini

However, if you are using PHP FPM, it may be located in 

/etc/php/8.1/apache2/php.ini
2. Replace 
/etc/php/8.1/apache2/php.ini
7 with your own version, e.g, 
/etc/php/8.1/apache2/php.ini
8, 
/etc/php/8.1/apache2/php.ini
9, etc.

To edit:

sudo nano /etc/php/8.1/fpm/php.ini

To save file and exit, press 

<?php
phpinfo();
?>
4 + 
php -i | grep "Loaded Configuration File"
5, press 
php -i | grep "Loaded Configuration File"
6 and then press 
php -i | grep "Loaded Configuration File"
7

You must restart Apache after altering 

<?php
phpinfo();
?>
2.

sudo systemctl restart apache2

If you are using PHP-FPM, you must restart that service. Replace 

php -i | grep "Loaded Configuration File"
9 with your own version, e.g, 
/etc/php/8.1/apache2/php.ini
8, 
/etc/php/8.1/apache2/php.ini
9, etc.

sudo service php8.1-fpm restart

Nginx or Apache with PHP-FPM

Nginx uses PHP FPM and <code>php.ini</code>&nbsp;is usually located in&nbsp;<code>/etc/php/8.1/fpm/php.ini</code>.&nbsp;Replace&nbsp;<code>8.1</code>&nbsp;with your own version, e.g,&nbsp;<code>php5.6</code>,&nbsp;<code>php7.4</code>, etc.</p><div class="code-wrap"><pre id="supercoder-block_629f3eb9c73bc" class="code language-bash"><code class="language-bash">sudo nano /etc/php/8.1/fpm/php.ini</code></pre><div class="btn-copy-wrapper"><button class="btn-copy" title="Copy"></button></div></div><p>Save and exit (press <code>CTRL</code> + <code>X</code>, press <code>Y</code> and then press <code>ENTER</code>)</p><p>You must restart Nginx after altering&nbsp;<code>php.ini</code>.</p><div class="code-wrap"><pre id="supercoder-block_629f3ed8c73bd" class="code language-bash"><code class="language-bash">sudo systemctl reload nginx</code></pre><div class="btn-copy-wrapper"><button class="btn-copy" title="Copy"></button></div></div><a class="anchor" id="id-older-versions"></a><h2>Older Versions</h2><p>For versions of Ubuntu <em>lower</em> than 16.04, <code>/etc/php/5.6/</code>,<code>/etc/php/7.0/</code>,<code>/etc/php/7.1/</code>, and so on, are replaced by <code>/etc/php5/</code> and so on. Otherwise, these paths remain accurate.<span id="ezoic-pub-ad-placeholder-130" class="ezoic-adpicker-ad"></span></p><p>Let me know if this helped. Follow me on <a href="https://twitter.com/DevAnswers" target="_blank" rel="noreferrer">Twitter</a>, <a href="https://www.facebook.com/DevAnswers-326312698016716/" target="_blank" rel="noreferrer">Facebook</a> and <a href="https://www.youtube.com/channel/UCXvcK0LxaefzAgkUJWqd0FA" target="_blank" rel="noreferrer">YouTube</a>, or 🍊 <a href="https://www.buymeacoffee.com/DevAnswers" target="_blank" rel="noreferrer">buy me a smoothie</a>.</p><p>p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my <a target="_blank" href="https://devanswers.co/ezoic-review-increase-adsense-ad-revenue/">Ezoic review</a> to find out how.</p></div></article><div id="comments" class="comments-area"><a class="anchor" id="comments-anchor"></a><h2 class="comments-title">2 replies</h2><div id="respond" class="comment-respond"><h3 id="reply-title" class="comment-reply-title">Leave a reply <small></small></h3><form action="https://devanswers.co/wp-comments-post.php" method="post" id="commentform" class="comment-form" novalidate><p class="comment-notes"><span id="email-notes">Your email address will not be published.</span> <span class="required-field-message" aria-hidden="true">Required fields are marked <span class="required" aria-hidden="true">*</span></span></p><p class="comment-form-comment"><label for="comment">Comment <span class="required" aria-hidden="true">*</span></label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" required></textarea></p><p class="comment-form-author"><label for="author">Name <span class="required" aria-hidden="true">*</span></label> <input id="author" name="author" size="30" maxlength="245" required></p><p class="comment-form-email"><label for="email">Email <span class="required" aria-hidden="true">*</span></label> <input id="email" name="email" type="email" size="30" maxlength="100" aria-describedby="email-notes" required></p><p class="comment-form-cookies-consent"><input id="wp-comment-cookies-consent" name="wp-comment-cookies-consent" type="checkbox" value="yes"> <label for="wp-comment-cookies-consent">Save my name, email, and website in this browser for the next time I comment.</label></p><p class="form-submit"><input name="submit" type="submit" id="submit" class="submit" value="Post Comment"> <input type="hidden" name="comment_post_ID" value="464" id="comment_post_ID"> <input type="hidden" name="comment_parent" id="comment_parent" value="0"></p><p style="display:none"><input type="hidden" id="akismet_comment_nonce" name="akismet_comment_nonce" value="dcb7dd6115"></p><p style="display:none!important"><label>Δ<textarea name="ak_hp_textarea" cols="45" rows="8" maxlength="100"></textarea></label><input type="hidden" id="ak_js_1" name="ak_js" value="205"><script>document.getElementById("ak_js_1").setAttribute("value",(new Date()).getTime());