- Настройка параметров PHP (Debian / Ubuntu)
- Создание phpinfo-скрипта
- Настройка параметров
- How to find the php.ini file used by the command line?
- What is php.ini
- Where is php.ini file located by default
- How can I find the php.ini file from command line
- php –ini
- Where is my PHP php.ini Configuration File Located?
- Method 1
- Method 2
- CLI
- Apache
- Nginx or Apache with PHP-FPM
- Method 3
- Editing php.ini in Linux
- Apache
- Nginx or Apache with PHP-FPM
- Older Versions
- No replies yet
- 2 replies
- Leave a reply Cancel reply
- Where is php.ini Configuration File in Ubuntu
- Where is php.ini Configuration File in Ubuntu
- Method 1: Through Browser
- Method 2: Through Terminal
- Conclusion
- About the author
- Awais Khan
Настройка параметров PHP (Debian / Ubuntu)
В статье описана настройка параметров PHP на сервере с операционными системами Ubuntu или Debian.
Настройка параметров производится в конфигурационном файле php.ini .
В зависимости от того, как используется PHP на сервере, эти файлы обычно размещаются по следующим путям:
# Если PHP работает как модуль Apache:/etc/php/x.x/apache2/php.ini
# Если PHP работает в режиме FastCGI:
/etc/php/x.x/cgi/php.ini
# Настройки PHP в командной строке:/etc/php/x.x/cli/php.ini
# где x.x — соответствующая версия обработчика php
Определить точное расположение файла php.ini можно с помощью скрипта phpinfo.php .
Создание phpinfo-скрипта
Подключитесь к серверу по 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 :
Настройка параметров
Рассмотрим настройку на примере параметра mbstring.func_overload .
1. Найдите нужный параметр в php.ini при помощи команды:
grep -ni 'имя_параметра' /путь/до/php.ini
grep -ni 'mbstring.func_overload' /etc/php/7.2/apache2/php.ini
Ключ -n покажет, в какой строке расположена директива, чтобы можно было перейти сразу к ней.
В данном случае номер строки — 1704.
2. Откройте файл в текстовом редакторе, указав номер нужной строки:
nano +номер_строки путь/до/php.ini
nano +1704 /etc/php/7.2/apache2/php.ini
3. Отредактируйте строку: уберите знак комментария ( ; ) и измените значение на нужное вам:
В данном случае мы указываем 2:
4. Сохраните изменения: нажмите Ctrl+x для выхода из nano , далее Y для сохранения изменений и Enter.
5. Перезапустите веб-сервер Apache командой:
How to find the php.ini file used by the command line?
There are a few ways to locate php.ini file by command line on Linux Ubuntu, Linux Mint, and other Linux distributions. Some of the options showed here are also compatible with Windows, specially usin WSL.
What is php.ini
The php.ini file is the configuration file that is read when PHP starts up. For the server module versions of PHP, this happens only once when the web server is started. For the CGI and CLI versions, it happens on every invocation.
It is the main place where you declare changes to your PHP settings. The server is already configured with standard settings for PHP, which your site or application will use by default. Unless you need to change one or more settings, there is no need to create or modify a php.ini file.
Where is php.ini file located by default
The php.ini file is searched for in these locations (in order):
- SAPI module specific location (PHPIniDir directive in Apache 2, -c command line option in CGI and CLI)
- The PHPRC environment variable.
- The location of the php.ini file can be set for different versions of PHP. The root of the registry keys depends on 32- or 64-bitness of the installed OS and PHP. For 32-bit PHP on a 32-bit OS or a 64-bit PHP on a 64-bit OS use [(HKEY_LOCAL_MACHINE\SOFTWARE\PHP] for 32-bit version of PHP on a 64-bit OS use [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP]] instead. For same bitness installation the following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y.z], [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\PHP\x], where x, y and z mean the PHP major, minor and release versions. For 32 bit versions of PHP on a 64 bit OS the following registry keys are examined in order: [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y.z], [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x.y] and [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6421Node\PHP\x], where x, y and z mean the PHP major, minor and release versions. If there is a value for IniFilePath in any of these keys, the first one found will be used as the location of the php.ini (Windows only).
- [HKEY_LOCAL_MACHINE\SOFTWARE\PHP] or [HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\PHP], value of IniFilePath (Windows only).
- Current working directory (except CLI).
- The web server’s directory (for SAPI modules), or directory of PHP (otherwise in Windows).
- Windows directory (C:\windows or C:\winnt) (for Windows), or –with-config-file-path compile time option.
If php-SAPI.ini exists (where SAPI is the SAPI in use, so, for example, php-cli.ini or php-apache.ini ), it is used instead of php.ini . The SAPI name can be determined with php_sapi_name() (returns the type of interface between web server and PHP).
The Apache web server changes the directory to root at startup, causing PHP to attempt to read php.ini from the root filesystem if it exists.
How can I find the php.ini file from command line
php –ini
There is a simple option called —ini that you can use when run php command:
The output will show where is the php.ini used by command line, as well additional scanned configuration files:
Using php-config you can list only the path where the main PHP configuration file is located:
The output is something like:
The command php -i shows a complete phpinfo() result. You can find all configurations and apply grep command to filter only the .ini configuration file:
Or in Windows you can use find instead:
The result to both command will be similar to:
Finally you can use grep to filter all lines of the phpinfo() that shows .ini :
The output will be similar to php -i command:
There are several ways to find php.ini file and other configurations files of your PHP installation using native commands on terminal.
Where is my PHP php.ini Configuration File Located?
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 php.ini Configuration File in Ubuntu
php.ini is the default configuration file for the PHP programming language. It makes it easy for users to run PHP applications and you can use the file to customize the PHP environment too according to your choice. This file also includes some derivatives that help you control various aspects of PHP, such as memory limit, file size, error reporting and much more.
If you are searching for the location of this file on the Ubuntu system, you can follow this guide to learn different ways to find the php.ini file location.
Where is php.ini Configuration File in Ubuntu
There are multiple ways to find the location of php.ini configuration file in Ubuntu:
Method 1: Through Browser
To find php.ini configuration file via the browser on Ubuntu, follow the below-given steps:
Step 1: First create a phpinfo.php file in the default HTML root folder on Ubuntu system from the following command:
Step 2: Inside the file, add the following PHP code.
// Show All PHP Information
phpinfo ( ) ;
Step 3: Now, head towards your system browser and enter the address http://127.0.0.1/phpinfo.php.
Method 2: Through Terminal
There are some useful terminal methods that will make it easier for you to find the php.ini configuration file in the Ubuntu system.
The first one is running the following command on the terminal to find the location of php.ini configuration file:
To get only the location of the php.ini file on Ubuntu system, you can use the following modified command:
You can also run the PHP interactive shell to find the location of the php.ini file. For that purpose, first open the PHP interactive shell from the following command:
Then execute the following command to get the location of the php.ini configuration file on the Ubuntu system.
Conclusion
php.ini is the PHP configuration file that you can utilize to run PHP applications on the system. You can find the location of this file on the Ubuntu system by creating a .php file, inserting a PHP code inside it and access it on the browser. Alternatively, the Ubuntu users can also find php.ini file location from the php –ini command on the interactive shell using phpinfo(); command.
About the author
Awais Khan
I’m an Engineer and an academic researcher by profession. My interest for Raspberry Pi, embedded systems and blogging has brought me here to share my knowledge with others.