Maison  >  Article  >  développement back-end  >  Que faire si l'extension php ne prend pas effet

Que faire si l'extension php ne prend pas effet

藏色散人
藏色散人original
2021-11-01 10:01:442521parcourir

Les solutions pour l'extension php ne prennent pas effet : 1. Spécifiez le fichier php.ini pour démarrer le service php-fpm ; 2. Modifiez le chemin du fichier php.ini ; 3. Redémarrez le service php-fpm.

Que faire si l'extension php ne prend pas effet

L'environnement d'exploitation de cet article : système Windows 7, PHP version 7.1, ordinateur DELL G3

Que dois-je faire si l'extension php ne prend pas effet ?

Solution au problème selon lequel l'installation de l'extension PHP ne prend pas effet

Après que PHP ait installé le module d'extension, la raison et la solution ne prennent pas effet après le redémarrage

Dans l'environnement d'exploitation et de maintenance de lnmp, nous rencontrons souvent cela certains modules d'extension dont dépend PHP ne sont pas installés, ce qui nécessite l'ajout ultérieur de ces modules d'extension. Une fois les extensions installées et configurées, vous constaterez souvent qu'après le redémarrage du service php-fpm, ces extensions ne sont pas réellement chargées ! Voici un exemple pour illustrer :

Exemple d'environnement :

Chemin de stockage du package d'installation php : /data/software/php-5.6.10.tar.gz

Répertoire d'installation php : /data/php

[root@zabbix ~]# ll /data/software/php-5.6.10.tar.gz
-rw-r--r-- 1 root root 18306403 6月 11 2015 /data/software/php-5.6.10.tar.gz
[root@zabbix ~]# ll -d /data/software/php-5.6.10
drwxr-xr-x 17 www www 4096 10月 13 19:38 /data/software/php-5.6.10
[root@zabbix ~]# ls /data/php/
bin etc include lib php sbin var

En utilisant la commande php -m, on constate que bcmath et gettest extension

[root@zabbix ~]# vim /etc/profile
export PATH=$PATH:/data/php/bin
[root@zabbix ~]# source /etc/profile
[root@zabbix ~]# php -m|grep bcmath
[root@zabbix ~]# php -m|grep gettext
[root@zabbix ~]#

Maintenant, commencez à installer bcmatn et gettest extension

Installez l'extension bcmath

[root@zabbix ~]# cd /data/software/php-5.6.10/ext/bcmath/
[root@zabbix bcmath]# /data/php/bin/phpize
[root@zabbix bcmath]# ./configure --with-php-config=/data/php/bin/php-config
[root@zabbix bcmath]# make && make
.......

Un répertoire vous sera indiqué après une compilation réussie

Installing shared extensions:   /data/php/lib/php/extensions/no-debug-non-zts-20131226

Installez l'extension gettext

[root@zabbix ~]# cd /data/software/php-5.6.10/ext/gettext/
[root@zabbix gettext]# /data/php/bin/phpize
[root@zabbix gettext]# ./configure --with-php-config=/data/php/bin/php-config
[root@zabbix gettext]# make && make
.......

Vous le ferez être informé après une compilation réussie Vous avez un répertoire

Installing shared extensions:   /data/php/lib/php/extensions/no-debug-non-zts-20131226
[root@zabbix ~]# ll /data/php/lib/php/extensions/no-debug-non-zts-20131226

Utilisation totale 2336

-rwxr-xr-x 1 root root 380152 10月 13 23:03 bcmath.so
-rwxr-xr-x 1 root root  50376 10月 13 23:31 gettext.so

Configurer php.ini

[root@zabbix ~]# vim /data/php/etc/php.ini
.........
extension_dir = "/data/php/lib/php/extensions/no-debug-non-zts-20131226"
extension=bcmath.so
extension=gettext.so

Redémarrer php-fpm

[root@zabbix ~]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done

Et puis vérifier à nouveau si les extensions bcmath et gettext ont pris effet après leur installation ?

[root@zabbix ~]# php -m|grep bcmath
[root@zabbix ~]# php -m|grep gettext
[root@zabbix ~]#

J'ai trouvé que ça ne fonctionnait pas ! pourquoi! ?

C'est parce que php.ini n'a pas été spécifié au démarrage de php-fpm, donc il n'a jamais pris effet !

[root@zabbix etc]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@zabbix etc]# ps -ef|grep php-fpm
root   19529   1 0 23:37 ?    00:00:00 php-fpm: master process (/data/php/etc/php-fpm.conf)
www   19530 19529 0 23:37 ?    00:00:00 php-fpm: pool www
www   19531 19529 0 23:37 ?    00:00:00 php-fpm: pool www
root   19533 17173 0 23:37 pts/4  00:00:00 grep --color=auto php-fpm

Solution :

1) Spécifiez le fichier php.ini pour démarrer le service php-fpm

[root@zabbix etc]# /etc/init.d/php-fpm stop
Gracefully shutting down php-fpm . done
[root@zabbix etc]# ps -ef|grep php-fpm
root   19541 17173 0 23:38 pts/4  00:00:00 grep --color=auto php-fpm
[root@zabbix etc]# /data/php/sbin/php-fpm -y /data/php/etc/php-fpm.conf -c /data/php/etc/php.ini
[root@zabbix etc]# ps -ef|grep php-fpm
root   19543   1 0 23:38 ?    00:00:00 php-fpm: master process (/data/php/etc/php-fpm.conf)
www   19544 19543 0 23:38 ?    00:00:00 php-fpm: pool www
www   19545 19543 0 23:38 ?    00:00:00 php-fpm: pool www
root   19547 17173 0 23:39 pts/4  00:00:00 grep --color=auto php-fpm

2) Si l'extension php installée ne prend toujours pas effet après avoir démarré ci-dessus ! Alors il se peut que le fichier php.ini ne soit pas placé dans le bon chemin (ici j'agrandis directement le répertoire etc de php)

[root@zabbix ~]# ll /data/php/etc/php.ini
-rw-r--r-- 1 root root 73243 10月 13 23:32 /data/php/etc/php.ini
[root@zabbix ~]# cp /data/php/etc/php.ini /data/php/lib/
[root@zabbix ~]# ll /data/php/lib/php.ini
-rw-r--r-- 1 root root 73243 10月 13 23:35 /data/php/lib/php.ini

Redémarrez ensuite le service php-fpm !

[root@zabbix ~]# /etc/init.d/php-fpm restart
Gracefully shutting down php-fpm . done
Starting php-fpm done
[root@zabbix ~]# ps -ef|grep php
root   19564   1 0 23:43 ?    00:00:00 php-fpm: master process (/data/php/etc/php-fpm.conf)
www   19565 19564 0 23:43 ?    00:00:00 php-fpm: pool www
www   19566 19564 0 23:43 ?    00:00:00 php-fpm: pool www
root   19568 17173 0 23:43 pts/4  00:00:00 grep --color=auto php
[root@zabbix ~]#

Enfin, vérifiez à nouveau si les extensions bcmath et gettext ont pris effet ?

[root@zabbix ~]# php -m|grep bcmath
bcmath
[root@zabbix ~]# php -m|grep gettext
gettext
[root@zabbix ~]#

Apprentissage recommandé : "Tutoriel vidéo PHP"

Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn