Table of Contents
PHP related configuration
PHP dynamic extension module
Home Backend Development PHP Tutorial PHP related configuration, PHP dynamic extension module

PHP related configuration, PHP dynamic extension module

Apr 16, 2018 pm 04:26 PM
php Expand module

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


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
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
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!

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1669
14
PHP Tutorial
1273
29
C# Tutorial
1256
24
PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP in Action: Real-World Examples and Applications PHP in Action: Real-World Examples and Applications Apr 14, 2025 am 12:19 AM

PHP is widely used in e-commerce, content management systems and API development. 1) E-commerce: used for shopping cart function and payment processing. 2) Content management system: used for dynamic content generation and user management. 3) API development: used for RESTful API development and API security. Through performance optimization and best practices, the efficiency and maintainability of PHP applications are improved.

The Enduring Relevance of PHP: Is It Still Alive? The Enduring Relevance of PHP: Is It Still Alive? Apr 14, 2025 am 12:12 AM

PHP is still dynamic and still occupies an important position in the field of modern programming. 1) PHP's simplicity and powerful community support make it widely used in web development; 2) Its flexibility and stability make it outstanding in handling web forms, database operations and file processing; 3) PHP is constantly evolving and optimizing, suitable for beginners and experienced developers.

PHP and Python: Different Paradigms Explained PHP and Python: Different Paradigms Explained Apr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP vs. Other Languages: A Comparison PHP vs. Other Languages: A Comparison Apr 13, 2025 am 12:19 AM

PHP is suitable for web development, especially in rapid development and processing dynamic content, but is not good at data science and enterprise-level applications. Compared with Python, PHP has more advantages in web development, but is not as good as Python in the field of data science; compared with Java, PHP performs worse in enterprise-level applications, but is more flexible in web development; compared with JavaScript, PHP is more concise in back-end development, but is not as good as JavaScript in front-end development.

PHP and Python: Code Examples and Comparison PHP and Python: Code Examples and Comparison Apr 15, 2025 am 12:07 AM

PHP and Python have their own advantages and disadvantages, and the choice depends on project needs and personal preferences. 1.PHP is suitable for rapid development and maintenance of large-scale web applications. 2. Python dominates the field of data science and machine learning.

See all articles