Php get ini path

Where is my php.ini file located?

In this guide, we will show you how to find the location of your php.ini file.

As you probably already know, the php.ini file is a configuration file that allows you to enable and disable PHP extensions. It also allows you to configure a number of key directives.

Unfortunately, finding the location of the php.ini file can be a bit tricky at times.

Use the phpinfo() function.

The easiest way to find your php.ini file is to use the PHP function phpinfo like so:

//Use phpinfo to output information //about PHP's configuration: phpinfo();

The phpinfo function is a debugging tool that prints out information about your PHP installation.

In the output, you will find a line called “Loaded Configuration File”:

An output from phpinfo.

This is the PHP configuration file that has been loaded by your web server.

If you want to enable an extension or alter a configuration setting, you will need to edit this file.

As you can see in the screenshot above, I am using Windows and my php.ini file is located at:

C:\wamp64\bin\apache\apache2.4.27\bin\php.ini

Note how I highlighted the words “loaded by your web server” above.

I made this distinction because the command line version of PHP (PHP CLI) has its own php.ini file.

To make things even more confusing, there may be other php.ini files elsewhere on your file system.

For example, the file that my web server uses can be found inside the Apache folder. However, there is also a default configuration file located at:

When I first started out programming in PHP, I would often edit the wrong file. I would then spend the next 20 minutes scratching my head and wondering why my changes weren’t taking effect.

Note that you should always make sure that you remove your phpinfo script from your web server after you are finished using it.

As you can see in the screenshot above, the output from phpinfo contains a lot of sensitive information about your server environment.

Finding the php.ini location via the command line.

If you are using Linux and you are looking to find the php.ini file for PHP CLI, then you can use the following command:

The command above tells PHP to print out its configuration values. The grep utility then searches the output for a line that contains the phrase “php.ini”.

On an Ubuntu server that I have, this command resulted in the following output:

Configuration File (php.ini) Path => /etc/php/7.2/cli Loaded Configuration File => /etc/php/7.2/cli/php.ini

As you can see, the PHP CLI configuration file on my server is located at:

This means that if I want to make changes to how PHP CLI works, I will need to modify the file above.

Use the php_ini_loaded_file function.

If you are using PHP version 5.2.4 or above, then you can also use the php_ini_loaded_file function.

This function will return the location of the php.ini file as a string:

//Get the php.ini file location as a string $iniFile = php_ini_loaded_file(); echo $iniFile;

This approach is much better than using phpinfo, as it displays far less sensitive information.

If you do happen to forget to delete the script, then at least it isn’t outputting a truck load of information about your PHP environment.

Источник

Where is my PHP php.ini Configuration File Located?

PHP php.ini Configuration File location

In this article, we will guide you on a treasure hunt to find the php.ini configuration file, unravel its mysteries, and unlock the full capabilities of your PHP environment. Whether you are a seasoned PHP developer or a newcomer to the world of web development, understanding the ins and outs of this essential configuration file will make your journey smoother and your projects more efficient. So, let’s embark on this exciting quest to locate and master the php.ini file!

Method 1

One way to find out exactly which php.ini file your web sever is using is by creating a new PHP file in document root called info.php .

Load this file in your browser, press CTRL + F (or Command + F on Mac) and search for “Loaded Configuration File”. You should see something like

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.ini configuration file.

Or in Windows Command Line:

The result should be something like this:

In the above example, we can see that the PHP install is located in /etc/php/8.1 . Note that there are three different configuration files you should we aware of:

CLI

/etc/php/8.1/cli/php.ini 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 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/fpm/php.ini 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 locate command in Linux,. If it’s not already installed, run sudo apt update && sudo apt install mlocate .

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.ini is usually located in /etc/php/8.1/apache2/php.ini . Replace 8.1 with your own version, e.g, php5.6 , php7.4 , etc.

However, if you are using PHP FPM, it may be located in /etc/php/8.1/fpm/php.ini . Replace 8.1 with your own version, e.g, php5.6 , php7.4 , etc.

