您的位置:首页 > 编程语言 > PHP开发

11.10/11.11/11.12 安装PHP511.13安装PHP7

2017-09-28 20:39 519 查看
- 11.10/11.11/11.12 安装PHP5
- 11.13 安装PHP7
- 扩展
- php中mysql,mysqli,mysqlnd,pdo到底是什么
- http://blog.csdn.net/u013785951/article/details/60876816 - 查看编译参数 http://ask.apelearn.com/question/1295 
# 11.10安装PHP5 上

-  PHP官网www.php.net
-  当前主流版本为5.6/7.1

1.   cd /usr/local/src/

2.   wget http://cn2.php.net/distributions/php-5.6.30.tar.gz 
3.   tar zxf php-5.6.30.tar.gz

4.   cd php-5.6.30

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

6.  make && make install

7.  cp php.ini-production  /usr/local/php/etc/php.ini

```
[root@aminglinux-001 ~]# cd /usr/local/src
[root@aminglinux-001 src]# wget http://cn2.php.net/distributions/php-5.6.30.tar.bz2 --2017-09-27 21:39:15--  http://cn2.php.net/distributions/php-5.6.30.tar.bz2 正在解析主机 cn2.php.net (cn2.php.net)... 202.108.35.250, 202.108.35.235
正在连接 cn2.php.net (cn2.php.net)|202.108.35.250|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:15011816 (14M) [application/octet-stream]
正在保存至: “php-5.6.30.tar.bz2”

100%[====================================================>] 15,011,816   880KB/s 用时 19s

2017-09-27 21:39:35 (756 KB/s) - 已保存 “php-5.6.30.tar.bz2” [15011816/15011816])

[root@aminglinux-001 src]# du -sh php-5.6.30.tar.bz2
15M	php-5.6.30.tar.bz2
[root@aminglinux-001 src]#
```
- 先解压
```
[root@aminglinux-001 src]# tar jxvf php-5.6.30.tar.bz2

php-5.6.30/server-tests.php
php-5.6.30/php.ini-development
php-5.6.30/EXTENSIONS
php-5.6.30/README.namespaces
php-5.6.30/pear/
php-5.6.30/pear/install-pear.txt
php-5.6.30/pear/install-pear-nozlib.phar
php-5.6.30/pear/fetch.php
php-5.6.30/pear/Makefile.frag
php-5.6.30/README.SUBMITTING_PATCH
[root@aminglinux-001 src]#
```
- 编译
- --with-apxs2=/usr/local/apache2.4/bin/apxs  指定apache的
- --with-mysql=/usr/local/mysql    指定mysql的 (PHP7 用不到这个)
- --with-mysqli=/usr/local/mysql/bin/mysql_config    指定mysql的
```
[root@aminglinux-001 src]# cd php-5.6.30/
[root@aminglinux-001 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

Configuring extensions
checking size of long... (cached) 8
checking size of int... (cached) 4
checking for int32_t... yes
checking for uint32_t... yes
checking for sys/types.h... (cached) yes
checking for inttypes.h... (cached) yes
checking for stdint.h... (cached) yes
checking for string.h... (cached) yes
checking for stdlib.h... (cached) yes
checking for strtoll... yes
checking for atoll... yes
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@aminglinux-001 php-5.6.30]#    这里报错了,运行echo $?
[root@aminglinux-001 php-5.6.30]# echo $?
1
[root@aminglinux-001 php-5.6.30]# echo $?
0
[root@aminglinux-001 php-5.6.30]#

```
-  configure: error: xml2-config not found. Please check your libxml2 installation. 搜下xml2
```
[root@aminglinux-001 php-5.6.30]# yum list | grep xml2
libxml2.x86_64                          2.9.1-6.el7_2.3                @anaconda
libxml2.i686                            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 epel
tinyxml2-devel.x86_64                   2.1.0-2.20140406git6ee53e7.el7 epel
xml2.x86_64                             0.5-7.el7                      epel
[root@aminglinux-001 php-5.6.30]#
```
- 我们需要的库一帮都是 -devel 的包
```
[root@aminglinux-001 php-5.6.30]# yum install -y libxml2-devel

已安装:
libxml2-devel.x86_64 0:2.9.1-6.el7_2.3

作为依赖被安装:
xz-devel.x86_64 0:5.2.2-1.el7                 zlib-devel.x86_64 0:1.2.7-17.el7

完毕!
完了再次编译,
[root@aminglinux-001 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 use system default cipher list instead of hardcoded value... no
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@aminglinux-001 php-5.6.30]#
```
- 这里又报错了 configure: error: Cannot find OpenSSL's <evp.h>
```

[root@aminglinux-001 php-5.6.30]# yum install -y openssl-devel

已安装:
openssl-devel.x86_64 1:1.0.2k-8.el7

作为依赖被安装:
keyutils-libs-devel.x86_64 0:1.5.8-3.el7           krb5-devel.x86_64 0:1.15.1-8.el7
libcom_err-devel.x86_64 0:1.42.9-10.el7            libkadm5.x86_64 0:1.15.1-8.el7
libselinux-devel.x86_64 0:2.5-11.el7               libsepol-devel.x86_64 0:2.5-6.el7
libverto-devel.x86_64 0:0.2.5-4.el7

作为依赖被升级:
e2fsprogs.x86_64 0:1.42.9-10.el7               e2fsprogs-libs.x86_64 0:1.42.9-10.el7
krb5-libs.x86_64 0:1.15.1-8.el7                libcom_err.x86_64 0:1.42.9-10.el7
libselinux.x86_64 0:2.5-11.el7                 libselinux-python.x86_64 0:2.5-11.el7
libselinux-utils.x86_64 0:2.5-11.el7           libss.x86_64 0:1.42.9-10.el7
openssl.x86_64 1:1.0.2k-8.el7                  openssl-libs.x86_64 1:1.0.2k-8.el7

完毕!
[root@aminglinux-001 php-5.6.30]#

再继续 编译 ./configure

完毕!
[root@aminglinux-001 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@aminglinux-001 php-5.6.30]#
```
- 又出来一个新的错误  configure: error: Please reinstall the BZip2 distribution

