[root@hf-01 ~]# cd /usr/local/src/
[root@hf-01 src]#
[root@hf-01 ~]# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
[root@hf-01 src]# tar zxvf php-5.6.30.tar.gz
[root@hf-01 src]# ls
apr-1.6.3 httpd-2.4.29.tar.gz
apr-1.6.3.tar.gz mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-util-1.6.1 mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
apr-util-1.6.1.tar.bz2 php-5.6.30
httpd-2.4.29 php-5.6.30.tar.gz
[root@hf-01 src]#
[root@hf-01 src]# cd php-5.6.30/
[root@hf-01 php-5.6.30]#
[root@hf-01 src]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2.4/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-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
configure: error: xml2-config not found. Please check your libxml2 installation.
[root@hf-01 php-5.6.30]# yum list |grep xml2
libxml2.x86_64 2.9.1-5.el7 @anaconda
libxml2.i686 2.9.1-6.el7_2.3 base
libxml2.x86_64 2.9.1-6.el7_2.3 base
libxml2-devel.i686 2.9.1-6.el7_2.3 base
libxml2-devel.x86_64 2.9.1-6.el7_2.3 base
libxml2-python.x86_64 2.9.1-6.el7_2.3 base
libxml2-static.i686 2.9.1-6.el7_2.3 base
libxml2-static.x86_64 2.9.1-6.el7_2.3 base
mingw32-libxml2.noarch 2.9.3-1.el7 epel
mingw32-libxml2-static.noarch 2.9.3-1.el7 epel
mingw64-libxml2.noarch 2.9.3-1.el7 epel
mingw64-libxml2-static.noarch 2.9.3-1.el7 epel
python-xml2rfc.noarch 2.5.2-2.el7 epel
tinyxml2.x86_64 2.1.0-2.20140406git6ee53e7.el7
tinyxml2-devel.x86_64 2.1.0-2.20140406git6ee53e7.el7
xml2.x86_64 0.5-7.el7 epel
[root@hf-01 php-5.6.30]# yum install -y libxml2-devel
configure: error: Cannot find OpenSSL's <evp.h>
[root@hf-01 php-5.6.30]# yum install -y openssl-devel
configure: error: Please reinstall the BZip2 distribution
[root@hf-01 php-5.6.30]# yum install bzip2-devel
configure: error: jpeglib.h not found.
[root@hf-01 php-5.6.30]# yum install -y libjpeg-devel
configure: error: png.h not found.
[root@hf-01 php-5.6.30]# yum install -y libpng-devel
configure: error: freetype-config not found.
[root@hf-01 php-5.6.30]# yum install -y freetype-devel
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
先安装
[root@hf-01 php-5.6.30]# yum install -y epel-release
再安装
[root@hf-01 php-5.6.30]# yum install -y libmcrypt-devel
[root@hf-01 php-5.6.30]# echo $?
0
[root@hf-01 php-5.6.30]#
[root@hf-01 php-5.6.30]# make && make install
[root@hf-01 php-5.6.30]# ls /usr/local/php/
bin etc include lib php
[root@hf-01 php-5.6.30]#
[root@hf-01 php-5.6.30]# ls /usr/local/php/bin/
pear peardev pecl phar phar.phar php php-cgi php-config phpize
[root@hf-01 php-5.6.30]# du -sh /usr/local/php/bin/php //查看核心二进制文件大小
36M /usr/local/php/bin/php
[root@hf-01 php-5.6.30]#
[root@hf-01 php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so
37M /usr/local/apache2.4/modules/libphp5.so
[root@hf-01 php-5.6.30]#
[root@hf-01 php-5.6.30]# /usr/local/php/bin/php -m //查看php加载的模块
[PHP Modules]
bz2
Core
ctype
date
dom
ereg
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysql
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
[root@hf-01 php-5.6.30]#
[root@hf-01 php-5.6.30]# /usr/local/apache2.4/bin/httpd -M
AH00557: httpd: apr_sockaddr_info_get() failed for hf-01
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 127.0.0.1. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
php5_module (shared)
[root@hf-01 php-5.6.30]#
[root@hf-01 php-5.6.30]# ls -l /usr/local/apache2.4/modules/libphp5.so
-rwxr-xr-x 1 root root 37752872 12月 15 22:02 /usr/local/apache2.4/modules/libphp5.so
[root@hf-01 php-5.6.30]#
[root@hf-01 php-5.6.30]# vim /usr/local/apache2.4/conf/httpd.conf
去搜索php5.so,会发现自动增加了一行
LoadModule php5_module modules/libphp5.so
若想使用文件中的那一个模块,将前面的 # 号去除即可使用
若想不使用哪个模块,只需要加一个 # 号即可
[root@hf-01 ~]# /usr/local/php/bin/php -i |less
可以看到
Configuration File (php.ini) Path => /usr/local/php/etc //configurtion 的配置路径
Loaded Configuration File => (none) /这些都没有加载任何东西,因为 /usr/local/php/etc 目录是空的
[root@hf-01 ~]# cd /usr/local/src/
[root@hf-01 src]# cd php-5.6.30/
[root@hf-01 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
[root@hf-01 php-5.6.30]#
[root@hf-01 php-5.6.30]# /usr/local/php/bin/php -i |less
这里会看到加载了路径
Loaded Configuration File => /usr/local/php/etc/php.ini
[root@hf-01 php-5.6.30]# cd /usr/local/src/
[root@hf-01 src]#
[root@hf-01 src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
[root@hf-01 src]# ls
apr-1.6.3 mariadb-10.2.6-linux-glibc_214-x86_64.tar.gz
apr-1.6.3.tar.gz mysql-5.6.35-linux-glibc2.5-x86_64.tar.gz
apr-util-1.6.1 php-5.6.30
apr-util-1.6.1.tar.bz2 php-5.6.30.tar.gz
httpd-2.4.29 php-7.1.6.tar.bz2
httpd-2.4.29.tar.gz
[root@hf-01 src]# tar jxvf php-7.1.6.tar.bz2 //解压php7.1版本
[root@hf-01 src]# cd php-7.1.6/
[root@hf-01 php-7.1.6]#
[root@hf-01 php-7.1.6]# ./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache2.4/bin/apxs --with-config-file-path=/usr/local/php7/etc --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-zlib-dir --with-bz2 --with-openssl --with-mcrypt --enable-soap --enable-gd-native-ttf --enable-mbstring --enable-sockets --enable-exif
[root@hf-01 php-7.1.6]# make && make install
[root@hf-01 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so
[root@hf-01 php-7.1.6]# du -sh !$ //查看php7大小
du -sh /usr/local/apache2.4/modules/libphp7.so
37M /usr/local/apache2.4/modules/libphp7.so
[root@hf-01 php-7.1.6]#
[root@hf-01 php-7.1.6]# /usr/local/php7/bin/php -m
[PHP Modules]
bz2
Core
ctype
date
dom
exif
fileinfo
filter
gd
hash
iconv
json
libxml
mbstring
mcrypt
mysqli
openssl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib
[Zend Modules]
[root@hf-01 php-7.1.6]#
[root@hf-01 php-7.1.6]# /usr/local/apache2.4/bin/apachectl -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.0.104. Set the 'ServerName' directive globally to suppress this message
Loaded Modules:
core_module (static)
so_module (static)
http_module (static)
mpm_event_module (static)
authn_file_module (shared)
authn_core_module (shared)
authz_host_module (shared)
authz_groupfile_module (shared)
authz_user_module (shared)
authz_core_module (shared)
access_compat_module (shared)
auth_basic_module (shared)
reqtimeout_module (shared)
filter_module (shared)
mime_module (shared)
log_config_module (shared)
env_module (shared)
headers_module (shared)
setenvif_module (shared)
version_module (shared)
unixd_module (shared)
status_module (shared)
autoindex_module (shared)
dir_module (shared)
alias_module (shared)
php5_module (shared)
php7_module (shared)
[root@hf-01 php-7.1.6]#
[root@hf-01 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf
搜索php5.so,会看到有两行
LoadModule php5_module modules/libphp5.so
LoadModule php7_module modules/libphp7.so
想使用哪个php,就在另一个前面加 # 号注释掉,然后保存