To save file and exit, press CTRL + X , press Y and then press ENTER

You must restart Apache after altering php.ini .

If you are using PHP-FPM, you must restart that service. Replace php8.1 with your own version, e.g, php5.6 , php7.4 , etc.

Nginx or Apache with PHP-FPM

Nginx uses PHP FPM and php.ini is usually located in /etc/php/8.1/fpm/php.ini . Replace 8.1 with your own version, e.g, php5.6 , php7.4 , etc.

Save and exit (press CTRL + X , press Y and then press ENTER )

You must restart Nginx after altering php.ini .

Older Versions

For versions of Ubuntu lower than 16.04, /etc/php/5.6/ , /etc/php/7.0/ , /etc/php/7.1/ , and so on, are replaced by /etc/php5/ and so on. Otherwise, these paths remain accurate.

Let me know if this helped. Follow me on Twitter, Facebook and YouTube, or 🍊 buy me a smoothie.

p.s. I increased my AdSense revenue by 200% using AI 🤖. Read my Ezoic review to find out how.

No replies yet

Join the full discussion at the DevAnswe.rs Forums →

2 replies

Leave a reply Cancel reply

Very good… this information saved me!

Источник

Where is my php.ini file located?

In this guide, we will show you how to find the location of your php.ini file.

As you probably already know, the php.ini file is a configuration file that allows you to enable and disable PHP extensions. It also allows you to configure a number of key directives.

Unfortunately, finding the location of the php.ini file can be a bit tricky at times.

Use the phpinfo() function.

The easiest way to find your php.ini file is to use the PHP function phpinfo like so:

//Use phpinfo to output information //about PHP's configuration: phpinfo();

The phpinfo function is a debugging tool that prints out information about your PHP installation.

In the output, you will find a line called “Loaded Configuration File”:

An output from phpinfo.

This is the PHP configuration file that has been loaded by your web server.

If you want to enable an extension or alter a configuration setting, you will need to edit this file.

As you can see in the screenshot above, I am using Windows and my php.ini file is located at:

C:\wamp64\bin\apache\apache2.4.27\bin\php.ini

Note how I highlighted the words “loaded by your web server” above.

I made this distinction because the command line version of PHP (PHP CLI) has its own php.ini file.

To make things even more confusing, there may be other php.ini files elsewhere on your file system.

For example, the file that my web server uses can be found inside the Apache folder. However, there is also a default configuration file located at:

When I first started out programming in PHP, I would often edit the wrong file. I would then spend the next 20 minutes scratching my head and wondering why my changes weren’t taking effect.

Note that you should always make sure that you remove your phpinfo script from your web server after you are finished using it.

As you can see in the screenshot above, the output from phpinfo contains a lot of sensitive information about your server environment.

Finding the php.ini location via the command line.

If you are using Linux and you are looking to find the php.ini file for PHP CLI, then you can use the following command:

The command above tells PHP to print out its configuration values. The grep utility then searches the output for a line that contains the phrase “php.ini”.

On an Ubuntu server that I have, this command resulted in the following output:

Configuration File (php.ini) Path => /etc/php/7.2/cli Loaded Configuration File => /etc/php/7.2/cli/php.ini

As you can see, the PHP CLI configuration file on my server is located at:

This means that if I want to make changes to how PHP CLI works, I will need to modify the file above.

Use the php_ini_loaded_file function.

If you are using PHP version 5.2.4 or above, then you can also use the php_ini_loaded_file function.

This function will return the location of the php.ini file as a string:

//Get the php.ini file location as a string $iniFile = php_ini_loaded_file(); echo $iniFile;

This approach is much better than using phpinfo, as it displays far less sensitive information.

If you do happen to forget to delete the script, then at least it isn’t outputting a truck load of information about your PHP environment.

Источник

Читайте также:  Сумма элементов кратных 3 python
Оцените статью