Enable php cli php ini

Where can php.ini be Found

This tutorial is dedicated to an issue that almost every developer may come across. It’s where to find the php.ini file.

As multiple versions of PHP exist with different server configurations, the php.ini file may be placed in different folders.

Here, we will provide you with three methods that will help you to find php.ini in a straightforward way.

Method 1: Creating a new PHP File

The first method to find the php.ini file is creating a new PHP file called info.php . Here is how you can implement it:

You need to load this file in the browser, pressing CTRL + F and looking for “Loaded Configuration File”. You may see what is demonstrated below:

It will tell you the exact location of the php.ini file.

Method 2: Using php -i

For locating the php.ini configuration file, you can run the code below in Linux:

$ php -i | grep "Loaded Configuration File"

In the Windows Command Line, you can invoke:

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

The output will look like this:

Loaded Configuration File => /etc/php/7.2/cli/php.in

So, from the example mentioned above, we found out that the PHP install is placed inside /etc/php/7.2 . But, there is an essential thing to consider: there exist three distinct configuration files. Let’s take a look at them:

CLI

For the CLI PHP program, there exists /etc/php/7.2/cli/php.ini . Modifications in this config file will only impact PHP because it operates within the terminal. Hence, the web server will not be affected by that.

APACHE

For the plugin used for APACHE, there exists /etc/php/7.2/apache2/php.ini . You are required to edit it once you work with the APACHE web server.

Nginx either Apache with PHP-FPM

Now, let’s have a look at /etc/php/7.2/apache2/php.ini . It is considered a fastcgi-compatible ‘wrapper’. You are required to edit it once you work with Apache with PHP-FPM or Nginx web server.

Method 3: Using the locate Command

The third method is using the locate command in Linux. If you haven’t installed it yet, you can act like this:

sudo apt update && sudo apt install mlocate

Then, run the locate command as follows:

Читайте также:  Java вырезать часть строки

After running this command, you will notice the list of php.ini files.

How to Edit php.ini in Linux

In this section, we will demonstrate how to edit php.ini on APACHE and Nginx or Apache with PHP-FPM.

APACHE

As a rule, the php.ini file is located in /etc/php/7.2/apache2/php.ini on APACHE. You can replace it with the version that you use. For example, php 7.1 , and so on.

For editing, you can act like this:

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

If you work with PHP FPM, it can be placed in /etc/php/7.2/fpm/php.ini . So, change the 7.2 version to your own version.

For editing, you can act like this:

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

Afterwards, you need to press CTRL + X , pressing Y and then — ENTER. In this way, you will save the file and exit it.

After alerting php.ini, you need to restart APACHE.

If you use PHP-FMP, you should restart it.

Nginx or Apache with PHP-FPM

As a rule, Nginx works with PHP-FPM. The php.ini file is placed inside /etc/php/7.2/fpm/php.ini . You need to replace the 7.2 version with your own one.

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

For saving the file, you need to press CTRL + X . Afterwards, press Y and then ENTER .

After the alert of the php.ini file, it is necessary to restart Nginx like this:

After the alert of the php.ini file, it is necessary to restart Nginx like this:

sudo service nginx restart

So, in this tutorial, we represented to you three different and efficient ways to find the php.ini file. After checking out all the examples above, you can choose the best one for you.

Источник

Using Custom php.ini File for PHP (cli) via SSH

While you are working with PHP in command mode, the php command automatically runs the PHP CLI binary file corresponding to the default PHP version.

To view a list with all PHP CLI options, use the following command:

To check the current PHP CLI version, you should execute:

Check the version of PHP CLI

In case you have not specified another file, PHP CLI will always use the default system php.ini file /opt/cpanel/ea-phpXX/root/etc/php.ini.

If it is necessary to set specific settings for executing a PHP script, you might need to add a -c option to the command followed by the custom php.ini file. For example:

php -c /home/cpuser/my-custom-php.ini /home/cpuser/public_html/file.php

/home/cpuser/my-custom-php.ini – replace the full path and the .ini file name;
/home/cpuser/public_html/file.php – the file that will be executed;

If the custom php.ini file will be used with each PHP command in the console, add a line in the .bash_profile file so that you do not need to type the file name every next time:

alias php='php -c /home/cpuser/my-custom-php.ini'

/home/cpuser/my-custom-php.ini – replace with the full path and the .ini file name;

Читайте также:  Html header text css

If you wish to work with a different PHP (cli) version, edit the line by changing the binary file path:

alias php=’/opt/cpanel/ea-phpXX/root/usr/bin/php -c /home/cpuser/my-custom-php.ini’

ea-phpXX – replace with the PHP version, for example /opt/cpanel/ea-php72/root/usr/bin/php;

ini file for PHP directives is loaded

If you are logged into the hosting account via SSH, log out and then log in again to activate this setting. You might also use this command:

The .bash_profile file settings will load every time you access your hosting account via SSH.

Check which .ini file is loaded with:

This time the command result should display the custom .ini file in the Loaded Configuration File field.

