apache中的php模塊安裝
php5版本的對Discuz這個論壇支持解析,有較好的兼容性,不過在php7及以後的版本對discuz這個論壇不兼容,php7可能也對某些相關軟件兼容性不是很好
安裝php5
環境:安裝了http和mysql服務,安裝php時必須指定http和mysql的服務安裝路徑
首先下載對應的php版本,這裏下載的是php5.6.37
解壓php,並在解壓目錄下執行編譯參數
關於編譯參數解釋:
./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\
在php解壓目錄下的編譯參數,對於編譯中出現的錯誤,筆記結尾有解答
[root@localhost 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 -------------------------編譯過程忽略-----------------------
make過程後的結果
-----------------------make開頭信息省略------------------------ Generating phar.php Generating phar.phar PEAR package PHP_Archive not installed: generated phar will require PHP‘s phar extension be enabled. clicommand.inc directorytreeiterator.inc invertedregexiterator.inc directorygraphiterator.inc pharcommand.inc phar.inc Build complete. Don‘t forget to run ‘make test‘. [root@localhost php-5.6.37]# echo $? 0
make install 過程,其中有警告,提示libtool這個模塊未正常加載,這裏忽略
[root@localhost php-5.6.37]# make install
Installing 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.so
libtool: install: install .libs/libphp5.lai /usr/local/httpd/modules/libphp5.la
libtool: 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 man page: /usr/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
program: php-config
Installing man pages: /usr/local/php5/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment: /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.5
Wrote PEAR system config file at: /usr/local/php5/etc/pear.conf
You may want to add: /usr/local/php5/lib/php to your php.ini include_path
/usr/local/src/php-5.6.37/build/shtool install -c ext/phar/phar.phar /usr/local/php5/bin
ln -s -f phar.phar /usr/local/php5/bin/phar
Installing PDO headers: /usr/local/php5/include/php/ext/pdo/
[root@localhost php-5.6.37]# echo $?
0
在結合apache安裝php中,php只是編譯一個模塊給apache使用,php模塊是/usr/local/httpd/modules/libphp5.so
[root@localhost 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
查看php加載的模塊,使用php目錄下的一個可執行文件查看,php在apache中是以模塊來進行加載的,php模塊就是/usr/local/httpd/modules/libphp5.so 文件, apache在解析php時會自動加載php模塊文件跟數據庫進行交互
[root@localhost php-5.6.37]# /usr/local/php5/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
[Zend Modules]
拷貝php的配置文件,並查看是否加載配置文件
[root@localhost ]# cp /usr/local/src/php-5.6.37/php.ini-production /usr/local/php5/etc/php.ini
[root@localhost php-5.6.37]# /usr/local/php5/bin/php -i |less
phpinfo()
PHP Version => 5.6.37
System => Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Jul 29 2018 08:17:07
Configure 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 Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/local/php/etc <-------加載的php配置文件
Loaded Configuration File => (none)
Scan this dir for additional .ini files => (none)
查看apache配置文件中加載php配置項,註釋表示不在apache啟動時啟動該模塊
[root@localhost ]# vim /usr/local/httpd/conf/httpd.conf
~
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module modules/libphp5.so
php7安裝
安裝php7,編譯過程和php5基本一致,需要修改php5安裝時指定的安裝目錄和配置文件目錄,否則安裝php7時會覆蓋掉php5
[root@localhost 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-exif
configure: WARNING: unrecognized options: --with-mysql, --with-mcrypt, --enable-gd-native-ttf
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for a sed that does not truncate output... /usr/bin/sed
checking build system type... x86_64-unknown-linux-gnu
checking host system type... x86_64-unknown-linux-gnu
-----------------------過程省略----------------------
Thank you for using PHP.
config.status: creating php7.spec
config.status: creating main/build-defs.h
config.status: creating scripts/phpize
config.status: creating scripts/man1/phpize.1
config.status: creating scripts/php-config
config.status: creating scripts/man1/php-config.1
config.status: creating sapi/cli/php.1
config.status: creating sapi/cgi/php-cgi.1
config.status: creating ext/phar/phar.1
config.status: creating ext/phar/phar.phar.1
config.status: creating main/php_config.h
config.status: executing default commands
configure: WARNING: unrecognized options: --with-mysql, --with-mcrypt, --enable-gd-native-ttf
編譯的函數庫有警告,忽略警告執行make繼續編譯
make繼續編譯php7,make install 完成安裝
[root@localhost 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
-----------------------省略過程------------------------------
PEAR package PHP_Archive not installed: generated phar will require PHP‘s phar extension be enabled.
directorygraphiterator.inc
clicommand.inc
directorytreeiterator.inc
invertedregexiterator.inc
pharcommand.inc
phar.inc
Build complete.
Don‘t forget to run ‘make test‘.
[root@localhost php-7.2.8]# echo $?
0
[root@localhost php-7.2.8]# make install make install編譯安裝最後步驟
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.so
libtool: install: install .libs/libphp7.lai /usr/local/httpd/modules/libphp7.la
libtool: 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: /usr/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.1
Installing PEAR environment: /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.5
Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
/usr/local/src/php-7.2.8/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers: /usr/local/php7/include/php/ext/pdo/
同一臺機器可以運行兩個php,只不過在其他程序在調用時指定好需要使用的php模塊
拷貝php7的配置文件
[root@localhost php-7.2.8]# cp /usr/local/src/php-7.2.8/php.ini-production /usr/local/php7/etc/php.ini
[root@localhost php-7.2.8]# /usr/local/php7/bin/php -i
phpinfo()
PHP Version => 7.2.8
System => Linux localhost.localdomain 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Jul 29 2018 09:54:15
Configure 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 Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/local/php7/etc <---顯示了php7的配置文件
Loaded Configuration File => /usr/local/php7/etc/php.ini
Scan this dir for additional .ini files => (none)
讓apache使用指定的php程序,只需要修改apache的配置文件,找到配置文件中php模塊的配置項,把不需要加載的php配置註釋掉即可
[root@localhost ]# vim /usr/local/httpd/conf/httpd.conf
~
LoadModule php5_module modules/libphp5.so
#LoadModule php7_module modules/libphp7.so <------註釋掉php7模塊,不讓它被apache動態加載
php編譯中出現的問題
問題一:
php編譯安裝中有安裝庫報錯,根據報錯信息查找對應安裝包,安裝包軟件一般是以devel結尾的,使用yum install 安裝庫名稱-devel 可以正常安裝該支持庫
問題二:
解決:error: Cannot find libmysqlclient_r under /usr/local/mysql.
配置php的時候出現以下問題解決方案
checking for MySQL support... yes
checking for specified location of the MySQL UNIX socket...no
checking for MySQL UNIX socket location... no
configure: error: Cannot find libmysqlclient_r under/usr/local/mysql. Note that the MySQL client library is not bundledanymore!
其實這跟PHP沒有關系,那是因為在編譯APACHE的時候,使用--with-mpm模塊,所以就必須在編譯MYSQL的時候加上--enable-thread-safe-client.參數
這是PHP5.2的一個改進,在PHP5.2.0之前的版本都不需要MYSQL啟用安全線程。關於--enable-thread-safe-client項的官方介紹如下:如何生成線程式客戶端庫總是線程安全的。最大的問題在於從套接字讀取的net.c中的子程序並不是中斷安全的。或許你可能希望用自己的告警中斷對服務器的長時間讀取,以此來解決問題。如果為SIGPIPE中斷安裝了中斷處理程序,套接字處理功能應是線程安全的。SupeSite/X-為了避免連接中斷時放棄程序,MySQL將在首次調用mysql_server_init()、mysql_init()或mysql_connect()時屏蔽SIGPIPE。如果你打算使用自己的SIGPIPE處理程序,首先應調用mysql_server_init(),然後安裝你的處理程序.
還有第二種解決方法比較方便:編譯之前,先處理一下mysql的庫,默認查找libmysqlclient_r.so,可是mysql默認為libmysqlclient.so,內容完全一樣,做個鏈接即可
# cd /usr/local/mysql/lib/mysql/
# ln -s libmysqlclient.so.20.0.0 libmysqlclient_r.so
apache中的php模塊安裝