11.10/11.11/11.12 安装PHP5
PHP官网
www.php.net
当前主流版本为5.6/7.1
cd /usr/local/src/
tar zxf php-5.6.30.tar.gz
cd php-5.6.30
./configure --prefix(安装目录)=/usr/local/php --with-apxs2(Apache工具,自动扩展模块放置Apache /usr/local/apache/modules/目录中,并且在配置文件中加入load module,自动配置httpd -M时加载出来)=/usr/local/apache2.4/bin/apxs --with-config-file-path(指定PHP配置文件所在路径,PHP的配置文件是php.ini)=/usr/local/php/etc --with-mysql(mysql路径,老版本)=/usr/local/mysql --with-pdo-mysql=/usr/local/mysql --with-mysqli(新版本centos7)=/usr/local/mysql/bin/mysql_config (后面参数PHP指定模块)--with-libxml-dir --with-gd --with-jpeg-dir --with-png-dir --with-freetype-dir --with-iconv-dir --with-zlib-dir --with-bz2 --with-openssl--enable-soap--enable-mbstring --enable-sockets --enable-exif
注:mysql、pdo-mysql、mysqli三种驱动、三种库 原因:想让PHP与mysql通信首先编译出支持通信模块,识别PHP代码中定义链接mysql命令代码的驱动、函数(如网卡没有驱动程序才能识别)
make && make install
cp php.ini-production /usr/local/php/etc/php.ini
[root
@test ~]# cd /usr/local/src/
[root
@test src]# wget
http://php.net/distributions/php-5.6.38.tar.gz
解压
[root
@test src]# tar -zxvf php-5.6.38.tar.gz
进入php-5.6.38目录
[root
@test src]# cd php-5.6.38/
配置参数
[root
@test php-5.6.38]# ./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/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--enable-soap--enable-mbstring --enable-sockets --enable-exif
报错1:
configure: error: xml2-config not found. Please check your libxml2 installation.
[root@test php-5.6.38]# yum list |grep libxml2
[root@test php-5.6.38]# yum install -y libxml2-devel.x86_64
报错2:
configure: error: Please reinstall the BZip2 distribution
[root@test php-5.6.38]# yum list |grep -i BZip2
[root@test php-5.6.38]# yum install -y bzip2-devel.x86_64
报错3:
configure: error: jpeglib.h not found.
[root@test php-5.6.38]# yum list |grep -i libjpeg
[root@test php-5.6.38]# yum install -y libjpeg-turbo-devel.x86_64
报错4:
configure: error: png.h not found.
[root@test php-5.6.38]# yum list |grep -i png
[root@test php-5.6.38]# yum install -y libpng-devel.x86_64
报错5:
configure: error: freetype-config not found.
[root@test php-5.6.38]# yum list |grep -i freetype
[root@test php-5.6.38]# yum install -y freetype-devel.x86_64
报错6:
configure: error: Cannot find libmysqlclient_r under /usr/local/mysql.
Note that the MySQL client library is not bundled anymore!
其实这跟PHP没有关系,那是因为在编译APACHE的时候,使用--with-mpm模块,所以就必须在编译MYSQL的时候加上--enable-thread-safe-client.参数
这是PHP5.2的一个改进,在PHP5.2.0之前的版本都不需要MYSQL启用安全线程。关于--enable-thread-safe-client项的官方介绍如下:如何生成线程式客户端库总是线程安全的。最大的问题在于从套接字读取的net.c中的子程序并不是中断安全的。或许你可能希望用自己的告警中断对服务器的长时间读取,以此来解决问题。如果为SIGPIPE中断安装了中断处理程序,套接字处理功能应是线程安全的。SupeSite/X-为了避免连接中断时放弃程序,MySQL将在首次调用mysql_server_init()、mysql_init()或mysql_connect()时屏蔽SIGPIPE。如果你打算使用自己的SIGPIPE处理程序,首先应调用mysql_server_init(),然后安装你的处理程序.
还有第二种解决方法比较方便:编译之前,先处理一下mysql的库,默认查找libmysqlclient_r.so,可是mysql默认为libmysqlclient.so,内容完全一样,做个链接即可
[root@test php-5.6.38]# cd /usr/local/mysql/lib/
[root@test lib]# ls
libcrypto.so libmysqlclient.a libmysqlclient.so.21 libmysqlservices.a libssl.so.1.0.0 pkgconfig
libcrypto.so.1.0.0 libmysqlclient.so libmysqlclient.so.21.0.12 libssl.so mecab plugin
[root@test lib]# ln -s libmysqlclient.so.21.0.12 libmysqlclient_r.so
配置成功
编译
[root@test php-5.6.38]# make
报错:
/usr/local/src/php-5.6.38/ext/mysqli/php_mysqli_structs.h:63:23: 致命错误:my_global.h:没有那个文件或目录
解决方法重新配置参数
--enable-mysqlnd --with-mysqli
[root@test php-5.6.38]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/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
--enable-mysqlnd --with-mysqli
报错:
usr/local/src/php-5.6.38/ext/pdo_mysql/php_pdo_mysql_int.h:138:2: 错误:未知的类型名‘my_bool’
my_bool *in_null;
解决方法
[root@test php-5.6.38]#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache/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 --enable-mysqlnd --with-mysqli
--with-pdo_mysql
编译完毕
安装
[root@test php-5.6.38]# make install
将参考配置文件需要放置到安装路径下,在配置时已经定义:--with-config-file-path=/usr/local/php/etc
参考配置文件有两种:
php.ini-production 线上生产环境使用
php.ini-development 开发环境使用
[root@test php-5.6.38]# cp php.ini-production /usr/local/php/etc/php.ini
查看PHP信息,编译参数,路径等
[root@test php-5.6.38]# /usr/local/php/bin/php -i |less
核心配置文件
[root@test php-5.6.38]# ls /usr/local/php/bin/php
/usr/local/php/bin/php
扩展模块,PHP和Apache结合起来的模块libphp5.so
[root@test php-5.6.38]# ls /usr/local/apache/modules/libphp5.so
/usr/local/apache/modules/libphp5.so
PHP加载的模块(静态模块)
[root@test php-5.6.38]# /usr/local/php/bin/php -m
查看Apache模块加载情况 php5_module (shared)
Apache配置文件
[root@test php-5.6.38]# vim /usr/local/apache/conf/httpd.conf
注:想用模块就把#去掉,不需要就加上#
11.13 安装PHP7
注:一台机子上可以有两个版本的PHP版本,但是在Apache调用配置上要配置好选择
cd /usr/local/src/
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 --enable-soap --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@test ~]# cd /usr/local/src/
[root@test src]# wget
http://php.net/distributions/php-7.2.12.tar.gz
解压
[root@test src]# tar -zxvf php-7.2.12.tar.gz
[root@test src]# cd php-7.2.12/
[root@test php-7.2.12]#
配置
[root@test php-7.2.12]#./configure --prefix=/usr/local/php7 --with-apxs2=/usr/local/apache/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 --enable-soap --enable-mbstring --enable-sockets --enable-exif --enable-mysqlnd --with-mysqli --with-pdo_mysql
编译
[root@test php-7.2.12]# make
安装
[root@test php-7.2.12]# make install
PHP7模块
[root@test php-7.2.12]# ls /usr/local/apache/modules/libphp7.so
/usr/local/apache/modules/libphp7.so
选择使用PHP模块
[root@test php-7.2.12]# vim /usr/local/apache/conf/httpd.conf