码迷,mamicode.com
首页 > Web开发 > 详细

安装PHP5和PHP7

时间:2018-02-28 23:07:03      阅读:503      评论:0      收藏:0      [点我收藏+]

标签:PHP

安装PHP5

技术分享图片
1.下载php5.6包

[root@weixing01 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2
--2018-02-28 21:03:29--  http://cn2.php.net/distributions/php-5.6.30.tar.bz2
正在解析主机 cn2.php.net (cn2.php.net)... 123.125.23.168, 123.125.23.169, 123.125.23.171, ...
正在连接 cn2.php.net (cn2.php.net)|123.125.23.168|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:15011816 (14M) [application/octet-stream]
正在保存至: “php-5.6.30.tar.bz2”

100%[=============================================>] 15,011,816   478KB/s 用时 29s    

2018-02-28 21:03:58 (497 KB/s) - 已保存 “php-5.6.30.tar.bz2” [15011816/15011816])

2.解压缩

tar -jxvf php-5.6.30.tar.bz2 

3.进行编译

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

报错

checking for strftime... (cached) yes
checking which regex library to use... php
checking whether to enable LIBXML support... yes
checking libxml2 install dir... yes
checking for xml2-config path... 
configure: error: xml2-config not found. Please check your libxml2 installation.

需要安装库文件

[root@weixing01 php-5.6.30]# yum install -y libxml2-devel
已加载插件:fastestmirror
base                                                            | 3.6 kB  00:00:00     
epel/x86_64/metalink                                            | 6.0 kB  00:00:00     
epel                                                            | 4.7 kB  00:00:00     
extras                                                          | 3.4 kB  00:00:00   

再次编译

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

发现第二个错误

checking for DSA_get_default_method in -lssl... no
checking for X509_free in -lcrypto... no
checking for RAND_egd... no
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL‘s <evp.h>

安装第二个库文件

[root@weixing01 php-5.6.30]# yum install -y openssl-devel
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 openssl-devel.x86_64.1.1.0.2k-8.el7 将被 安装
--> 正在处理依赖关系 krb5-devel(x86-64),它被软件包 1:openssl-devel-1.0.2k-8.el7.x86_64 需要
--> 正在检查事务

再次编译

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

新的错误

checking for gzgets in -lz... yes
checking whether to enable bc style precision math functions... no
checking for BZip2 support... yes
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution

需要安装


[root@weixing01 php-5.6.30]# yum install -y bzip2-devel
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 bzip2-devel.x86_64.0.1.0.6-13.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

再次编译

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

新的错误

checking whether to enable truetype string function in GD... yes
checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
configure: error: jpeglib.h not found.

需要安装的包

[root@weixing01 php-5.6.30]# yum install -y libjpeg-devel
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 libjpeg-turbo-devel.x86_64.0.1.2.90-5.el7 将被 安装
--> 正在处理依赖关系 libjpeg-turbo(x86-64) = 1.2.90-5.el7,它被软件包 libjpeg-turbo-devel-1.2.90-5.el7.x86_64 需要
--> 正在处理依赖关系 libjpeg.so.62()(64bit),它被软件包 libjpeg-turbo-devel-1.2.90-5.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libjpeg-turbo.x86_64.0.1.2.90-5.el7 将被 安装
--> 解决依赖关系完成

再次编译

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

新的错误

checking whether to enable JIS-mapped Japanese font support in GD... no
If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.

安装的包

[root@weixing01 php-5.6.30]# yum install -y libpng-devel
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 libpng-devel.x86_64.2.1.5.13-7.el7_2 将被 安装
--> 正在处理依赖关系 libpng(x86-64) = 2:1.5.13-7.el7_2,它被软件包 2:libpng-devel-1.5.13-7.el7_2.x86_64 需要
--> 正在处理依赖关系 libpng15.so.15()(64bit),它被软件包 2:libpng-devel-1.5.13-7.el7_2.x86_64 需要
--> 正在检查事务
---> 软件包 libpng.x86_64.2.1.5.13-7.el7_2 将被 安装
--> 解决依赖关系完成

再次编译

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

新的错误

checking for jpeg_read_header in -ljpeg... yes
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.

需要安装的包

