Hoe kan ik het php.ini-bestand vinden dat door de opdrachtregel wordt gebruikt?

Ik moet pdo_mysqlinschakelen in mijn EasyPHP-omgeving, dus ik ging naar het bestand php.inien maakte de volgende regel ongedaan:

extension=php_pdo_mysql.dll

Helaas heb ik nog steeds hetzelfde probleem.
Ik gebruik de CLI, dus ik veronderstel dat ik het php.ini-bestand moet vinden dat door de CLI wordt gebruikt. Hoe kan ik het vinden?


Antwoord 1, autoriteit 100%

Voer gewoon php --iniuit en zoek naar Geladen configuratiebestandin de uitvoer voor de locatie van php.inidie door uw CLI wordt gebruikt .


Antwoord 2, autoriteit 36%

Je kunt een volledige phpinfo()krijgen met:

php -i

En daarin is het php.ini-bestand dat wordt gebruikt:

$ php -i | grep 'Configuration File'
Configuration File (php.ini) Path => /etc
Loaded Configuration File => /etc/php.ini

Gebruik in Windows findin plaats daarvan:

php -i | find/i"configuration file"

Antwoord 3, autoriteit 2%

Je kunt daarvoor get_cfg_var(‘cfg_file_path’)gebruiken:

Controleer of het systeem een ​​configuratiebestand gebruikt, probeer de waarde van de CFG_FILE_PATH-configuratie-instelling op te halen. Als dit beschikbaar is, wordt een configuratiebestand gebruikt.

In tegenstelling tot phpinfo () zal het zeggen of het helemaal geen PHP.INI vond / gebruik.

var_dump( get_cfg_var('cfg_file_path') );

en je kunt eenvoudig set de locatie van de php.ini . U gebruikt de opdrachtregelversie, dus met behulp van de -cParameter U kunt de locatie opgeven voor deze specifieke run, b.g.

php -c /home/me/php.ini -f /home/me/test.php

4

Voer php --iniin uw terminal uit en u krijgt alle details over INI-bestanden:

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

Gebruik voor meer help-commando php --help. Het zal alle mogelijke opties weergeven.


5

Soms zijn dingen niet altijd zoals ze lijken wanneer ze in het algemeen naar configuratiebestanden komen. Dus hier moet ik mijn gebruikelijke methoden toepassen voor het verkennen van welke bestanden worden geopend door een proces.

Ik gebruik een zeer krachtig en nuttig commandelijnprogramma genaamd strace om me te laten zien wat er is echt achter mijn rug gaan!

$ strace -o strace.log php --version
$ grep php.ini strace.log

Strace Digs Out Out Kernel (System) roept dat uw programma de uitvoer in het bestand is opgegeven en dumpt in het bestand dat is opgegeven door -o.

Het is eenvoudig te gebruiken grep om te zoeken naar voorkomen van bestand php.ini in dit logboek. Het is behoorlijk voor de hand liggend naar het volgende typische antwoord om te zien wat er aan de hand is.

open("/usr/bin/php.ini", O_RDONLY)      = -1 ENOENT (No such file or directory)
open("/etc/php.ini", O_RDONLY)          = 3
lstat("/etc/php.ini", {st_mode=S_IFREG|0644, st_size=69105, ...}) = 0

6

Als u wilt dat alle geladen configuratiebestanden, wordt dit u verteld:

php -i | grep "\.ini"

Sommige systemen laden dingen uit meer dan één INI-bestand. Op mijn Ubuntu-systeem ziet het er als volgt uit:

$  php -i | grep "\.ini"
Configuration File (php.ini) Path => /etc/php5/cli
Loaded Configuration File => /etc/php5/cli/php.ini
Scan this dir for additional .ini files => /etc/php5/cli/conf.d
additional .ini files parsed => /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/mcrypt.ini,
/etc/php5/cli/conf.d/memcache.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

Antwoord 7

Op OS X v10.9(Mavericks), actief:

$ php -i | grep 'Configuration File'

Geretourneerd:

Configuration File (php.ini) Path => /etc
Loaded Configuration File:         (none)

In de directory /etc/stond:

php.ini.default

(evenals php-fpm.conf.default)

Ik kon php.ini.defaultkopiëren naar php.ini, date.timezone = "US/Central"toevoegen aan bovenaan (rechts onder [php]), en het probleem is opgelost.

(De foutmelding is in ieder geval verdwenen.)


Antwoord 8

Als u het aan een andere app moet doorgeven, kunt u zoiets doen als:

php --ini | grep Loaded | cut -d" " -f12

retourneert alleen het pad. php -c $(php --ini | grep Loaded | cut -d" " -f12)wordt doorgegeven in het configuratiebestand (handig voor fpm)


Antwoord 9

Van wat ik me herinner toen ik EasyPHP gebruikte, bevindt het php.ini-bestand zich in C:\Windows\of C:\Windows\System32


Antwoord 10

Doe

find / -type f -name "php.ini" 

Hiermee wordt alle bestanden uitgevoerd met de naam php.ini.

Zoek uit welke u gebruikt, meestal apache2/php.ini


11

De eenvoudigste manier is tegenwoordig om PHP-configuratie te gebruiken:

# php-config --ini-dir
/usr/local/etc/php/7.4/conf.d

Er vind je er meer. Voorbeelduitgang van de --helpSubopdracht (MacOS Local Install):

# php-config --help
Usage: /usr/local/bin/php-config [OPTION]
Options:
  --prefixUsage: /usr/local/bin/php-config [OPTION]
Options:
  --prefix            [/usr/local/Cellar/php/7.4.11]
  --includes          [-I/usr/local/Cellar/php/7.4.11/include/php - …ETC…]
  --ldflags           [ -L/usr/local/Cellar/krb5/1.18.2/lib -…ETC…]
  --libs              [ -ltidy -largon2 …ETC… ]
  --extension-dir     [/usr/local/Cellar/php/7.4.11/pecl/20190902]
  --include-dir       [/usr/local/Cellar/php/7.4.11/include/php]
  --man-dir           [/usr/local/Cellar/php/7.4.11/share/man]
  --php-binary        [/usr/local/Cellar/php/7.4.11/bin/php]
  --php-sapis         [ apache2handler cli fpm phpdbg cgi]
  --ini-path          [/usr/local/etc/php/7.4]
  --ini-dir           [/usr/local/etc/php/7.4/conf.d]
  --configure-options [--prefix=/usr/local/Cellar/php/7.4.11 --…ETC…]
  --version           [7.4.11]
  --vernum            [70411]

12

Opslaan CLI PHPINFO-uitvoer in het lokale bestand:

php -i >> phpinfo-cli.txt

13

In uw PHP.INI -bestand, zet u uw extension directory, b.v:

extension_dir = "C:/php/ext/"

U ziet in uw PHP-map Er is een map ext met alle DLL-bestanden en extensies.


14

In Docker Container PHPMYADMIN / PHPMYADMIN geen PHP.INI-bestand. Maar er zijn twee bestanden:
php.ini-debug en php.ini-productie

Hernoem het probleem om het probleem op te lossen, de naam van een van de bestanden naar Php.ini en herstart Docker Container.

Other episodes