PHP module installation in Apache

Source: Internet
Author: User
Tags bz2 soap mysql client pear php cli sapi zts zend

PHP's website: http://php.net
PHP5 version of the Discuz this forum support parsing, there is good compatibility, but in PHP7 and later versions of Discuz This forum is not compatible, PHP7 may also be some related software compatibility is not very good

Installing PHP5
Environment: HTTP and MySQL services installed, HTTP and MySQL service installation paths must be specified when installing PHP
First download the corresponding PHP version, here is the download php5.6.37
Unzip PHP and execute the compilation parameters in the extracted directory
Explanation of the compilation parameters:

./configure --prefix=/usr/local/php5 \            指定php安装目录--with-apxs2=/usr/local/httpd/bin/apxs \         指定http目录,编译中可向http配置文件中添加php--with-config-file-path=/usr/local/php/etc \     指定php的配置文件目录--with-mysql=/usr/local/mysql \                  指定mysql的安装目录和mysql的库路径--with-pdo-mysql=/usr/local/mysql \               --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir \                                以下是指定php需要编译支持的函数库--with-gd \ --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-sockets --enable-exif\

Compilation parameters in PHP decompression directory, for errors in compilation, the end of the note is answered

[[email protected] php-5.6.37]# ./configure --prefix=/usr/local/php5 --with-apxs2=/usr/local/httpd/bin/apxs --with-config-file-path=/usr/local/php/etc --with-mysql=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli=/usr/local/mysql/bin/mysql_config --with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-sockets --enable-exif-------------------------编译过程忽略-----------------------

Results after the make process

-----------------------make开头信息省略------------------------Generating phar.phpGenerating phar.pharPEAR package PHP_Archive not installed: generated phar will require PHP‘s phar extension be enabled.clicommand.incdirectorytreeiterator.incinvertedregexiterator.incdirectorygraphiterator.incpharcommand.incphar.incBuild complete.Don‘t forget to run ‘make test‘.[[email protected] php-5.6.37]# echo $?0

Make the install process, where there is a warning that libtool this module does not load properly, this ignores

[[email protected] php-5.6.37]# make installinstalling php SAPI module:apache2handler/usr/local/httpd/build/ instdso.sh sh_libtool= '/usr/local/apr/build-1/libtool ' libphp5.la/usr/local/httpd/modules/usr/local/apr/build-1/ Libtool--mode=install install Libphp5.la/usr/local/httpd/modules/libtool:install:install. libs/libphp5.so/usr/ Local/httpd/modules/libphp5.solibtool:install:install. libs/libphp5.lai/usr/local/httpd/modules/ Libphp5.lalibtool:warning:remember to run ' libtool--finish/usr/local/src/php-5.6.37/libs ' chmod 755/usr/local/httpd /modules/libphp5.so[activating module ' php5 ' in/usr/local/httpd/conf/httpd.conf]installing shared extensions:/usr/ local/php5/lib/php/extensions/no-debug-zts-20131226/installing php CLI binary:/usr/local/php5/bin/installing php CLI man page:/usr/local/php5/php/man/man1/installing php cgi binary:/usr/local/php5/bin/installing PHP CGI mans page:/US R/local/php5/php/man/man1/installing Build Environment:/usr/local/php5/lib/php/build/inStalling header files:/usr/local/php5/include/php/installing helper programs:/usr/local/php5/bin/program:phpize Pro Gram:php-configinstalling man pages:/usr/local/php5/php/man/man1/page:phpize.1 page:php-config.1installing PEAR env Ironment:/usr/local/php5/lib/php/[pear] archive_tar-installed:1.4.3[pear] console_getopt-installed:1.4.1[pear] Structures_graph-installed:1.1.1[pear] xml_util-installed:1.4.2[pear] pear-installed:1.10.5wrote PEAR system confi G file at:/usr/local/php5/etc/pear.confyou could want to add:/usr/local/php5/lib/php to your php.ini Include_path/usr/loca L/src/php-5.6.37/build/shtool install-c ext/phar/phar.phar/usr/local/php5/binln-s-F phar.phar/usr/local/php5/bin/ pharinstalling PDO headers:/usr/local/php5/include/php/ext/pdo/[[email protected] php-5.6.37]# echo $?0

