你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux安装PHP5与PHP7共存

[日期:2018-01-01] 来源:Linux社区  作者:taoxie [字体: ]

在Linux下安装PHP5与PHP7共存。

PHP5安装

  1. PHP官网www.php.net
  2. 当前主流版本为5.6/7.1
  3. 进入存储源码包的目录:
    [root@linuxidc ~]# cd /usr/local/src
    
  4. 下载php的源码包:

地址:wget http://cn2.php.net/distributions/php-5.6.30.tar.gz

5.解压压缩包:

[root@linuxidc src]# tar -zxvf php-5.6.30.tar.gz

6.进入安装目录:

[root@linuxidc src]# cd php-5.6.30
[root@linuxidc php-5.6.30]#

7.安装php:

[root@linuxidc php-5.6.30]# ./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  //安装PHP
[root@linuxidc php-5.6.30]# echo $?  //安装完成没有错误用这个检查
0

解释说明个别参数:

--prefix:指定安装目录。
--with-apxs2:Apache的工具,指定工具的地址,可以帮我们自动配置一些模块,不用人工干涉。
--with-config-file-path:指定配置文件的路径。
--with-mysql:指定mysql路径。

安装报错:

  • 缺少libxml2这个库,安装命令:yum install -y libxml2-devel

  • 缺少openssl库,安装命令:yum install -y openssl-devel

  • 缺少bzip2包,安装命令:yum install -y bzip2-devel

  • 缺少jpeglid包,安装命令:yum install -y libjpeg-devel

  • 缺少libpng包,安装命令:yum install -y libpng-devel

  • 缺少freetype包,安装命令:yum install -y freetype-devel

  • 缺少libmcrypt包,安装命令:yum install -y libmcrypt-devel,如果你没有安装epel-release这个扩展源,就需要先安装这个扩展源,因为libmcrypt是在这个扩展源里面,安装扩展源命令:yum install -y epel-release

8.编译安装

[root@linuxidc php-5.6.30]# make
[root@linuxidc php-5.6.30]# make install 
[root@linuxidc php-5.6.30]# echo $?
0

备注:Apache和php结合的通过图中的libphp5.so模块

9.查看php加载的模块(都是静态的):

[root@linuxidc php-5.6.30]# /usr/local/php/bin/php -m
[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]

10.PHP是做为apache的模块存在,查看模块:

[root@linuxidc php-5.6.30]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 218.93.250.18. 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@linuxidc php-5.6.30]# ls -l /usr/local/apache2.4/modules/libphp5.so   //模块文件
-rwxr-xr-x 1 root root 37752872 12月 18 17:09 /usr/local/apache2.4/modules/libphp5.so

解释说明:
php5_module (shared):这个说明PHP是作为httpd扩展模块的形式存在的,那如果apache要想执行php的脚本,它就需要依赖借助于这个模块文件,如果把这个.so文件删除,那apache就不支持php了,这个模块非常重要。

11.这个httpd的配置文件里就多了一行php模块,被注释掉的就是没有用的模块,如果想用,把#号去掉就可以了,随用随取:

[root@linuxidc php-5.6.30]# vim /usr/local/apache2.4/conf/httpd.conf  //这是apache的配置文件

12.把php的参考配置文件复制到php的配置文件目录下:

示例如下:

[root@linuxidc php-5.6.30]# /usr/local/php/bin/php -i |less  //查看php的一些配置信息,包括编译参数。


phpinfo()
PHP Version => 5.6.30

System => Linux linuxidc 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Dec 18 2017 17:05:31
Configure Command =>  './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'
Server API => Command Line Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/local/php/etc
Loaded Configuration File => (none)
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20131106
PHP Extension => 20131226
Zend Extension => 220131226
Zend Extension Build => API220131226,TS
PHP Extension Build => API20131226,TS
Debug Build => no
Thread Safety => enabled
Zend Signal Handling => disabled
Zend Memory Manager => enabled
Zend Multibyte Support => provided by mbstring
IPv6 Support => enabled
DTrace Support => disabled

Registered PHP Streams => https, ftps, compress.zlib, compress.bzip2, php, file, glob, data, http, ftp, phar
Registered Stream Socket Transports => tcp, udp, unix, udg, ssl, sslv3, tls, tlsv1.0, tlsv1.1, tlsv1.2
Registered Stream Filters => zlib.*, bzip2.*, convert.iconv.*, mcrypt.*, mdecrypt.*, string.rot13, string.toupper, string.tolower, string.strip_tags, convert.*, consumed, dechunk

This program makes use of the Zend Scripting Language Engine:
Zend Engine v2.6.0, Copyright (c) 1998-2016 Zend Technologies


 _______________________________________________________________________


Configuration

bz2
[root@linuxidc php-5.6.30]# ls /usr/local/php/etc //查看模块下有没php.ini文件
pear.conf 
[root@linuxidc php-5.6.30]# cp php.ini-production  /usr/local/php/etc/php.ini  //需要到源码包的参考文件复制到php的配置文件目录下
[root@linuxidc php-5.6.30]# /usr/local/php/bin/php -i |less  //查看php.ini是否有加载php.ini文件模块,如下图


PHP7安装

  1. 进入源码包的目录:
    [root@linuxidc ~]# cd /usr/local/src/
    
    2.下载源码包:

地址:wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

3.解压压缩包:

[root@linuxidc src]#  tar jxvf php-7.1.6.tar.bz2

备注:如果没有安装bzip2压缩工具,请安装:yum install -y bzip2

4.进入目录:

[root@linuxidc src]# cd php-7.1.6
[root@linuxidc php-7.1.6]#

5.安装php7:

[root@linuxidc 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

6.编译安装:

[root@linuxidc php-7.1.6]# make
[root@linuxidc php-7.1.6]# make install

7.php7模块路径:

[root@linuxidc php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so

8.查看php7加载的模块(静态):

[root@linuxidc 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]

9.查看apache加载了几个php,通过修改配置文件来指定使用php5还是php7模块,不要的就注释掉:

示例如下:

[root@linuxidc 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 218.93.250.18. 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@linuxidc php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf

10.把php7的参考配置文件复制到php7的配置文件目录下:

[root@linuxidc php-7.1.6]# cp php.ini-production  /usr/local/php7/etc/php.ini

本文永久更新链接地址http://www.linuxidc.com/Linux/2018-01/150007.htm

linux
相关资讯       Linux安装PHP  PHP5与PHP7共存 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款