# 11.11安装PHP5 中
- 继续上面的错误configure: error: Please reinstall the BZip2 distribution
```
checking for BZip2 support... yes
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
[root@aminglinux-001 php-5.6.30]# yum install -y bzip2-devel

已安装:
bzip2-devel.x86_64 0:1.0.6-13.el7

完毕!
[root@aminglinux-001 php-5.6.30]#
```
- 再来继续编译./configure
```
[root@aminglinux-001 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@aminglinux-001 php-5.6.30]#
```
- 又出错了error: jpeglib.h not found.
```
[root@aminglinux-001 php-5.6.30]# yum install -y libjpeg-devel

已安装:
libjpeg-turbo-devel.x86_64 0:1.2.90-5.el7

完毕!
[root@aminglinux-001 php-5.6.30]#
```
- 再继续编译./configure
```
[root@aminglinux-001 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

If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
[root@aminglinux-001 php-5.6.30]#

If configure fails try --with-vpx-dir=<DIR>
checking for jpeg_read_header in -ljpeg... yes
configure: error: png.h not found.
[root@aminglinux-001 php-5.6.30]#
```
- 又报错了error: png.h not found,这次是要安装png
```
[root@aminglinux-001 php-5.6.30]# yum install -y libpng-devel

已安装:
libpng-devel.x86_64 2:1.5.13-7.el7_2

完毕!
[root@aminglinux-001 php-5.6.30]#
```
- 继续
```

完毕!
[root@aminglinux-001 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

If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
[root@aminglinux-001 php-5.6.30]#
```
- 又报错 error: freetype-config not found
```
[root@aminglinux-001 php-5.6.30]# yum install -y freetype-devel

已安装:
freetype-devel.x86_64 0:2.4.11-15.el7

作为依赖被升级:
freetype.x86_64 0:2.4.11-15.el7

完毕!
[root@aminglinux-001 php-5.6.30]#
```
- 继续./configure
```

完毕!
[root@aminglinux-001 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 stdarg.h... (cached) yes
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
[root@aminglinux-001 php-5.6.30]#
```
- 又报错了error: mcrypt.h not found. Please reinstall libmcrypt.
- 安装这个mcrypt , mcrypt库 在epel扩展源里面,所以想要安装mcrypt 先需要先安装epel 扩展源(yum install epel-release),
```
[root@aminglinux-001 php-5.6.30]# yum install libmcrypt-devel

依赖关系解决

================================================================================================
Package                     架构               版本                     源                大小
================================================================================================
正在安装:
libmcrypt-devel             x86_64             2.5.8-13.el7             epel              13 k
为依赖而安装:
libmcrypt                   x86_64             2.5.8-13.el7             epel              99 k

事务概要
================================================================================================
安装  1 软件包 (+1 依赖软件包)

总下载量:112 k
安装大小:302 k
Is this ok [y/d/N]: y

已安装:
libmcrypt-devel.x86_64 0:2.5.8-13.el7

作为依赖被安装:
libmcrypt.x86_64 0:2.5.8-13.el7

完毕!
[root@aminglinux-001 php-5.6.30]#

```
- 再来一次
```
[root@aminglinux-001 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

creating libtool
appending configuration tag "CXX" to libtool

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@aminglinux-001 php-5.6.30]#

[root@aminglinux-001 php-5.6.30]# echo $?
0
[root@aminglinux-001 php-5.6.30]#

```

