search
HomeBackend DevelopmentPHP TutorialPHP related configuration, PHP dynamic extension 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

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

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

<?php
phpinfo();
?>

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

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

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

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

改名为phpredis-develop.zip:

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

解压这个包:

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

到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

编译安装是要有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

编译:

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

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

make:

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

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

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

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

这个时候PHP还是不支持的

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

通过编辑配置文件在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

发现在/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

将redis.so文件加入进去

;extension=php_xmlrpc.dll
;extension=php_xsl.dll
extension=redis.so

保存退出

这时就加载了:

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

问题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.

少了autoconf这个包 
安装:

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

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

有些第三方扩展模块是要通过下载源码包来安装,有些模块是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

如果想安装里面的模块,直接进入模块目录下,执行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

生成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

编译安装:

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

make:

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

make install:

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

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

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

这个时候PHP还是不支持的

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

编辑php.ini:

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

将zip.so文件加入进去

;extension=php_xsl.dll
extension=redis.so
extension=zip.so

保存退出

这时就加载了:

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

扩展 
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
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
PHP's Purpose: Building Dynamic WebsitesPHP's Purpose: Building Dynamic WebsitesApr 15, 2025 am 12:18 AM

PHP is used to build dynamic websites, and its core functions include: 1. Generate dynamic content and generate web pages in real time by connecting with the database; 2. Process user interaction and form submissions, verify inputs and respond to operations; 3. Manage sessions and user authentication to provide a personalized experience; 4. Optimize performance and follow best practices to improve website efficiency and security.

PHP: Handling Databases and Server-Side LogicPHP: Handling Databases and Server-Side LogicApr 15, 2025 am 12:15 AM

PHP uses MySQLi and PDO extensions to interact in database operations and server-side logic processing, and processes server-side logic through functions such as session management. 1) Use MySQLi or PDO to connect to the database and execute SQL queries. 2) Handle HTTP requests and user status through session management and other functions. 3) Use transactions to ensure the atomicity of database operations. 4) Prevent SQL injection, use exception handling and closing connections for debugging. 5) Optimize performance through indexing and cache, write highly readable code and perform error handling.

How do you prevent SQL Injection in PHP? (Prepared statements, PDO)How do you prevent SQL Injection in PHP? (Prepared statements, PDO)Apr 15, 2025 am 12:15 AM

Using preprocessing statements and PDO in PHP can effectively prevent SQL injection attacks. 1) Use PDO to connect to the database and set the error mode. 2) Create preprocessing statements through the prepare method and pass data using placeholders and execute methods. 3) Process query results and ensure the security and performance of the code.

PHP and Python: Code Examples and ComparisonPHP and Python: Code Examples and ComparisonApr 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.

PHP in Action: Real-World Examples and ApplicationsPHP in Action: Real-World Examples and ApplicationsApr 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.

PHP: Creating Interactive Web Content with EasePHP: Creating Interactive Web Content with EaseApr 14, 2025 am 12:15 AM

PHP makes it easy to create interactive web content. 1) Dynamically generate content by embedding HTML and display it in real time based on user input or database data. 2) Process form submission and generate dynamic output to ensure that htmlspecialchars is used to prevent XSS. 3) Use MySQL to create a user registration system, and use password_hash and preprocessing statements to enhance security. Mastering these techniques will improve the efficiency of web development.

PHP and Python: Comparing Two Popular Programming LanguagesPHP and Python: Comparing Two Popular Programming LanguagesApr 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.

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.

See all articles

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.