目录
一、安装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所需的一些模块。
- 初始化过程出现的错误
- 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
- configure: error: Cannot find OpenSSL's <evp.h>
解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y openssl openssl-devel
- configure: error: Please reinstall the BZip2 distribution
解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y bzip2 bzip2-devel
- configure: error: jpeglib.h not found.
解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y libjpeg-devel
- configure: error: png.h not found.
解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y libpng libpng-devel
- configure: error: freetype-config not found.
解决:[root@minglinux-01 /usr/local/src/php-5.6.30] yum install -y freetype-devel
- 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