In conjunction with Apache installation PHP, PHP just compiles a module for Apache to use, PHP module is/usr/local/httpd/modules/libphp5.so

[[email protected] php-5.6.37]# ll -h /usr/local/httpd/modules/libphp5.so -rwxr-xr-x 1 root root 34M 7月 29 08:27 /usr/local/httpd/modules/libphp5.so

View PHP loaded module, using a PHP directory executable file view, PHP in Apache is a module to load, PHP module is the/usr/local/httpd/modules/libphp5.so file, Apache will automatically load PHP module files to interact with the database when parsing PHP

[[email protected] php-5.6.37]# /usr/local/php5/bin/php -m[PHP Modules]bz2CorectypedatedomeregexiffileinfofiltergdhashiconvjsonlibxmlmcryptmysqlmysqliopensslpcrePDOpdo_mysqlpdo_sqlitePharposixReflectionsessionSimpleXMLsoapsocketsSPLsqlite3standardtokenizerxmlxmlreaderxmlwriter[Zend Modules]

Copy the PHP configuration file and see if the configuration file is loaded

[[email protected]]# Cp/usr/local/src/php-5.6.37/php.ini-production/usr/local/php5/etc/php.ini[[email  protected] php-5.6.37]#/usr/local/php5/bin/php-i |lessphpinfo () php Version = 5.6.37System = Linux Localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 16:42:41 UTC x86_64build Date = Jul 29 2018 08:17:0 7Configure Command = './configure '--prefix=/usr/local/php5 '--with-apxs2=/usr/local/httpd/bin/apxs '-- With-config-file-path=/usr/local/php/etc '--with-mysql=/usr/local/mysql '--with-pdo-mysql=/usr/local/mysql '-- With-mysqli=/usr/local/mysql/bin/mysql_config '--with-libxml-dir '--with-gd '--with-jpeg-dir '--with-png-dir ' --with-freetype-dir '--with-iconv-dir '--with-bz2 '--with-openssl '--with-mcrypt '--enable-soap '-- Enable-gd-native-ttf '--enable-sockets '--enable-exif ' Server API = Command line interfacevirtual Directory Support = Enabledconfiguration File (php.ini) Path =/usr/local/php/etc <-------load PHP config file loaded configuration files = = (none) Scan this dir for additional. ini files = (none) 

Check the Apache configuration file to load the PHP configuration entry, note that the module does not start when Apache starts

[[email protected] ]# vim /usr/local/httpd/conf/httpd.conf~#LoadModule rewrite_module modules/mod_rewrite.soLoadModule php5_module modules/libphp5.so
PHP7 Installation

Install PHP7, the compilation process and PHP5 are basically consistent, you need to modify the installation directory and configuration file directory specified PHP5 installation, or the installation PHP7 will be overwritten php5

[[email protected] php-7.2.8]#./configure--PREFIX=/USR/LOCAL/PHP7--with-apxs2=/usr/local/httpd/bin/apxs-- With-config-file-path=/usr/local/php7/etc--with-mysql=/usr/local/mysql--with-pdo-mysql=/usr/local/mysql-- With-mysqli=/usr/local/mysql/bin/mysql_config--with-libxml-dir--with-gd--with-jpeg-dir--with-png-dir-- With-freetype-dir--with-iconv-dir--with-bz2--with-openssl--with-mcrypt--enable-soap--enable-gd-native-ttf-- Enable-sockets--enable-exifconfigure:warning:unrecognized options:--with-mysql,--with-mcrypt,-- Enable-gd-native-ttfchecking for grep that handles long lines and-e .../usr/bin/grepchecking for egrep .../usr/bin/grep- Echecking for a sed this does not truncate output .../usr/bin/sedchecking build system type ... X86_64-unknown-linux-gnuche Cking host system Type ... x86_64-unknown-linux-gnu-----------------------procedure omitted----------------------Thank you Using PHP.config.status:creating php7.specconfig.status:creating main/build-defs.hconfig.status:Creating Scripts/phpizeconfig.status:creating scripts/man1/phpize.1config.status:creating scripts/ Php-configconfig.status:creating scripts/man1/php-config.1config.status:creating Sapi/cli/php.1config.status: Creating Sapi/cgi/php-cgi.1config.status:creating ext/phar/phar.1config.status:creating ext/phar/ Phar.phar.1config.status:creating main/php_config.hconfig.status:executing Default commandsconfigure:warning: Unrecognized options:--with-mysql,--with-mcrypt,--enable-gd-native-ttf compiled library with warnings, ignoring warnings perform make to continue compiling