- 成功了!
- 下一步接着就是 make  这一步花费的时间长一点

# 11.12安装PHP5 下
```
[root@aminglinux-001 php-5.6.30]# make

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
clicommand.inc
directorytreeiterator.inc
invertedregexiterator.inc
directorygraphiterator.inc
pharcommand.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

[root@aminglinux-001 php-5.6.30]#
```
- 最后一步 make install
```

Build complete.
Don't forget to run 'make test'.

[root@aminglinux-001 php-5.6.30]# make install

Wrote PEAR system config file at: /usr/local/php/etc/pear.conf
You may want to add: /usr/local/php/lib/php to your php.ini include_path
/usr/local/src/php-5.6.30/build/shtool install -c ext/phar/phar.phar /usr/local/php/bin
ln -s -f phar.phar /usr/local/php/bin/phar
Installing PDO headers:           /usr/local/php/include/php/ext/pdo/
[root@aminglinux-001 php-5.6.30]#
```
- 看下php的目录
```
[root@aminglinux-001 php-5.6.30]# ls /usr/local/php/
bin  etc  include  lib  php
核心的二进制文件
[root@aminglinux-001 php-5.6.30]# ls /usr/local/php/bin/
pear  peardev  pecl  phar  phar.phar  php  php-cgi  php-config  phpize
[root@aminglinux-001 php-5.6.30]# du -sh /usr/local/php/bin/php
36M	/usr/local/php/bin/php
[root@aminglinux-001 php-5.6.30]#
```
```
[root@aminglinux-001 php-5.6.30]# du -sh /usr/local/apache2.4/modules/libphp5.so
37M	/usr/local/apache2.4/modules/libphp5.so
[root@aminglinux-001 php-5.6.30]#
```
- 这个/usr/local/apache2.4/modules/libphp5.so 就是我们想要的模块,php和apache结合起来是通过这个文件实现的

- 看一看php所加载的模块都有哪些 ,查看它加载模块的一个命令,这全是静态的
- /usr/local/php/bin/php -m  这个和httpd -M类似的功能
```
[root@aminglinux-001 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]

[root@aminglinux-001 php-5.6.30]#
```

