安装PHP5、安装PHP7

目录

一、安装PHP5
二、安装PHP7

一、安装PHP5

  • 下载源码包
[root@minglinux-01 /usr/local/src] wget http://cn2.php.net/distributions/php-5.6.30.tar.gz 

  • 解压
[root@minglinux-01 /usr/local/src] tar zxvf php-5.6.30.tar.gz 

  • 初始化
[root@minglinux-01 /usr/local/src] cd php-5.6.30/
[root@minglinux-01 /usr/local/src/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-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 

--prefix 指定安装目录。
--with-apxs2 是apache的一个工具,可以帮助用户自动安装、配置apache的扩展模块,使apache即使不停止或重启也可以被安装新的模块并立即支持。
--with-config-file-path 指定配置文件所在路径,php的配置文件为php.ini。
--with-mysql 指定mysql的路径。
--with-pdo-mysql 这里的三个参数用于定义连接mysql的相关启动或函数。
--with-mysqli 以上为三种不同的mysql的库(驱动),要想让php和mysql通信,需要编译出支持的模块,让mysql和php可以连接。
--其余的是指定php所需的一些模块。

  • 初始化过程出现的错误
  1. configure: error: xml2-config not found. Please check your libxml2 installation.
    解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y libxml2-devel
  2. configure: error: Cannot find OpenSSL's <evp.h>
    解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y openssl openssl-devel
  3. configure: error: Please reinstall the BZip2 distribution
    解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y bzip2 bzip2-devel
  4. configure: error: jpeglib.h not found.
    解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y libjpeg-devel
  5. configure: error: png.h not found.
    解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y libpng libpng-devel
  6. configure: error: freetype-config not found.
    解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y freetype-devel
  7. configure: error: mcrypt.h not found. Please reinstall libmcrypt.
    解决:
    [root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y epel-release
    [root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y libmcrypt-devel
    CentOS默认的yum源没有libmcrypt-devel这个包,这个包在扩展源epel中有,所以需先安装epel yum扩展源。
  • 初始化成功
···
Generating files
configure: creating ./config.status
creating main/internal_functions.c
creating main/internal_functions_cli.c
+--------------------------------------------------------------------+
| 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
[root@minglinux-01 /usr/local/src/php-5.6.30]
[root@minglinux-01 /usr/local/src/php-5.6.30] echo $?
0
  • 编译安装
[root@minglinux-01 /usr/local/src/php-5.6.30] make && make install
[root@minglinux-01 /usr/local/src/php-5.6.30] echo $?
0
  • 复制配置文件
[root@minglinux-01 /usr/local/src/php-5.6.30] cp php.ini-production /usr/local/php/etc/php.ini 

  • 查看php目录和文件
[root@minglinux-01 /usr/local/src/php-5.6.30] ls /usr/local/php/
bin  etc  include  lib  php
[root@minglinux-01 /usr/local/src/php-5.6.30] ls /usr/local/php/bin/  ##该目录存放了php核心二进制文件
pear     pecl  phar.phar  php-cgi     phpize
peardev  phar  php        php-config
[root@minglinux-01 /usr/local/src/php-5.6.30] du -sh /usr/local/php/bin/php
35M /usr/local/php/bin/php
[root@minglinux-01 /usr/local/src/php-5.6.30] du -sh /usr/local/apache2.4/modules/libphp5.so       
36M /usr/local/apache2.4/modules/libphp5.so       ##modules目录下php相关模块文件大小

  • 查看php加载的模块
[root@minglinux-01 /usr/local/src/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
openssl
pcre
PDO
pdo_sqlite
Phar
posix
Reflection
session
SimpleXML
soap
sockets
SPL
sqlite3
standard
tokenizer
xml
xmlreader
xmlwriter
zlib

[Zend Modules]

以上加载的均为静态模块,php之所以这么大是由于增加了很多相关的功能。php是作为httpd的扩展模块形式存在,是不需要启动的。

  • 查看apache的模块
[root@minglinux-01 /usr/local/src/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 fe80::20c:29ff:fe46:125. 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)

最后一行即为Apache的php模块文件。

二、安装PHP7

  • 下载PHP7源码包
[root@minglinux /usr/local/src] wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2

  • 解压
[root@minglinux /usr/local/src] tar jxvf php-7.1.6.tar.bz2
  • 初始化
[root@minglinux /usr/local/src] cd php-7.1.6
[root@minglinux /usr/local/src/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@minglinux /usr/local/src/php-7.1.6] make && make install
  • 查看当前PHP版本
[root@minglinux ~] php -v
PHP 7.0.31 (cli) (built: Jul 20 2018 08:55:22) ( NTS )
Copyright (c) 1997-2017 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2017 Zend Technologies
    with Zend OPcache v7.0.31, Copyright (c) 1999-2017, by Zend Technologies

  • 查看php7加载的模块
[root@minglinux /usr/local/src/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]

  • Apache目前加载了两个php模块
[root@minglinux ~] /usr/local/apache2.4/bin/apachectl -M | grep php
 php5_module (shared)
 php7_module (shared)
  • 在httpd.conf中注释掉不用的模块
[root@minglinux ~] vim /usr/local/apache2.4/conf/httpd.conf
...
#LoadModule php5_module        modules/libphp5.so
LoadModule php7_module        modules/libphp7.so
...
  • 测试PHP是否正确解析
[root@minglinux ~] vim /usr/local/apache2.4/htdocs/2.php
<?php
    echo "正常解析";
?>
[root@minglinux ~] curl localhost/2.php
正常解析
扩展

php中mysql,mysqli,mysqlnd,pdo到底是什么 http://blog.csdn.net/u013785951/article/details/60876816
查看编译参数 http://ask.apelearn.com/question/1295

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,544评论 6 501
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,430评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,764评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,193评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,216评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,182评论 1 299
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,063评论 3 418
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,917评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,329评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,543评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,722评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,425评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,019评论 3 326
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,671评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,825评论 1 269
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,729评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,614评论 2 353

推荐阅读更多精彩内容