Home  >  Article  >  Backend Development  >  PHP compilation and installation Detailed explanation of each PHP compilation parameter configuration

PHP compilation and installation Detailed explanation of each PHP compilation parameter configuration

不言
不言Original
2018-04-03 11:19:353083browse

This article introduces the compilation and installation of PHP. The detailed configuration of each compilation parameter of PHP is shared with everyone now, and it can also be used as a reference for friends who need help.

  • Basic steps for php compilation and installation

//首先要下载一个php的安装包,例如:php-5.6.25.tar.gz,tar zxvf php-5.6.25.tar.gz   // 解压php安装包,得到一个php-5.6.25的文件夹cd php-5.6.25  ./configure           //对php的安装进行配置,后面要加配置选项# make && make install //编译安装完成之后,需要从解压后的文件夹中把php.ini-development //或是 php.ini-production 重命名成php.ini 复制到php安装文件中的相应位置,//可在phpinfo中查看 相应位置.//  把/usr/local/php/etc/php-fpm.conf.default  复制到当前文件夹下,保存未php-fpm.conf

The above are the basic steps for php compilation and installation Process, the following describes the configuration parameters of php in detail.


--prefix=/usr/local/php                      //指定 php 安装目录 --with-apxs2=/usr/local/apache/bin/apxs      //整合apache,
                        //apxs功能是使用mod_so中的LoadModule指令,
                       //加载指定模块到 apache,要求 apache 要打开SO模块--with-config-file-path=/usr/local/php/etc    //指定php.ini位置--with-MySQL=/usr/local/mysql                 //mysql安装目录,对mysql的支持--with-mysqli=/usr/local/mysql/bin/mysql_config                      //mysqli扩展技术不仅可以调用MySQL的存储过程、处理MySQL事务,
                      //而且还可以使访问数据库工作变得更加稳定。--enable-safe-mode    //打开安全模式 --enable-ftp          //打开ftp的支持 --enable-zip          //打开对zip的支持 --with-bz2            //打开对bz2文件的支持 --with-jpeg-dir       //打开对jpeg图片的支持 --with-png-dir        //打开对png图片的支持 --with-freetype-dir   //打开对freetype字体库的支持 --without-iconv       //关闭iconv函数,各种字符集间的转换 --with-libXML-dir     //打开libxml2库的支持 --with-XMLrpc         //打开xml-rpc的c语言 --with-zlib-dir       //打开zlib库的支持 --with-gd             //打开gd库的支持 --enable-gd-native-ttf //支持TrueType字符串函数库 --with-curl            //打开curl浏览工具的支持 --with-curlwrappers    //运用curl工具打开url流 --with-ttf             //打开freetype1.*的支持,可以不加了 --with-xsl             //打开XSLT 文件支持,扩展了libXML2库 ,需要libxslt软件 --with-gettext         //打开gnu 的gettext 支持,编码库用到 --with-pear            //打开pear命令的支持,PHP扩展用的 --enable-calendar      //打开日历扩展功能 --enable-mbstring      //多字节,字符串的支持 --enable-bcmath        //打开图片大小调整,用到zabbix监控的时候用到了这个模块--enable-sockets       //打开 sockets 支持--enable-exif          //图片的元数据支持 --enable-magic-quotes  //魔术引用的支持 --disable-rpath        //关闭额外的运行库文件 --disable-debug        //关闭调试模式 --with-mime-magic=/usr/share/file/magic.mime  //魔术头文件位置
  • CGI Parameters only used for installation:

--enable-fpm                 //打上PHP-fpm 补丁后才有这个参数,CGI方式安装的启动程序--enable-fastCGI             //支持fastcgi方式启动PHP--enable-force-CGI-redirect  //重定向方式启动PHP--with-ncurses         //支持ncurses 屏幕绘制以及基于文本终端的图形互动功能的动态库--enable-pcntl         //freeTDS需要用到的,可能是链接mssql 才用到--with-mcrypt          //mcrypt算法的扩展--with-mhash           //mhash算法的扩展//以上函数库需要安装--with-gmp                     //应该是支持一种规范--enable-inline-optimization   //优化线程--with-openssl                 //openssl的支持,加密传输时用到的--enable-dbase                 //建立DBA 作为共享模块--with-pcre-dir=/usr/local/bin/pcre-config       //perl的正则库案安装位置--disable-dmalloc
--with-gdbm            //dba的gdbm支持--enable-sigchild
--enable-sysvsem
--enable-sysvshm
--enable-zend-multibyte  //支持zend的多字节--enable-mbregex
--enable-wddx
--enable-shmop
--enable-soap

  • Notes

  • specified After setting --with-apxs2=/usr/local/apache/bin/apxs, do not activate --enable-fpm and --enable-fastCGI. apxs loads PHP in php module mode.

  • Mysql After compiling the Mysql development library, you do not need to specify the path to mysql.

  • PHP compilation has basic dependencies. To compile PHP, you first need to install the XML extension, because the php5 core has XML support turned on by default. Other basic libraries require the following: GD -> ; zlib, Png, Jpg, if you need to support others, you still need to compile the extension library according to the actual situation. The ttf library needs the support of the freetype library.

  • --enable-magic-quotes is an extremely not recommended parameter. Of course, if you need PHP to do the underlying work for you, in fact it is not very thorough. Solve the problem.

  • --with-openssl, requires openssl library. mysqli is the MySQL driver provided by the MySQL team and has many practical functions and typical features. However, it is not the best choice for MySQL on the PHP platform. PDO has been proven to be a simple, high-concurrency, and easy-to-create and recycle standard interface. However, PDO also experienced memory overflow problems before 5.3. After 5.3, when reading Oracle's LOB resources, if the memory is not restricted, memory overflow will still occur.
    If it is product mode, it is not recommended to use pear, shmop, ftp, etc. What they have to do is to use C/C++, Java, or even other scripting languages. There are good and fast options. No need to Limited to using PHP to implement. Unfamiliar class libraries and libraries that are not commonly used are not recommended. Magic-quote, session.auto_start, PHP server information, PHP error information, etc. should be closed as soon as possible after compilation is completed to avoid exposing server information.

    The Web Server mode corresponding to PHP only requires one of Module, fastcgi, and fpm. The server is not your experimental field. Fastcgi can choose Nginx and lighttpd. In fact, Nginx also uses lighttpd's spwan-fcgi for fcgi process management. fpm uses PHP itself to manage multiple processes, somewhat similar to a back-end proxy. Regardless of the mode, when releasing a product server, process and thread tuning should be done, and enough stress testing should be done to find the best combination of process numbers.

    Choose a PHP OPCode cache extension. This is also very important. Under Linux 2.6 core and fcgi, xcache has good practical experience. Others will have serious performance degradation after the number of concurrency increases.

    If you really want to experience it, you would rather compile several more PHP versions than collect various extensions for one version of PHP to adapt to various environments. This will put yourself in a dilemma.


  • Extensions that need to be installed separately

  • gd library.

  • ming extension.

  • Extensions for mhash and mcrypt.