In the command line you can set different values for certain PHP directives through the -d (configuration_directive=value) option. For example:

php -c /home/cpuser/php.ini /home/cpuser/file.php -d memory_limit=256M

According to the set parameters for script execution, the value for memory_limit will be 256MB.

This article is about: hosting services with cPanel.

Источник

Using custom php.ini file with php CLI

Using custom php.ini file with php CLI

© pk2000@sxc.hu

Considering that I have never been real Linux user before, there was few things that I had to learn to successfully handle my code on server through SSH.

One of these things is forcing php CLI to use my custom php.ini file on server.

Let me start this story from beginning …

Situation was that we took managed dedicated server for my Symfony2 project installation to be used as production server. I have no root access there (it’s level 2 managed server), but I always have possibility to ask support to enable me some things that I need inside my project’s account.

Of course, during the testing server configuration with my project I asked support to enable local php.ini file inside my account, so I can change setting as necessary without every time sending mail to support and waiting their response.

So, I got my local php.ini in which I first needed to remove shell_exec function from disabled functions – used in my custom command for handling database backups with cron job (independently and slightly different from default backups handling in control panel)

Yeah, I removed the function from php.ini and made custom command for back up and restore my data using php console command (Symfony2 shell).

Then I noticed that shell_exec is not working from php CLI. It’s still disabled ….
When I add shell_exec function in controller and run the code via web browser, it is working, but within SSH: php console backup create not working and it says that “shell_exec function is disabled for security reasons”…

Читайте также:  Soap web service client in java

Luckily, my colleague @Tomas Novoselic was near and thanks to him that this agony was not took too long. (He is hardcore Linux user … :-))

If you want to force specific php.ini file to be used with Php CLI, you just have to add path to php.ini file that you want to use inside command, so instead of:

$ php console backup create

you should use something like this:

php -c /home/divineof/etc/php.ini console backup create

… and that solved my problem…

In meantime, I found one more elegant solution, considering that I am using bash shell with SSH:
Inside root installation of my hosting account, there is hidden file called ‘.bashrc’, so I opened it and entered inside:

# .bashrc # Source global definitions if [ -f /etc/bashrc ]; then . /etc/bashrc fi # User specific aliases and functions alias php='php -c /home/divineof/etc/php.ini'

After defining alias for php command, I am able to write again like this:

$ php console backup create

That’s all from me for today … 🙂

Источник

где я могу найти php.ini для php-cli

Похоже, что в командной строке php используется другой php.ini из основного php-интерпретатора. Я использую Ubuntu 10.4. Моя проблема заключается в том, что в основном php.ini я включил дополнительный путь для внешней библиотеки, но в версии cli этого нет, и поэтому у меня есть ошибка включения пути.

Это также покажет все дополнительные файлы * .ini, загруженные (обычно зависающие в некоторых файлах conf.d в debian):

Файл конфигурации (php.ini) Путь: / etc / php5 / cli
Загруженный файл конфигурации: /etc/php5/cli/php.ini
Сканировать дополнительные .ini-файлы в: /etc/php5/cli/conf.d
Дополнительные .ini-файлы проанализированы: /etc/php5/cli/conf.d/apc.ini,
/etc/php5/cli/conf.d/curl.ini,
/etc/php5/cli/conf.d/gd.ini,
/etc/php5/cli/conf.d/geoip.ini,
/etc/php5/cli/conf.d/imagick.ini,
/etc/php5/cli/conf.d/imap.ini,
/etc/php5/cli/conf.d/ldap.ini,
/etc/php5/cli/conf.d/memcache.ini,
/etc/php5/cli/conf.d/memcached.ini,
/etc/php5/cli/conf.d/ming.ini,
/etc/php5/cli/conf.d/mysql.ini,
/etc/php5/cli/conf.d/mysqli.ini,
/etc/php5/cli/conf.d/pdo.ini,
/etc/php5/cli/conf.d/pdo_mysql.ini,
/etc/php5/cli/conf.d/pdo_sqlite.ini,
/etc/php5/cli/conf.d/snmp.ini,
/etc/php5/cli/conf.d/sqlite.ini,
/etc/php5/cli/conf.d/sqlite3.ini,
/etc/php5/cli/conf.d/suhosin.ini,
/etc/php5/cli/conf.d/tidy.ini,
/etc/php5/cli/conf.d/xdebug.ini,
/etc/php5/cli/conf.d/xsl.ini

Обратите внимание, что это было о php-cli, php-cgi не имеет этого афаика.

На моей последней работе у меня появилась привычка указывать мой файл ini при каждом выполнении …

C:\php\cli\php.exe -c C:\php\php.ini myscript.php 

Вы можете найти php.ini, используя следующую команду. в LINUX

Интересным в окнах является то, что в обоих тестах (в apache с phpinfo () и в cli с php -ini) путь к файлу конфигурации – c: \ windows. Больше информации здесь

У меня такая же проблема. Просто проверьте владельца и разрешения от всех файлов в файле /etc/php5/conf.d/. Он должен принадлежать root и доступен любому человеку.

Источник

Оцените статью