- RootUsers
- Guides, tutorials, reviews and news for System Administrators.
- Where Is The php.ini Configuration File In CentOS?
- RPM Query Configuration Files
- Find Command
- PHPInfo
- Summary
- Share this:
- Настройка параметров PHP (CentOS)
- Создание phpinfo-скрипта
- Настройка параметров
- How to Find php.ini File Location in Ubuntu | Centos Linux
- Using Locate to Find php.ini File Location
RootUsers
Guides, tutorials, reviews and news for System Administrators.
Where Is The php.ini Configuration File In CentOS?
How can we find the default configuration files for the PHP packages in CentOS Linux?
By using the RPM command we can query a package to find all of its associated configuration files. Failing that we can use the find command to search the file system for these files, as we will see here.
Finally we’ll cover how we can use a phpinfo file to show us which configuration file is in use.
RPM Query Configuration Files
The options we will use with the RPM command are -q to query a package, and -c which will list the configuration files that are part of the package. As shown below we have run RPM with the -qc options on the php-common package, which is a dependency when installing the php package and is where the php.ini file comes from in CentOS.
[[email protected] ~]# rpm -qc php-common /etc/php.d/curl.ini /etc/php.d/fileinfo.ini /etc/php.d/json.ini /etc/php.d/phar.ini /etc/php.d/zip.ini /etc/php.ini
These are all of the default configuration files that are installed by the php-common package, we can see here that by default the php.ini file is found at /etc/php.ini.
There are also a couple more configuration files from the php package.
[[email protected] ~]# rpm -qc php /etc/httpd/conf.d/php.conf /etc/httpd/conf.modules.d/10-php.conf
The php package requires the httpd package to be installed, which makes sense as these are the configuration files that tell Apache how to work with PHP.
Find Command
If you aren’t using packages to install PHP and perhaps compiled it from source instead or otherwise installed to a custom location, we can easily run find over the entire file system to find these files.
[[email protected] ~]# find / -name php.ini /etc/php.ini
The above example will search through root file system ‘/’ and find every file named ‘php.ini’.
PHPInfo
We can create a simple phpinfo file and open it in a browser to display the location of the php.ini file that is being used. Copy the below into a .php file and navigate to it within a browser to view this information. You should delete the file once you’re done, as this can provide a lot of information to an attacker.
The “Configuration File (php.ini) Path” shows the directory the php.ini file can be found in, while “Loaded Configuration File” shows the full path to the file.
Summary
With these simple methods we can quickly search the file system to find all php.ini files, or simply display the php.ini file that our php file is currently making use of thanks to phpinfo.
Share this:
Настройка параметров PHP (CentOS)
Ниже мы рассмотрим настройку параметров PHP на сервере с операционной системой Centos или Bitrix.
Создание phpinfo-скрипта
В процессе настройки потребуется получать информацию о параметрах PHP на сервере, поэтому в первую очередь необходимо разместить скрипт phpinfo.php в директории сайта.
Подключитесь к серверу по SSH и выполните следующие действия:
1. Перейдите в директорию сайта:
Например, если на сервере установлен LAMP (автоматически при создании сервера):
Если на сервере установлена панель VestaCP:
cd /home/имя_пользователя/web/имя_домена/public_html
2. Создайте файл phpinfo.php :
3. Добавьте в него следующее содержимое:
4. Сохраните изменения (нажать Ctrl+X для выхода из nano , далее Y для сохранения изменений и Enter).
После перейдите по адресу http://вашдомен/phpinfo.php , и в браузере будет отображена информация о настройках PHP.
Путь к конфигурационному файлу php.ini можно найти в строке Loaded Configuration File :
В нашем случае это /etc/php.ini (стандартное размещение для CentOS).
Настройка параметров
Рассмотрим настройку параметров на примере mbstring.func_overload .
1. Найдите нужный параметр в php.ini при помощи команды:
grep -ni 'имя_параметра' /путь/до/php.ini
grep -ni 'mbstring.func_overload' /etc/php.ini
Ключ -n покажет, в какой строке расположена директива, чтобы можно было перейти сразу к ней.
В данном случае номер строки — 1714.
2. Откройте файл в текстовом редакторе, указав номер нужной строки:
nano +номер_строки путь/до/php.ini
3. Отредактируйте строку: уберите знак комментария ( ; ) и измените значение параметра на нужное вам:
В данном случае мы указываем 2.
4. Сохраните изменения (нажмите Ctrl+x для выхода из nano , далее Y для сохранения изменений и Enter).
5. Перезагрузите веб-сервер Apache:
How to Find php.ini File Location in Ubuntu | Centos Linux
There are several ways to find the php.ini file location in Ubuntu and Centos Linux servers. It is also interesting to note that there are usually several php.ini files on the server. Here will show you how to find the file and determine which one is the active configuration file.
Using Locate to Find php.ini File Location
Use the following command to get a list of all of the php.ini files.
This will give an output similar to this:
/etc/php/7.2/apache2/php.ini /etc/php/7.2/cli/php.ini /etc/php/7.2/fpm/php.ini /etc/php/7.3/cli/php.ini /etc/php/7.4/apache2/php.ini /etc/php/7.4/apache2/php.ini.save /etc/php/7.4/apache2/php.ini.ucf-dist /etc/php/7.4/cli/php.ini /etc/php/7.4/cli/php.ini.ucf-dist /etc/php/7.4/fpm/php.ini /etc/php/7.4/fpm/php.ini.ucf-dist /etc/php/8.0/cli/php.ini /usr/lib/php/5.6/php.ini-development /usr/lib/php/5.6/php.ini-production /usr/lib/php/5.6/php.ini-production.cli /usr/lib/php/7.0/php.ini-development /usr/lib/php/7.0/php.ini-production /usr/lib/php/7.0/php.ini-production.cli /usr/lib/php/7.1/php.ini-development /usr/lib/php/7.1/php.ini-production /usr/lib/php/7.1/php.ini-production.cli /usr/lib/php/7.2/php.ini-development /usr/lib/php/7.2/php.ini-production /usr/lib/php/7.2/php.ini-production.cli /usr/lib/php/7.3/php.ini-development /usr/lib/php/7.3/php.ini-production /usr/lib/php/7.3/php.ini-production.cli /usr/lib/php/7.4/php.ini-development /usr/lib/php/7.4/php.ini-production /usr/lib/php/7.4/php.ini-production.cli /usr/lib/php/8.0/php.ini-development /usr/lib/php/8.0/php.ini-production /usr/lib/php/8.0/php.ini-production.cli
The above output may not be very helpful in drilling down to the active php.ini file location.
You can use the PHP CLI to get the configuration file that is being used in your setup with the following command:
From the output look for the line similar to this:
Loaded Configuration File => /etc/php/7.4/cli/php.ini
You can also use the following to retrieve the same output:
$ php -r "echo php_ini_loaded_file().PHP_EOL;"
With the expected result being:
You can use PHPs phpinfo function as follows:
$ php -r "phpinfo();" | grep php.ini
With the following as the result.
Configuration File (php.ini) Path => /etc/php/7.4/cli Loaded Configuration File => /etc/php/7.4/cli/php.ini
In case you need to get the php.ini file location for the settings used by the webserver you will need to use the following function from within a PHP file created in the web server document root and accessed from a web browser.
echo php_ini_loaded_file().PHP_EOL;
There you have it you should now be able to find the php.ini file location in Ubuntu and Centos Linux servers including determining the one that is active.
Found this article interesting? Follow Brightwhiz on Facebook, Twitter, and YouTube to read and watch more content we post.