Regarding the detailed options, in addition to the above installation introduction, other options can also be added during compilation.
apache module
Syntax: --with-apache=DIR
Description: Use this option to allow **PHP
** to be used as an apache module, DIR The string can be /usr/local/apache or other directory where apache is installed
Example: --with-apache=/var/lib/apache
fhttpd server module
Syntax: --with-fhttpd=DIR
Note: If you use fttpd server, you can use this command to compile PHP. Using modules to cooperate with the fttpd server can achieve better efficiency.
Adabas D database
Syntax: --with-adabas=DIR
Explanation: This option needs to be added when the database system is Adabas D database. For details about the Adabas D database, please refer to http://www.adabas.com.
Example: --with-adabas=/usr/local/adabasd
dBase data table
Syntax: --with-dbase
Explanation: Just add this option, no need For other parameters or function libraries, PHP will allow the system to access the dBase data table.
filePro database
Syntax: --with-filepro
Description: You can read the filePro database (read-only) without specifying the database path and other function libraries.
mSQL database
Syntax: --with-msql=DIR
Description: Provides access to mSQL database. For more details please refer to the mSQL website http://www.hughes.com.au.
Example: --with-msql=/usr/local/Hughes
MySQL database
Syntax: --with-mysql=DIR
Description: Provides access to MySQL database . For more details please refer to the MySQL website http://www.tcx.se.
Example: --with-mysql=/usr/local/mysql
iODBC database device
Syntax: --with-iodbc=DIR
Description: Provide ODBC database device , used to access the backend database. For more details please refer to the iODBC website http://www.iodbc.org.
Example: --with-iodbc=/usr/local/iodbc
OpenLink ODBC database device
Syntax: --with-openlink=DIR
Description: Use OpenLink ODBC Database device, used to access the back-end database. For more details please refer to the OpenLink ODBC website http://www.openlinksw.com.
Example: --with-openlink=/usr/local/openlink
Oracle database
Syntax: --with-oracle=DIR
Instructions: Use Oracle database. The Oracle version must be version 7.3 or above. You can also use the environment variable ORACLE_HOME in your PHP program to specify the path to Oracle. For more information about Oracle, please refer to Oracle's website http://www.oracle.com.
Example: --with-oracle=/export/app/oracle/product/7.3.2
PostgreSQL database
Syntax: --with-pgsql=DIR
Description : Use PostgreSQL database. For more information about PostgreSQL please refer to the PostgreSQL website http://www.postgreSQL.org or Taiwan Mirror site http://postgresql.ccit.edu.tw.
Example: --with-pgsql=/usr/local/pgsql
Solid database
Syntax: --with-solid=DIR
Description: Use Solid database. For more information about Solid please refer to Solid’s website http://www.solidtech.com.
Example: --with-solid=/usr/local/solid
Sybase database
Syntax: --with-sybase=DIR
Description: Use Sybase database. For more information about Sybase, please refer to the Sybase website http://www.sybase.com.
Example: --with-sybase=/home/sybase
Sybase-CT database
Syntax: --with-sybase-ct=DIR
Instructions: Use Sybase- CT database.
Example: --with-sybase-ct=/home/sybase
Velocis database
Syntax: --with-velocis=DIR
Description: Use Velocis database. For further information on the Velocis database please refer to the Raima website http://www.raima.com.
Example: --with-velocis=/usr/local/velocis
Customized ODBC database driver
Syntax: --with-custom-odbc=DIR
Description : Use custom ODBC function library. Of course, you must specify the CUSTOM_ODBC_LIBS and CFLAGS variables when using this method. For example, when using Sybase **SQL
** Anywhere on a QNX machine, you may need to configure the system environment variables CFLAGS=-DODBC_QNX, LDFLAGS=-lunix and CUSTOM_ODBC_LIBS="-ldblib -lodbc", and add -- in the PHP configuration. with-custom-odbc=/usr/lib/sqlany50
Example: --with-custom-odbc=/usr/local/odbc
Do not use ODBC database driver
Syntax : --disable-unified-odbc
Description: Using this option will disable all ODBC database drivers. This option does not need to specify a path, and the options affected by this option are --with-iodbc, --with-solid, --with-adabas, --with-velocis and --with-custom-odbc.
LDAP Directory Protocol
Syntax: --with-ldap=DIR
Description: If you want to use the Directory Protocol (Lightweight Directory Access Protocol, LDAP), you must turn on this option. For details about LDAP, please refer to the RFC documents RFC1777 and RFC1778.
Example: --with-ldap=/usr/local/ldap.
mcrypt encoding function library
Syntax: --with-mcrypt=DIR
说明: 当安装了 mcrypt 函数库后,可在编译 PHP 时加入本选项,让程序可以使用编解码功能。
范例: --with-mcrypt=/usr/local/include
Sys V 信号
语法: --enable-sysvsem
说明: 要使用 SysV 的信号 (semaphores) 机制,则要打开本选项。
XML 支持
语法: --with-xml
说明: 打开本选项可以支持 James Clark's 写的 XML 解析程序库。
维护模式
语法: --enable-maintainer-mode
说明: 本选项一般不会打开,除非是 PHP 开发人员比较有用。
正则表达式程序库
语法: --with-system-regex
说明: 若您需要额外的正则表达式功能,可以加入本选项。
PHP 配置文件
语法: --with-config-file-path=DIR
说明: 用来指定 php3.ini 或 php4.ini 的路径,供 PHP 初始化时使用。
范例: --with-config-file-path=/usr/local/lib
PHP 执行路径
语法: --with-exec-dir=DIR
说明: 有时为了系统的安全性考虑,会指定 PHP 程序一定要在哪个目录执行。
范例: --with-exec-dir=/usr/local/bin
调试模式
语法: --enable-debug
说明: 本选项一般不会使用,除非在开发 PHP 程序时比较有用。它可以显示额外的错误信息。
安全模式
语法: --enable-safe-mode
说明: 默认值是打开的,可以对系统安全提供比较多的保护。
变量追踪
语法: --enable-track-vars
说明: 让 PHP 能 追踪 HTTP_GET_VARS、HTTP_POST_VARS 及 HTTP_COOKIE_VARS 三个变量,一般是打开的。
自动加引入字符
语法: --enable-magic-quotes
说明: 可让程序在执行时自动加入反斜线的引入字符。
打开调试器
语法: --enable-debugger
说明: 打开内建的 PHP 调试器。目前本功能还在实验阶段,尚未成熟。
取消路径 (discard path)
语法: --enable-discard-path
说明: 打开这个选项,**用户
**就不能透过浏览器读取 .htaccess 等和系统安全相关的文件。
高精确度数学函数
语法: --enable-bcmath
说明: 打开高精确度函数。必须要先安装本函数库,本选项方有效。
强制 CGI 重定向
语法: --enable-force-cgi-redirect
范 例: 若使用 CGI VERSION 模式来执行 PHP 的设,打开本选项会增加安全性。例如用户读 http://my.host/cgi-bin/php/secret/doc.html 遇到比较了解 PHP 系统的黑客级用户可能会自已输入以下网址 http://my.host/secret/doc.html 来读取相关信息。若 PHP 和 Apache 编译在一起,让 PHP 变成 Apache 的一部份,则不需要加入本选项。
不使用短的标记
语法: --disable-short-tags
说明: 配置本选项后,PHP 的程序就不能使用短的标记,一定要用的长标记。
引入远端档宁
语法: --enable-url-includes
说明: 配置本选项可让 PHP 程序可以引入 (include) 远端的 HTTP 或 FTP 服务器中的文件。
关闭语法效果
语法: --disable-syntax-hl
说明: 使用本选项会关闭 PHP 语法的彩色效果。
函数库路径
语法: CPPFLAGS=-IDIR 及 LDFLAGS=-LDIR
说明: 若 PHP 在安全或编译所需的函数库在值得的路径,需要加入本选项,LDFLAGS 表示函数库的路径,CPPFLAGS 表示标头文件的路径。
范例: LDFLAGS=-L/my/lib/dir CPPFLAGS=-I/my/include/dir ./configure


  • 配置项代码

./configure --prefix=/usr/local/php --with-config-file-path=/usr/local/php  
--enable-mysqlnd --enable-opcache --enable-sockets --enable-sysvmsg 
--enable-sysvsem  --enable-sysvshm --enable-shmop --enable-zip 
--enable-ftp --enable-soap --enable-xml --enable-mbstring --disable-rpath 
--disable-debug --disable-fileinfo --with-mysql=mysqlnd 
--with-mysqli=mysqlnd --with-pdo-mysql=mysqlnd --with-pcre-regex 
--with-iconv --with-zlib --with-gd --with-openssl --with-xmlrpc 
--with-curl --with-imap-ssl --with-freetype-dir --enable-fpm 
--enable-pcntl --with-mcrypt --with-mhash

转自:https://www.jianshu.com/p/0a79847c8151

相关推荐:

Centos 下PHP编译安装fileinfo扩展

PHP编译安装时常见错误解决办法_PHP教程


The above is the detailed content of PHP compilation and installation Detailed explanation of each PHP compilation parameter configuration. 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