- 那php 需不需要启动?
![mark](http://oqxf7c508.bkt.clouddn.com/blog/20170927/225931610.png?imageslim)

php 作为apache的模块存在的,
看看apache的模块
```
[root@aminglinux-001 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::a152:bbdf:8b2b:db9b. 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)
[root@aminglinux-001 php-5.6.30]#
```
-  这个就是它的模块文件
```
[root@aminglinux-001 php-5.6.30]# ls -l /usr/local/apache2.4/modules/libphp5.so
-rwxr-xr-x 1 root root 37752696 9月  27 22:45 /usr/local/apache2.4/modules/libphp5.so
[root@aminglinux-001 php-5.6.30]#
```

-  这个是Apache的配置文件,打开它
-  如果不想用哪个模块,直接把它注释掉 前面加个#就行 ,随用随取
```

[root@aminglinux-001 php-5.6.30]# vi /usr/local/apache2.4/conf/httpd.conf

LoadModule status_module modules/mod_status.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule info_module modules/mod_info.so
#LoadModule cgid_module modules/mod_cgid.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
#LoadModule actions_module modules/mod_actions.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module        modules/libphp5.so

<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
Group daemon
```

- 接下来 把配置文件php.ini-prodution 这是它的一个参考配置文件 拷贝到/usr/local/php/etc/php.ini

- 为什么要放在这 ?   因为之前定义了这个位置,

- 使用-i 可以查看详细信息,参数
```

[root@aminglinux-001 php-5.6.30]# /usr/local/php/bin/php -i |less

phpinfo()
PHP Version => 5.6.30

System => Linux aminglinux-001 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Sep 27 2017 22:41:39
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
```
-可以看到Loaded Configuration File => (none)

- 把php.ini-production 生产环境中 这个文件拷贝到 /usr/local/php/etc/php.ini
```
[root@aminglinux-001 php-5.6.30]# ls -l /usr/local/apache2.4/modules/libphp5.so
-rwxr-xr-x 1 root root 37752696 9月  27 22:45 /usr/local/apache2.4/modules/libphp5.so
[root@aminglinux-001 php-5.6.30]# vi /usr/local/apache2.4/conf/httpd.conf
[root@aminglinux-001 php-5.6.30]# /usr/local/php/bin/php -i |less
[root@aminglinux-001 php-5.6.30]# ls /usr/local/php/etc
pear.conf
[root@aminglinux-001 php-5.6.30]# cp php.ini-production /usr/local/php/etc/php.ini
[root@aminglinux-001 php-5.6.30]# /usr/local/php/bin/php -i|less
````

```
System => Linux aminglinux-001 3.10.0-514.el7.x86_64 #1 SMP Tue Nov 22 16:42:41 UTC 2016 x86_64
Build Date => Sep 27 2017 22:41:39
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 => /usr/local/php/etc/php.ini
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
:...skipping...
```
-  现在有了加载的配置文件 Loaded Configuration File => /usr/local/php/etc/php.ini

# 11.13 安装PHP 7

-  cd /usr/local/src/
-  wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2 -  tar zxf php-7.1.6.tar.bz2
-  cd 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
-  make && make install
-  ls /usr/local/apache2.4/modules/libphp7.so
-  cp php.ini-production  /usr/local/php7/etc/php.ini

```
[root@aminglinux-001 php-5.6.30]# cd ..
[root@aminglinux-001 src]#

[root@aminglinux-001 src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2 --2017-09-27 23:40:28--  http://cn2.php.net/distributions/php-7.1.6.tar.bz2 ```
- 解压
```
[root@aminglinux-001 src]# tar jxvf php-7.1.6.tar.bz2

php-7.1.6/win32/winutil.c
php-7.1.6/win32/ioutil.c
php-7.1.6/win32/fnmatch.h
php-7.1.6/win32/ftok.c
php-7.1.6/win32/select.c
[root@aminglinux-001 src]#
```
- cd php-7.1.6/
- ./configure
```
[root@aminglinux-001 src]# cd php-7.1.6/
[root@aminglinux-001 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

creating libtool
appending configuration tag "CXX" to libtool

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 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
[root@aminglinux-001 php-7.1.6]#

```
- make 这个时间有点长 要10多分钟
```
[root@aminglinux-001 php-7.1.6]# make

Generating phar.php
Generating phar.phar
PEAR package PHP_Archive not installed: generated phar will require PHP's phar extension be enabled.
directorytreeiterator.inc
directorygraphiterator.inc
pharcommand.inc
clicommand.inc
invertedregexiterator.inc
phar.inc

Build complete.
Don't forget to run 'make test'.

[root@aminglinux-001 php-7.1.6]#
```

-  make install
```
[root@aminglinux-001 php-7.1.6]# make install

Installing man pages:             /usr/local/php7/php/man/man1/
page: phpize.1
page: php-config.1
Installing PEAR environment:      /usr/local/php7/lib/php/
[PEAR] Archive_Tar    - installed: 1.4.2
[PEAR] Console_Getopt - installed: 1.4.1
[PEAR] Structures_Graph- installed: 1.1.1
[PEAR] XML_Util       - installed: 1.4.2
[PEAR] PEAR           - installed: 1.10.4
Wrote PEAR system config file at: /usr/local/php7/etc/pear.conf
You may want to add: /usr/local/php7/lib/php to your php.ini include_path
/usr/local/src/php-7.1.6/build/shtool install -c ext/phar/phar.phar /usr/local/php7/bin
ln -s -f phar.phar /usr/local/php7/bin/phar
Installing PDO headers:           /usr/local/php7/include/php/ext/pdo/
[root@aminglinux-001 php-7.1.6]#
```

```
[root@aminglinux-001 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so
[root@aminglinux-001 php-7.1.6]# du -sh !$
du -sh /usr/local/apache2.4/modules/libphp7.so
37M	/usr/local/apache2.4/modules/libphp7.so
[root@aminglinux-001 php-7.1.6]#

[root@aminglinux-001 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@aminglinux-001 php-7.1.6]#
```
- 可以看下
```
[root@aminglinux-001 php-7.1.6]# !vim
vim /etc/init.d/mariadb

# Safeguard (relative paths, core dumps..)
cd $basedir

echo $echo_n "Starting MySQL"
if test -x $bindir/mys

[root@aminglinux-001 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf
#LoadModule authz_dbd_module modules/mod_authz_dbd.so
LoadModule autoindex_module modules/mod_autoindex.so
#LoadModule info_module modules/mod_info.so
#LoadModule cgid_module modules/mod_cgid.so
#LoadModule dav_fs_module modules/mod_dav_fs.so
#LoadModule vhost_alias_module modules/mod_vhost_alias.so
#LoadModule negotiation_module modules/mod_negotiation.so
LoadModule dir_module modules/mod_dir.so
#LoadModule actions_module modules/mod_actions.so
#LoadModule speling_module modules/mod_speling.so
#LoadModule userdir_module modules/mod_userdir.so
LoadModule alias_module modules/mod_alias.so
#LoadModule rewrite_module modules/mod_rewrite.so
LoadModule php5_module        modules/libphp5.so
LoadModule php7_module        modules/libphp7.so

<IfModule unixd_module>
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.
#
# User/Group: The name (or #number) of the user/group to run httpd as.
# It is usually good practice to create a dedicated user and group for
# running httpd, as with most system services.
#
User daemon
150,12        28%
```

- LoadModule php5_module        modules/libphp5.so
LoadModule php7_module        modules/libphp7.so
- 不想用哪个可以注释掉哪个

- 扩展
- php中mysql,mysqli,mysqlnd,pdo到底是什么
- http://blog.csdn.net/u013785951/article/details/60876816 名词解释:

最开始的初学者,往往搞不清mysqli,mysqlnd,pdo到底是什么,下面先直接贴出最直观的名字吧。
```
MYSQL:This extension is deprecated as of PHP 5.5.0, and has been removed as of PHP 7.0.0.
MYSQLI: MySQL Improved Extension
MySQLND: MySQL Native Drive
PDO:The PHP Data Objects。extension defines a lightweight, consistent interface for accessing databases in PHP。
以上摘自 PHP官方手册: http://php.net/manual/en/book.mysqli.php 
用中文说:
MYSQL 也叫 Original MySQL,PHP4版本的MYSQL扩展,从PHP5起已经被废弃,并别从PHP7开始已经被移除。

MYSQLI 叫做 “MySQL增强扩展”。

MYSQLND MYSQL NATIVE DIRVER 叫做MYSQL “官方驱动”或者更加直接点的叫做“原生驱动”

PDO PHP Data Objects PHP数据对象,是PHP应用中的一个数据库抽象层规范。
```
针对本篇文章

再补充几个名词解释:

1 什么是API?

一个应用程序接口(Application Programming Interface的缩写),定义了类,方法,函数,变量等等一切 你的应用程序中为了完成特定任务而需要调用的内容。在PHP应用程序需要和数据库进行交互的时候所需要的API 通常是通过PHP扩展暴露出来(给终端PHP程序员调用)。
上文所说的MYSQL 和MYSQLI扩展就提供了这样的API。

2什么是驱动?

驱动是一段设计用来于一种特定类型的数据库服务器进行交互的软件代码。驱动可能会调用一些库,比如MySQL客户端库或者MySQL Native驱动库。 这些库实现了用于和MySQL数据库服务器进行交互的底层协议。
在PHP拓展的角度上看,MYSQL和MYSQLi还是比较上层的拓展,依赖更底层的库去连接和访问数据库。
上文所说的MYSQLND 就是所说的底层的数据库驱动。当然,还有一个驱动叫做libmysqlclient。至于如何选择使用这两种驱动的哪一种,请看这里选择哪一种底层数据库驱动。

总的来说:

从应用的层面上看,我们通过PHP 的MYSQL或者MYSQLi扩展提供的API去操作数据库。

从底层来看,MYSQLND提供了底层和数据库交互的支持(可以简单理解为和MySQL server进行网络协议交互)。

而PDO,则提供了一个统一的API接口,使得你的PHP应用不去关心具体要连接的数据库服务器系统类型。也就是说,如果你使用PDO的API,可以在任何需要的时候无缝切换数据库服务器。比如MYSQL,SQLITE任何数据库都行。

即从大部分功能上看,PDO提供的API接口和MYSQLI提供的接口对于普通的增删改查效果是一致的。

最后贴下代码:

MYSQL连接:
```
<?php

$conn = @ mysql_connect("localhost", "root", "") or die("数据库连接错误");

mysql_select_db("bbs", $conn);

mysql_query("set names 'utf8'");

echo "数据库连接成功";

?>
1
2
3
4
5
6
7
8
9
10
11
MYSQLI连接:

<?php

$conn = mysqli_connect('localhost', 'root', '', 'bbs');

if(!$conn){

die("数据库连接错误" . mysqli_connect_error());

}else{

echo"数据库连接成功";

}

?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
PDO连接:

<?php

try{

$pdo=new pdo("mysql:host=localhost;dbname=bbs","root","");

}catch(PDDException $e){

echo"数据库连接错误";

}

echo"数据库连接成功";

?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
想更多去了解他们的区别和联系,可以手动去编译一下PHP的源代码。注意参数

--enable-pdo
--with-pdo-mysql
--enable-mysqlnd
--with-mysqli
--with-mysql//php7的已经不再支持,此参数configure 的时候会报ERROR

```
- 查看编译参数 http://ask.apelearn.com/question/1295[/code] 
                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  PHP 安装