[root@weixing01 php-5.6.30]# yum install -y freetype-devel
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 freetype-devel.x86_64.0.2.4.11-15.el7 将被 安装
--> 解决依赖关系完成

依赖关系解决

再次编译

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

新的错误

checking for working memcmp... yes
checking for stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.

需要安装的包

[root@weixing01 php-5.6.30]# yum install -y epel-release
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 epel-release.noarch.0.7-9 将被 升级
---> 软件包 epel-release.noarch.0.7-11 将被 更新
--> 解决依赖关系完成
[root@weixing01 php-5.6.30]# yum install -y libmcrypt-devel
已加载插件:fastestmirror
Loading mirror speeds from cached hostfile
 * epel: mirrors.ustc.edu.cn
正在解决依赖关系
--> 正在检查事务
---> 软件包 libmcrypt-devel.x86_64.0.2.5.8-13.el7 将被 安装
--> 正在处理依赖关系 libmcrypt = 2.5.8-13.el7,它被软件包 libmcrypt-devel-2.5.8-13.el7.x86_64 需要
--> 正在处理依赖关系 libmcrypt.so.4()(64bit),它被软件包 libmcrypt-devel-2.5.8-13.el7.x86_64 需要
--> 正在检查事务
---> 软件包 libmcrypt.x86_64.0.2.5.8-13.el7 将被 安装
--> 解决依赖关系完成

再次编译

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

编译成功

+--------------------------------------------------------------------+
| License:                                                           |
| This software is subject to the PHP License, available in this     |
| distribution in the file LICENSE.  By continuing this installation |
| process, you are bound by the terms of this license agreement.     |
| If you do not agree with the terms of this license, you must abort |
| the installation process at this point.                            |
+--------------------------------------------------------------------+

Thank you for using PHP.

config.status: creating php5.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

4.进行make

[root@weixing01 php-5.6.30]# make
/bin/sh /usr/local/src/php-5.6.30/libtool --silent --preserve-dup-deps --mode=compile /usr/local/src/php-5.6.30/meta_ccld -Iext/date/lib -D HAVE_TIMELIB_CONFIG_H=1 -Iext/date/ -I/usr/local/src/php-5.6.30/ext/date/ -DPHP_ATOM_INC -I/usr/local/src/php-5.6.30/include -I/usr/local/src/php-5.6.30/main -I/usr/local/src/php-5.6.30 -I/usr/local/src/php-5.6.30/ext/date/lib -I/usr/local/src/php-5.6.30/ext/ereg/regex -I/usr/include/libxml2 -I/usr/include/freetype2 -I/usr/local/src/php-5.6.30/ext/mbstring/oniguruma -I/usr/loca

5.进行make install

[root@weixing01 php-5.6.30]# make install
Installing PHP SAPI module:       apache2handler
/usr/local/apache2.4/build/instdso.sh SH_LIBTOOL=‘/usr/local/apr/build-1/libtool‘ libphp5.la /usr/local/apache2.4/modules
/usr/local/apr/build-1/libtool --mode=install install libphp5.la /usr/local/apache2.4/modules/
libtool: install: install .libs/libphp5.so /usr/local/apache2.4/modules/libphp5.so

6.查看加载的模块

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

7.PHP作为一个Apache的模块使用

[root@weixing01 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 111.63.112.254. 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)

8.复制配置文件

安装PHP7

技术分享图片
1.下载PHP7安装包

[root@weixing01 php-5.6.30]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
--2018-02-28 21:51:00--  http://cn2.php.net/distributions/php-7.1.6.tar.bz2
正在解析主机 cn2.php.net (cn2.php.net)... 123.125.23.168, 123.125.23.171, 123.125.23.169, ...
正在连接 cn2.php.net (cn2.php.net)|123.125.23.168|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:15732452 (15M) [application/octet-stream]
正在保存至: “php-7.1.6.tar.bz2”

2.解压缩

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

3.进行编译

 ./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
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

4.进行make
5.进行make install
6.安装完成后发现Apache加载了两个PHP

[root@weixing01 php-7.1.6]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server‘s fully qualified domain name, using 111.63.112.254. 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)

7.修改配置文件来决定Apache调用哪个php

[root@weixing01 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf

安装PHP5和PHP7

标签:PHP

原文地址:http://blog.51cto.com/13517254/2074076

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!