PHP related configuration, PHP dynamic extension module

不言
Release: 2023-03-24 06:40:02
Original
2171 people have browsed it

The content introduced in this article is about PHP related configuration, PHP dynamic expansion module, which has certain reference value. Now I share it with you. Friends in need can refer to it

PHP related configuration


Check the location of the PHP configuration file

[root@shuai-01 111.com]# /usr/local/php/bin/php -i
Copy after login

Or use the phpinfo function to find it (accessed through a browser) (recommended)

[root@shuai-01 111.com]# vim index.php

<?php
phpinfo();
?>
Copy after login

This When you access it with a browser, everything will come out

PHP related configuration, PHP dynamic extension module
The directory where the configuration file is located, load the configuration file
PHP related configuration, PHP dynamic extension module
If the configuration file is not loaded, go to the source code package configuration file Copy the configuration file here

[root@abc php-5.6.30]# cp /usr/local/src/php-5.6.30/php.ini-development /usr/local/php/etc/php.ini

重新加载配置文件
[root@abc php-5.6.30]# /usr/local/apache2.4/bin/apachectl graceful
Copy after login

There are two configuration files here (one for development and one for production environment)

Modify the PHP configuration file:

vim  /usr/local/php/etc/php.ini
Copy after login

Dangerous function: (It also includes phpinfo. phpinfo will display all your information, which is very dangerous)

eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close
Copy after login

For dangerous functions, we can disable it.
Disable functions:
Search disable_functions

Add disabled functions

disable_functions =eval,assert,popen,passthru,escapeshellarg,escapeshellcmd,passthru,exec,system,chroot ,scandir,chgrp,chown,escapeshellcmd,escapeshellarg,shell_exec,proc_get_status,ini_alter,ini_restore,dl,pfsockopen,openlog,syslog,readlink,symlink,leak,popepassthru,stream_socket_server,popen,proc_open,proc_close,phpinfo

Test at this time:

Visit 111.com/index.php


PHP dynamic extension module

When there is a business need To use modules that are not installed when PHP is compiled and installed, you can use dynamic expansion to install the required modules.

现在介绍一下redis的安装,redis是一个nosql,在LAMP架构下一般把它当做缓存来使用。

要安装redis模块就要先下载redis这个包

下载地址:
https://codeload.github.com/phpredis/phpredis/zip/develop

[root@shuai-01 src]# wget https://codeload.github.com/phpredis/phpredis/zip/develop
Copy after login

改名为phpredis-develop.zip:

[root@shuai-01 src]# mv develop phpredis-develop.zip
Copy after login

解压这个包:

[root@shuai-01 src]# unzip phpredis-develop.zip
Copy after login

到phpredis-develo目录下进行编译安装:

[root@shuai-01 src]# cd phpredis-develop
[root@shuai-01 phpredis-develop]# ls
arrays.markdown    ISSUE_TEMPLATE.md   redis_array_impl.h
cluster_library.c  liblzf              redis.c
cluster_library.h  library.c           redis_cluster.c
cluster.markdown   library.h           redis_cluster.h
common.h           mkdeb-apache2.sh    redis_commands.c
config.m4          mkdeb.sh            redis_commands.h
config.w32         package.xml         redis_session.c
COPYING            php_redis.h         redis_session.h
crc16.h            README.markdown     rpm
CREDITS            redis_array.c       serialize.list
debian             redis_array.h       tests
debian.control     redis_array_impl.c
Copy after login

编译安装是要有configure文件的,这个没有,就要先生成configure文件:
生成configure文件:

[root@shuai-01 phpredis-develop]#  /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
[root@shuai-01 phpredis-develop]# ls
acinclude.m4       crc16.h            README.markdown
aclocal.m4         CREDITS            redis_array.c
arrays.markdown    debian             redis_array.h
autom4te.cache     debian.control     redis_array_impl.c
build              install-sh         redis_array_impl.h
cluster_library.c  ISSUE_TEMPLATE.md  redis.c
cluster_library.h  liblzf             redis_cluster.c
cluster.markdown   library.c          redis_cluster.h
common.h           library.h          redis_commands.c
config.guess       ltmain.sh          redis_commands.h
config.h.in        Makefile.global    redis_session.c
config.m4          missing            redis_session.h
config.sub         mkdeb-apache2.sh   rpm
configure          mkdeb.sh           run-tests.php
configure.in       mkinstalldirs      serialize.list
config.w32         package.xml        tests
COPYING            php_redis.h
Copy after login

编译:

[root@shuai-01 phpredis-develop]# ./configure --with-php-config=/usr/local/php/bin/php-config

[root@shuai-01 phpredis-develop]# echo $?
0
Copy after login

make:

[root@shuai-01 phpredis-develop]# make
[root@shuai-01 phpredis-develop]# echo $?
0
Copy after login

make install:

[root@shuai-01 phpredis-develop]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
[root@shuai-01 phpredis-develop]# echo $?
0
Copy after login

查看有没有生成redis.so文件:

[root@shuai-01 phpredis-develop]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
opcache.so  redis.so
Copy after login

