共计 7441 个字符,预计需要花费 19 分钟才能阅读完成。
在 Linux 下安装 PHP5 与 PHP7 共存。
PHP5 安装
- PHP 官网 www.php.net
- 当前主流版本为 5.6/7.1
- 进入存储源码包的目录:
[root@linuxidc ~]# cd /usr/local/src
- 下载 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. 进入安装目录:
[ | ]|
[ | ]
7. 安装 php:
[root-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 | php|
[root-5.6.30]# echo $? // 安装完成没有错误用这个检查 | php|
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. 编译安装
[ | ]|
[ | ]|
[ | ]|
0 |
备注:Apache 和 php 结合的通过图中的 libphp5.so 模块
9. 查看 php 加载的模块(都是静态的):
[ | ]|
[ | ]|
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 | |
[ | ]
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] | |
-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 的配置文件目录下:
示例如下:
[ | ]|
phpinfo() | |
PHP Version => 5.6.30 | |
System => Linux linuxidc 3.10.0-514.el7.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 | |
[ | ]|
pear.conf | |
[ | ]|
[ | ]
PHP7 安装
- 进入源码包的目录:
[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. 进入目录:
[ | ]|
[ | ]
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. 编译安装:
[ | ]|
[ | ]
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 加载的模块(静态):
[ | ]|
[ | ]|
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 | |
[ | ]
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
