三十九安装PHP5安装PHP7
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了三十九安装PHP5安装PHP7相关的知识,希望对你有一定的参考价值。
一、安装php5
PHP官网www.php.net。主流版本5.6,7.1。
如果你的程序,PHP代码能用PHP7就用7,不能用就用5,PHP7的性能有很大提升。
# cd /usr/local/src/
# wget http://cn2.php.net/distributions/php-5.6.30.tar.gz
# tar zxvf php-5.6.30.tar.gz
# cd php-5.6.30 要进这个里面不然./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
解析:
--prefix=/usr/local/php 指定安装目录
--with-apxs2=/usr/local/apache2.4/bin/apxs Apache的一个工具,它能让扩展模块自动的放到Apache的modules目录里,并且在配置文件里加一行lodmodule,自动配置上,能httpd -M加载出来这个模块。能帮你自动配置扩展模块。
--with-config-file-path=/usr/local/php/etc 指定配置文件所在路径,PHP的配置文件叫php.ini
--with-mysql=/usr/local/mysql 指定mysql的路径,三种不同的mysql驱动,或者是指定它的库,就好比需要识别网卡的驱动。老版本用这条
--with-pdo-mysql=/usr/local/mysql
--with-mysqli=/usr/local/mysql/bin/mysql_config 新版本用mysqli
--with-libxml-dir 后续的这些都是指定PHP所需要的一些模块,没有特殊要求就按照这些编译即可。
--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
安装PHP前要先安装mysql和Apache,因为这里的参数要指向他们。
输完该命令后,反馈有一条错误:
configure: error: xml2-config not found. Please check your libxml2 installation.
# yum list |grep xml2
# yum install -y libxml2-devel
# ./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
反馈了一条configure: error: Cannot find OpenSSL's <evp.h>
# yum install -y openssl-devel
# ./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
反馈了一条configure: error: Please reinstall the BZip2 distribution
# yum install -y bzip2-devel
# ./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
反馈一条configure: error: jpeglib.h not found.
# yum install -y libjpeg-devel (这个包的实际名字是libjpeg-turbo-devel.x86_64,可以yum list |grep jpeg看到)
# ./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
反馈一条configure: error: png.h not found.
# yum install -y libpng-devel
# ./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
反馈一条configure: error: freetype-config not found.
# yum install -y freetype-devel
# ./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
反馈一条configure: error: mcrypt.h not found. Please reinstall libmcrypt.
# yum install -y libmcrypt-devel (mcrypt这个库在扩展源里,如果没有安装就先装epel-release)
# ./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
看到这些,表示这步已经执行成功了,也可以echo $?看一下
现在已经知道是需要安装哪些包了,下次安装时就可以一次直接安装这7个包再执行./configure的命令
# make && make install
make install后,可以看到有:
chmod 755 /usr/local/apache2.4/modules/libphp5.so 把libphp5.so放到modules下
[activating module `php5' in /usr/local/apache2.4/conf/httpd.conf] 激活这个配置文件
# ls /usr/local/php
bin etc include lib php
[[email protected] php-5.6.30]# ls /usr/local/php/bin 核心的二进制文件在bin下
pear peardev pecl phar phar.phar php php-cgi php-config phpize
# du -sh /usr/local/apache2.4/modules/libphp5.so 这个文件就是我们想要的扩展模块
37M /usr/local/apache2.4/modules/libphp5.so
Apache和PHP结合是通过这个文件实现的。
# /usr/local/php/bin/php -m查看这个PHP加载了哪些模块,和httpd -M类似。
PHP不需要像Apache和mysql那样用start启动,因为它是作为Apache的一个模块存在的,如果libphp5.so这个文件删除,那Apache就不支持PHP了。需要执行PHP时就要用到php module。
PHP模块文件:/usr/local/apache2.4/modules/libphp5.so
# cp php.ini-production /usr/local/php/etc/php.ini
PHP的参考配置文件:php.ini-production
php.ini-production 生产环境使用
php.ini-development 开发环境
后面配置文件的路径,放这里是因为前面编译的时候指定的这里。
# /usr/local/php/bin/php -i |less
-i:该选项能查看到PHP的信息,编译参数,configuration file的路径(配置文件)
这行它要识别的名字是php.ini,拷贝过来以后才有。
二、安装PHP7
# cd /usr/local/src
# wget http://cn2.php.net/distributions/php-7.1.6.tar.bz2
# tar jxf 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
--with-mysql=/usr/local/mysql少了这一个参数,其他都一样。
# make && make install
一台机器可以装2个PHP,但是Apache调用的PHP要指定好,就是配置文件修改。
# ls /usr/local/apache2.4/modules/libphp 可以看到有两个php模块文件
libphp5.so libphp7.so
# /usr/local/apache2.4/bin/apachectl -M 查看到阿帕奇加载php5和php7两个。
php5_module (shared)
php7_module (shared)
# vim /usr/local/apache2.4/conf/httpd.conf 想用哪个就进配置文件改,不用哪个就在行首加个#注释掉
#LoadModule php5_module modules/libphp5.so 进文件直接/php5就可以搜到了
LoadModule php7_module modules/libphp7.so
扩展
php中mysql,mysqli,mysqlnd,pdo到底是什么http://blog.csdn.net/u013785951/article/details/60876816
查看编译参数 http://ask.apelearn.com/question/1295
以上是关于三十九安装PHP5安装PHP7的主要内容,如果未能解决你的问题,请参考以下文章