Make continue compiling Php7,make install to complete installation

[[email protected] php-7.2.8]# make/bin/sh/usr/local/src/php-7.2.8/libtool--silent--preserve-dup-deps--mode =compile/usr/local/src/php-7.2.8/meta_ccld-iext/date/lib-dzend_enable_static_tsrmls_cache=1-dhave_timelib_ config_h=1-iext/date/-i/usr/local/src/php-7.2.8/ext/date/-dphp_atom_inc-i/usr/local/src/php-7.2.8/include-i/ usr/local/src/php-7.2.8/main-i/usr/local/src/php-7.2.8-i/usr/local/src/php-7.2.8/ext/date/lib-i/usr/include/ libxml2-i/usr/include/freetype2-i/usr/local/mysql/include-i/usr/local/src/php-7.2.8/ext/sqlite3/libsqlite-i/ Usr/local/src/php-7.2.8/tsrm-i/usr/local/src/php-7.2.8/zend-d_reentrant-i/usr/include-g-o2-fvisibility=hidden- Pthread-dzts-dzend_signals-c/usr/local/src/php-7.2.8/ext/date/php_date.c-o Ext/date/php_date.lo---------------- -------Ellipsis process------------------------------PEAR package php_archive not installed:generated Phar would require PHP ' s Phar E XTension be enabled.directorygraphiterator.incclicommand.incdirectorytreeiterator.iNcinvertedregexiterator.incpharcommand.incphar.incBuild complete. Don ' t forget to run ' make test '. [[email protected] php-7.2.8]# Echo $?0[[email protected] php-7.2.8]# make install make INS Tall compile and install final steps installing PHP SAPI module:apache2handler/usr/local/httpd/build/instdso.sh sh_libtool= '/usr/local/apr/ Build-1/libtool ' Libphp7.la/usr/local/httpd/modules/usr/local/apr/build-1/libtool--mode=install Install Libphp7.la/usr/local/httpd/modules/libtool:install:install. libs/libphp7.so/usr/local/httpd/modules/ Libphp7.solibtool:install:install. Libs/libphp7.lai/usr/local/httpd/modules/libphp7.lalibtool:warning:remember To run ' Libtool--finish/usr/local/src/php-7.2.8/libs ' chmod 755/usr/local/httpd/modules/libphp7.so[activating Module ' PHP7 ' in/usr/local/httpd/conf/httpd.conf]installing shared extensions:/usr/local/php7/lib/php/extensions/ no-debug-zts-20170718/installing php cli binary:/usr/local/php7/bin/installing PHP CLI man page:/usr/local/php7/php/man/man1/installing phpdbg binary:/usr/local/php7/bin/installing phpdbg man page: /usr/local/php7/php/man/man1/installing php cgi binary:/usr/local/php7/bin/installing php cgi man page:/US          R/local/php7/php/man/man1/installing build Environment:/usr/local/php7/lib/php/build/installing Header files: /usr/local/php7/include/php/installing Helper Programs:/usr/local/php7/bin/program:phpize Program:php-config Installing man pages:/usr/local/php7/php/man/man1/page:phpize.1 page:php-config.1installing PEAR environ ment:/usr/local/php7/lib/php/[pear] archive_tar-installed:1.4.3[pear] console_getopt-installed:1.4.1[pear] Structures_graph-installed:1.1.1[pear] Xml_util-installed:1.4.2[pear] Pear-installed:1.10.5wrote P EAR System config file at:/usr/local/php7/etc/pear.confyou want to add:/usr/local/php7/lib/php to your php.ini inclu De_path/usr/local/src/phP-7.2.8/build/shtool install-c ext/phar/phar.phar/usr/local/php7/binln-s-F phar.phar/usr/local/php7/bin/ pharinstalling PDO headers:/usr/local/php7/include/php/ext/pdo/

