1 php5安装
系统环境是centos7.5
PHP官网www.php.net
当前主流版本为5.6/7.1
下载php5包:
[root@linux01 ~]# cd /usr/local/src/
[root@linux01 src]# wget http://cn2.php.net/distributions/php-5.6.32.tar.gz
--2018-11-13 22:26:48-- http://cn2.php.net/distributions/php-5.6.32.tar.gz
Resolving cn2.php.net (cn2.php.net)... 36.51.255.144
Connecting to cn2.php.net (cn2.php.net)|36.51.255.144|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 19294956 (18M) [application/x-gzip]
Saving to: ‘php-5.6.32.tar.gz’
100%[====================================================>] 19,294,956 245KB/s in 87s
2018-11-13 22:28:16 (216 KB/s) - ‘php-5.6.32.tar.gz’ saved [19294956/19294956]
解压包:
[root@linux01 src]# tar zxf php-5.6.32.tar.gz
[root@linux01 src]# cd php-5.6.32
编译php5包,configure
步骤:
[root@linux01 php-5.6.32]# ./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
提示信息:
以上省略:
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: main/php_config.h is unchanged
config.status: executing default commands
[root@linux01 php-5.6.32]# echo $?
0
这样configure
编译就完成了
进入make
和make install
[root@linux01 php-5.6.32]# make && make install
以上省略...
Installing PEAR environment: /usr/local/php/lib/php/
[PEAR] Archive_Tar - installed: 1.4.3
[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.5
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.32/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@linux01 php-5.6.32]# echo $?
0
这样make && make install
就编译完成
查看安装的php目录:
[root@linux01 php-5.6.32]# ls /usr/local/php/
bin etc include lib php
[root@linux01 php-5.6.32]# ls /usr/local/php/bin/
pear peardev pecl phar phar.phar php php-cgi php-config phpize
查看文件大小:
[root@linux01 php-5.6.32]# du -sh /usr/local/php/bin/php
36M /usr/local/php/bin/php
[root@linux01 php-5.6.32]# du -sh /usr/local/apache2.4/modules/libphp5.so
36M /usr/local/apache2.4/modules/libphp5.so
备注:现在把/usr/local/php/bin/php这个目录删掉是可以的,因为需要的是/usr/local/apache2.4/modules/libphp5.so这个php编译生成的模块
查看php加载的模块:
[root@linux01 php-5.6.32]# /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]
不过以上的这些模块是静态的模块;实际上也可以支持扩展模块以.so结束文件
mysql,Apache服务启动了,而php是以模块存在这个lamp架构的,所以不需要启动php,php5_module
这个模块很重要,删除了就不支持php解析了
[root@linux01 src]# /usr/local/apache2.4/bin/httpd -M
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.139.111. Set the 'ServerName' directive globally to suppress this message (这个不是Apache服务报错,是因为没有定义ServerName域名,修改配置文件开启域名定义就可以了)
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)
查看php的模块文件:
[root@linux01 php-5.6.32]# ls -l /usr/local/apache2.4/modules/libphp5.so
-rwxr-xr-x 1 root root 37735360 Nov 13 20:33 /usr/local/apache2.4/modules/libphp5.so
查看Apache配置文件里增加的php模块
[root@linux01 php-5.6.32]# vim /usr/local/apache2.4/conf/httpd.conf
备注:如果不想用这个模块,在前面加上#
即可注释掉
拷贝php.ini配置文件,因为前面的configure这一步定义了配置文件的路径:
./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
还有另外一种办法找配置文件的路径:
[root@linux01 php-5.6.32]# /usr/local/php/bin/php -i | less
phpinfo()
PHP Version => 5.6.32
System => Linux linux01 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64
Build Date => Nov 13 2018 20:31:36
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 (没添加之前是显示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.ini-production
-> 生产环境使用
php.ini-development
-> 开发环境使用
这里选择生产环境使用的配置文件:
[root@linux01 php-5.6.32]# cp php.ini-production /usr/local/php/etc/php.ini
编译源码包时,出现的问题:
1)
checking for xml2-config path...
configure: error: xml2-config not found. Please check your libxml2 installation.
解决办法:
[root@worker1 php-5.6.32]# yum install -y libxml2-devel
2)
checking for pkg-config... /usr/bin/pkg-config
configure: error: Cannot find OpenSSL's <evp.h>
解决办法:
[root@worker1 php-5.6.32]# yum install -y openssl-devel
3)
checking for BZip2 in default path... not found
configure: error: Please reinstall the BZip2 distribution
解决办法:
[root@worker1 php-5.6.32]# yum install -y bzip2-devel
4)
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@worker1 php-5.6.32]# yum install -y libjpeg-devel
5)
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@worker1 php-5.6.32]# yum install -y libpng-devel
6)
checking for png_write_image in -lpng... yes
If configure fails try --with-xpm-dir=<DIR>
configure: error: freetype-config not found.
解决办法:
[root@worker1 php-5.6.32]# yum install -y freetype-devel
7)
checking for mcrypt support... yes
configure: error: mcrypt.h not found. Please reinstall libmcrypt.
解决办法:
[root@worker1 php-5.6.32]# yum install -y libmcrypt-devel
2 php7安装
下载php7包:
[root@linux01 ~]# cd /usr/local/src/
[root@linux01 src]# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
--2018-11-13 22:30:03-- http://cn2.php.net/distributions/php-7.1.6.tar.bz2
Resolving cn2.php.net (cn2.php.net)... 36.51.255.144
Connecting to cn2.php.net (cn2.php.net)|36.51.255.144|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15732452 (15M) [application/octet-stream]
Saving to: ‘php-7.1.6.tar.bz2’
100%[====================================================>] 15,732,452 227KB/s in 80s
2018-11-13 22:31:23 (192 KB/s) - ‘php-7.1.6.tar.bz2’ saved [15732452/15732452]
解压包:
[root@linux01 src]# tar jxf php-7.1.6.tar.bz2
[root@linux01 src]# cd php-7.1.6
编译php7包:(与php5不同的是没有了--with-mysql=/usr/local/mysql
这个选项)
[root@linux01 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
以上省略..
+--------------------------------------------------------------------+
| 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@linux01 php-7.1.6]# echo $?
0
这样就configure编译成功了
进入make
和make install
阶段:
[root@linux01 php-7.1.6]#make && make install
以上省略...
program: phpize
program: php-config
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@linux01 php-7.1.6]# echo $?
0
这样就make && make install
编译成功了
查看编译好的php7模块:
[root@linux01 php-7.1.6]# ls /usr/local/apache2.4/modules/libphp7.so
/usr/local/apache2.4/modules/libphp7.so
查看模块大小:
[root@linux01 php-7.1.6]# du -sh /usr/local/apache2.4/modules/libphp7.so
37M /usr/local/apache2.4/modules/libphp7.so
查看Apache是否加载了php7模块:
[root@linux01 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 192.168.139.111. 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)
查看Apache配置的配置文件:
[root@linux01 php-7.1.6]# vim /usr/local/apache2.4/conf/httpd.conf
如果不需要哪个模块就在前面加#注释掉,两个模块不能同时开启
拷贝php.ini配置文件:
[root@linux01 php-7.1.6]# /usr/local/php7/bin/php -i | less
phpinfo()
PHP Version => 7.1.6
System => Linux linux01 3.10.0-862.el7.x86_64 #1 SMP Fri Apr 20 16:44:24 UTC 2018 x86_64
Build Date => Nov 13 2018 22:39:43
Configure Command => './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'
Server API => Command Line Interface
Virtual Directory Support => enabled
Configuration File (php.ini) Path => /usr/local/php7/etc
Loaded Configuration File => (none) (还没拷贝配置文件前是none)
Scan this dir for additional .ini files => (none)
Additional .ini files parsed => (none)
PHP API => 20160303
PHP Extension => 20160303
Zend Extension => 320160303
Zend Extension Build => API320160303,TS
PHP Extension Build => API20160303,TS
拷贝配置文件:
[root@linux01 php-7.1.6]# cp php.ini-production /usr/local/php7/etc/php.ini
拓展:
php中mysql,mysqli,mysqlnd,pdo到底是什么 http://blog.csdn.net/u013785951/article/details/60876816
查看编译参数 http://ask.apelearn.com/question/1295