这个时候PHP还是不支持的

[root@shuai-01 phpredis-develop]# /usr/local/php/bin/php -m |grep redis
[root@shuai-01 phpredis-develop]#
Copy after login

通过编辑配置文件在PHP中加载redis

先找扩展模块的目录路径:

[root@shuai-01 phpredis-develop]# /usr/local/php/bin/php -i |grep -i extension_dir
extension_dir => /usr/local/php/lib/php/extensions/no-debug-zts-20131226 => /usr/local/php/lib/php/extensions/no-debug-zts-20131226
sqlite3.extension_dir => no value => no value
Copy after login

发现在/usr/local/php/lib/php/extensions/no-debug-zts-20131226

这个extension_dir是可以自定义路径的,不过一般不会去定义它,安装的扩展模块会默认放在个目录下

编辑php.ini:

[root@shuai-01 phpredis-develop]# vim /usr/local/php/etc/php.ini
Copy after login

将redis.so文件加入进去

;extension=php_xmlrpc.dll
;extension=php_xsl.dll
extension=redis.so
Copy after login

保存退出

这时就加载了:

[root@shuai-01 phpredis-develop]# /usr/local/php/bin/php -m |grep redis
redis
Copy after login

问题1:
生成configure文件时出现:

[root@shuai-01 phpredis-develop]#  /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
Copy after login

少了autoconf这个包
安装:

[root@shuai-01 phpredis-develop]# yum install -y autoconf
Copy after login

安装完了之后再生成文件。

有些第三方扩展模块是要通过下载源码包来安装,有些模块是PHP源码包中自带的(在ext目录下)。

[root@shuai-01 php-5.6.30]# cd ext/
[root@shuai-01 ext]# ls
bcmath              ftp        mysqli        pgsql       standard
bz2                 gd         mysqlnd       phar        sybase_ct
calendar            gettext    oci8          posix       sysvmsg
com_dotnet          gmp        odbc          pspell      sysvsem
ctype               hash       opcache       readline    sysvshm
curl                iconv      openssl       recode      tidy
date                imap       pcntl         reflection  tokenizer
dba                 interbase  pcre          session     wddx
dom                 intl       pdo           shmop       xml
enchant             json       pdo_dblib     simplexml   xmlreader
ereg                ldap       pdo_firebird  skeleton    xmlrpc
exif                libxml     pdo_mysql     snmp        xmlwriter
ext_skel            mbstring   pdo_oci       soap        xsl
ext_skel_win32.php  mcrypt     pdo_odbc      sockets     zip
fileinfo            mssql      pdo_pgsql     spl         zlib
filter              mysql      pdo_sqlite    sqlite3
Copy after login

如果想安装里面的模块,直接进入模块目录下,执行phpize进行生成configure文件。

例如我现在要安装zip模块:

进入zip目录:

[root@shuai-01 ext]# cd zip/
[root@shuai-01 zip]# ls
config.m4   CREDITS   lib             php_zip.c  tests  zip_stream.c
config.w32  examples  LICENSE_libzip  php_zip.h  TODO
Copy after login

生成configure文件:

[root@shuai-01 zip]# /usr/local/php/bin/phpize
Configuring for:
PHP Api Version:         20131106
Zend Module Api No:      20131226
Zend Extension Api No:   220131226
Copy after login

编译安装:

[root@shuai-01 zip]# ./configure --with-php-config=/usr/local/php/bin/php-config
[root@shuai-01 zip]# echo $?
0
Copy after login

make:

[root@shuai-01 zip]# make
[root@shuai-01 zip]# echo $?
0
Copy after login

make install:

[root@shuai-01 zip]# make install
Installing shared extensions:     /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
Copy after login

查看有没有生成redis.so文件

[root@shuai-01 zip]# ls /usr/local/php/lib/php/extensions/no-debug-zts-20131226/
opcache.so  redis.so  zip.so
Copy after login

这个时候PHP还是不支持的

[root@shuai-01 zip]# /usr/local/php/bin/php -m |grep zip
[root@shuai-01 zip]#
Copy after login

编辑php.ini:

[root@shuai-01 phpredis-develop]# vim /usr/local/php/etc/php.ini
Copy after login

将zip.so文件加入进去

;extension=php_xsl.dll
extension=redis.so
extension=zip.so
Copy after login

保存退出

这时就加载了:

[root@shuai-01 zip]# /usr/local/php/bin/php -m |grep zip
zip
Copy after login

扩展 
apache rewrite教程 http://coffeelet.blog.163.com/blog/static/13515745320115842755199/ http://www.cnblogs.com/top5/archive/2009/08/12/1544098.html 
apache rewrite 出现死循环 http://ask.apelearn.com/question/1043 
php错误日志级别参考 http://ask.apelearn.com/question/6973 
php开启短标签 http://ask.apelearn.com/question/120 
php.ini详解 http://legolas.blog.51cto.com/2682485/493917

相关推荐:

基础 php相关函数

php相关问题总结


The above is the detailed content of PHP related configuration, PHP dynamic extension module. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template