The same machine can run two PHP, but in other programs when the call to specify the PHP module to use
Copy the PHP7 configuration file

[[email protected] php-7.2.8]# Cp/usr/local/src/php-7.2.8/php.ini-production/usr/local/php7/etc/php.ini [[ Email protected] php-7.2.8]#/usr/local/php7/bin/php-iphpinfo () php Version = 7.2.8System = Linux Localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 16:42:41 UTC x86_64build Date = Jul 29 2018 09:54:1 5Configure Command = './configure '--prefix=/usr/local/php7 '--with-apxs2=/usr/local/httpd/bin/apxs '-- With-config-file-path=/usr/local/php7/etc '--with-mysql=/usr/local/mysql '--with-pdo-mysql=/usr/local/mysql '- -with-mysqli=/usr/local/mysql/bin/mysql_config '--with-libxml-dir '--with-gd '--with-jpeg-dir '--with-png-dir ' '--with-freetype-dir '--with-iconv-dir '--with-bz2 '--with-openssl '--with-mcrypt '--enable-soap '-- Enable-gd-native-ttf '--enable-sockets '--enable-exif ' Server API = Command line interfacevirtual Directory Support = Enabledconfiguration File (php.ini) Path =/usr/local/php7/etc <---shows the phP7 profile Loaded configuration file =/usr/local/php7/etc/php.iniscan This dir for additional. ini files = (none) 

Let Apache use the specified PHP program, only need to modify the Apache configuration file, find the configuration file in the PHP module configuration, the PHP configuration does not need to load comments out

[[email protected] ]# vim /usr/local/httpd/conf/httpd.conf~LoadModule php5_module modules/libphp5.so#LoadModule php7_module modules/libphp7.so         <------注释掉php7模块,不让它被apache动态加载
Problems with PHP compilation

Question one:
PHP compilation installation in the installation of error, according to the error information to find the corresponding installation package, installation package software is generally end with devel, use the Yum Install Library name-devel can install the support library properly

Question two:
Resolution: Error:cannot Find Libmysqlclient_r under/usr/local/mysql.
The following problem solution is present when you configure PHP

checking for MySQL support... yeschecking for specified location of the MySQL UNIX socket...nochecking for MySQL UNIX socket location... noconfigure: error: Cannot find libmysqlclient_r under/usr/local/mysql. Note that the MySQL client library is not bundledanymore!

In fact, this is not related to PHP, it is because when compiling Apache, using the--WITH-MPM module, so you have to compile MySQL when you add--enable-thread-safe-client. Parameters
This is an improvement of PHP5.2, which does not require MySQL to enable security threads before the PHP5.2.0 version. The official introduction to the--enable-thread-safe-client item is as follows: How to build a wire program client library is always thread-safe. The biggest problem is that subroutines that are read from the socket in the net.c are not break-safe. You might want to resolve the problem by interrupting a long-time read of the server with your own alarms. If an interrupt handler is installed for Sigpipe interrupts, the socket processing feature should be thread-safe. supesite/x-to avoid dropping a program when the connection is interrupted, MySQL masks sigpipe on the first call to Mysql_server_init (), Mysql_init (), or mysql_connect (). If you plan to use your own sigpipe handler, you should first call Mysql_server_init () and then install your handler.

There is a second solution is convenient: before compiling, the first to process the MySQL library, the default lookup libmysqlclient_r.so, but MySQL default is libmysqlclient.so, the content is exactly the same, make a link

# cd /usr/local/mysql/lib/mysql/ # ln -s libmysqlclient.so.20.0.0 libmysqlclient_r.so

PHP module installation in Apache

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.