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
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=
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
If configure fails try --with-vpx-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=
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
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 需不需要启动?

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
#
# 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
- 为什么要放在这 ? 因为之前定义了这个位置,
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]#
#
# 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连接:
```